Jump to content

Php / Mysql select issue


Prank

Recommended Posts

Hi Guys,

I have a table with 5 records in it, when I select the records (even just using SELECT * FROM cars) it will sometimes retrieve 3 records and sometimes 4, never the whole amount. I have never seen this happen before. If I run the query in phpmyadmin it returns all records. I dont understand how this could happen, the Statement could not be more simple.

Anyone know why this could be happening?

Christian
Link to comment
Share on other sites

Its happening in several places, each with re-written code.

The code couldnt be more simple.

Heres one example;
[code]
        $q = "SELECT * FROM cars";
$qr = mysql_query($q) or die(mysql_error());
$r = mysql_fetch_assoc($qr);

echo '<strong>Select a link category</strong><br />';

while($r = mysql_fetch_assoc($qr)){

echo '<a href="links.php?do=listlinks&cat='.$r['name'].'">'.$r['name'].'</a><br />';

} // while[/code]

Thanks.
Link to comment
Share on other sites

[code]<?php
        $q = "SELECT * FROM cars";
$qr = mysql_query($q) or die(mysql_error());
$r = mysql_fetch_assoc($qr); // <- You already get one row here

echo '<strong>Select a link category</strong><br />';

while($r = mysql_fetch_assoc($qr)){
        // and ofcourse overhere total loops will be minus one of total rows
echo '<a href="links.php?do=listlinks&cat='.$r['name'].'">'.$r['name'].'</a><br />';

} // while
?>[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

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

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.