Samza Posted November 30, 2012 Share Posted November 30, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/271411-displaying-data-help-rows-displayed-are-being-skipped/ Share on other sites More sharing options...
MDCode Posted November 30, 2012 Share Posted November 30, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/271411-displaying-data-help-rows-displayed-are-being-skipped/#findComment-1396482 Share on other sites More sharing options...
Samza Posted November 30, 2012 Author Share Posted November 30, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/271411-displaying-data-help-rows-displayed-are-being-skipped/#findComment-1396487 Share on other sites More sharing options...
MDCode Posted November 30, 2012 Share Posted November 30, 2012 (edited) Php was made that way. I don't know as to what the reason was. Edited November 30, 2012 by SocialCloud Quote Link to comment https://forums.phpfreaks.com/topic/271411-displaying-data-help-rows-displayed-are-being-skipped/#findComment-1396489 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.