Jump to content

Displaying Data Help - Rows Displayed Are Being Skipped


Recommended Posts

Hi,

 

Okay so I have my database properly set up and I have tested that there is nothing wrong with my sql query.

 

But, whenever I try to display data from the database it will only show even or odd 'id' number rows.

 

this is my php code simplified and it still doesn't work:

 

<?php
include '../connection.php';
session_start();
$page = 'index.php';

$query = "SELECT id, productname, price, screensize, description, shipping, quantity FROM products WHERE quantity > 0 ORDER BY id ASC";
$result = mysql_query($query);
while ($result_row = mysql_fetch_assoc($result))
{
echo "<p>";
echo '<a href="shoppingcart.php?add='.$result_row['id'].'>Add to cart </a>';
echo $result_row["id"];
echo "<br />";
echo $result_row["productname"];
echo "<br />";
echo $result_row["screensize"];
echo "<br />";
echo $result_row["description"]. "<br/>";
echo "£" .number_format($result_row["price"], 2);
echo "</p>";
echo "<hr>";
}
?>

 

I found out that the problem was with the this line:

echo '<a href="shoppingcart.php?add='.$result_row['id'].'>Add to cart </a>';

And if I inserted it before the 'id' to display it would only show the even numbered 'id' rows and odd if I entered it after.

 

I am stuck for any ideas and I think I need someone with experience who knows how to sort this problem out.

 

Thanks

 

Sam.

But, whenever I try to display data from the database it will only show even or odd 'id' number rows.

 

What is this supposed to mean? It will only show even some of the times odd some other? Please explain in depth.

 

I found out that the problem was with the this line:

echo '<a href="shoppingcart.php?add='.$result_row['id'].'>Add to cart </a>';

 

Single quoted variables do not get parsed. Change the apostrophe of that echo to a quote.

When I was saying it was only displaying data that was ODD or EVEN by 'id' I meant it would display like

id row 1

id row 3

id row 5

or

id row 2

id row 4

id row 6

 

I changed that line as you suggested and it now works :)

echo "<a href='cart_index.php?add=".$result_row['id']."'>Add to cart</a>";

Why doesn't it get parsed if it's in single quotes?

 

and thanks for your advice :)

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.