Reputation: 893
I have the following code which displays only 1 result. However, I have six rows in my database with product_id = '1'. I'm talking about $order
, only one shows up, instead of six. What is wrong?
$get = "SELECT * FROM artikelbestelling WHERE product_id = '1' LIMIT 0, 500";
$doget = mysql_query($get) or die(mysql_error());
while($row = mysql_fetch_assoc($doget))
{
$order = $row['ordernummer'];
$artikel = $row['artikelnummer'];
echo "<strong>$order</strong><br />";
}
My database structure:
id (primary & autoincrement)(int 11)
product_id (int 11)
number (int 11)
ordernummer (int 11)
Upvotes: 0
Views: 1576
Reputation: 3826
There are two things that I notice immediately that shouldn't make a difference, but might be worth trying just to see if it does. First, assuming that the product_id column is a numeric column instead of a string, try using just 1 instead of '1'. Second, explicitly check the result of mysql_fetch_assoc()
against FALSE instead of any expression that might evaluate equivalent to false.
$get = "SELECT * FROM artikelbestelling WHERE product_id = 1 LIMIT 0, 500";
$doget = mysql_query($get) or die(mysql_error());
while(($row = mysql_fetch_assoc($doget)) !== FALSE)
{
$order = $row['ordernummer'];
$artikel = $row['artikelnummer'];
echo "<strong>$order</strong><br />";
}
Edit:
What do you get if you change your code to the following?
$get = "SELECT * FROM artikelbestelling WHERE product_id = 1 LIMIT 0, 500";
$doget = mysql_query($get) or die(mysql_error());
$index = 0;
while(($row = mysql_fetch_assoc($doget)) !== FALSE)
{
$order = $row['ordernummer'];
$artikel = $row['artikelnummer'];
echo $index++ . ": <strong>$order</strong><br />";
}
Specifically, does it count all the way from 0 to 7, or does it just show row 0? I'm thinking that it's got to be one of the following:
mysql_num_rows()
is returning 8),mysql_fetch_assoc()
is incorrectly returning FALSE after just one row (which indicates some kind of bug affecting PHP or the MySQL driver, which is typically very unlikely), orThis might effectively help narrow down which it is.
Upvotes: 0
Reputation: 580
try this.....
$get = "SELECT * FROM artikelbestelling WHERE product_id = '1'
LIMIT 0, 500";
$doget = mysql_query($get) or die(mysql_error());
while($row = mysql_fetch_array($doget))
{
echo "$row[ordernummer]";
echo "<br />";
echo "$row[artikelnummer]";
}
Upvotes: 0
Reputation: 36703
as your id is int, you dont need to use ''
$get = "SELECT * FROM artikelbestelling WHERE product_id = '1' LIMIT 0, 500";
$doget = mysql_query($get) or die(mysql_error());
while($row = mysql_fetch_array($doget))
{
$order = $row['ordernummer'];
$artikel = $row['artikelnummer'];
echo "<strong>$order</strong><br />";
}
Upvotes: 1