mickeymouse 0 Posted July 5, 2019 Report 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++;} Quote Link to post Share on other sites
JMRKER 10 Posted July 5, 2019 Report 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. Quote Link to post Share on other sites
mickeymouse 0 Posted July 5, 2019 Author Report 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); Quote Link to post Share on other sites
dsonesuk 914 Posted July 5, 2019 Report 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. Quote Link to post Share on other sites
mickeymouse 0 Posted July 6, 2019 Author Report 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. Quote Link to post Share on other sites
dsonesuk 914 Posted July 6, 2019 Report Share Posted July 6, 2019 Why are you using $link ? That is database connection data, not database row values. Quote Link to post Share on other sites
mickeymouse 0 Posted July 6, 2019 Author Report 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 Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.