Jump to content

Database Rows not printing


mickeymouse
 Share

Recommended Posts

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++;}

image.thumb.png.b5d55de7869da93d68a5185fce722c1c.png

Link to comment
Share on other sites

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

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...