Jump to content

Database Rows not printing

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.


while($AffectedRows > $cntr)

     {$row = mysql_fetch_row($Results);
       print("Number = $row[$cntr]<br>");


Link to post
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 post
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 post
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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...