mickeymouse Posted July 5, 2019 Share Posted July 5, 2019 My $AffectedRows = 4 which matches my database rows but when I print via the following code only row 0 gets printed - screen output below. $cntr=0; while($AffectedRows > $cntr) {$row = mysql_fetch_row($Results); print("Number = $row[$cntr]<br>"); $cntr++;} Link to comment Share on other sites More sharing options...
JMRKER Posted July 5, 2019 Share Posted July 5, 2019 Have you looked into what " mysql_fetch_row($Results); " is returning or what the contents of " $Results " contain? Neither is shown above. Link to comment Share on other sites More sharing options...
mickeymouse Posted July 5, 2019 Author Share Posted July 5, 2019 The only way I know how to check what is in $Results is by printing it with a While loop but it doesn't work. I figure $Results has to contain the correct info since $AffectedRows = 4. My code to get $Results is: $link = mysql_connect($host, $username, $password); if (!$link){die('Not connected : ' . mysql_error());} $db_selected = mysql_select_db($database, $link); if (!$db_selected){die ('Can\'t use ' .$database .':'. mysql_error());} $query = "SELECT * FROM `spindat` WHERE `hand` <> 'x' "; $Results = mysql_query($query, $link) or die ('Error = '. mysql_error()); $AffectedRows = mysql_affected_rows($link); Link to comment Share on other sites More sharing options...
dsonesuk Posted July 5, 2019 Share Posted July 5, 2019 Move $row = mysql_fetch_row ($Results) Above the while loop. By the way, the use of these old deprecated since 5.5 mysql (removed in 7) functions could be another problem. Link to comment Share on other sites More sharing options...
mickeymouse Posted July 6, 2019 Author Share Posted July 6, 2019 I agree, $row = mysql_fetch_row ($Results) should be before the While loop so I've made the correction but it doesn't make any difference - I still have the unbelievable problem. Link to comment Share on other sites More sharing options...
dsonesuk Posted July 6, 2019 Share Posted July 6, 2019 Why are you using $link ? That is database connection data, not database row values. Link to comment Share on other sites More sharing options...
mickeymouse Posted July 6, 2019 Author Share Posted July 6, 2019 Wherever I'm using $link is because documentation told me to use it and I always used that and it always worked. As for my problem, it is resolved. My logic was totally wrong. This is the way it should have been: while($Rows = mysql_fetch_row($Results)) {print("Number = $Rows[0],<br>");} My original code covered my (erroneous) thinking that $Rows were Records in the Database instead of $rows being the fields in the records. So sorry to have taken your time. Many thanks Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now