Jump to content
mickeymouse

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.

$cntr=0;

while($AffectedRows > $cntr)

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

image.thumb.png.b5d55de7869da93d68a5185fce722c1c.png

Share this post


Link to post
Share on other sites

Have you looked into what " mysql_fetch_row($Results);  " is returning

or what the contents of " $Results " contain?  Neither is shown above.

 

Share this post


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);

Share this post


Link to post
Share on other sites

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.

Share this post


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.

Share this post


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

 

Share this post


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.

Guest
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.

Loading...

×
×
  • Create New...