scmeeker Posted July 23, 2010 Share Posted July 23, 2010 Is it possible to echo a unique item from the database? For example, if I had this code: $get_item_sql = mysql_query("SELECT id, link_1, link_2, price FROM picks WHERE MONTH(date) = MONTH(CURDATE())") or die(mysql_error()); if (mysql_num_rows($get_item_sql) < 1) { //invalid item $display_block .= "<p><em>Invalid item selection.</em></p>"; } else { //valid item, get info while ($item_info = mysql_fetch_array($get_item_sql)) { $pick_id = $item_info['id']; $pick_link_1 = $item_info['link_1']; $pick_link_2 = $item_info['link_2']; $pick_price = $item_info['price']; But wanted to echo a unique ID. Say I'm referring to item ID #2 in the table. Can I refer to it in the echo statement? But I don't want it to show up in the browser, just the information that goes with it. I want to print different items in different places throughout the webpage and not in a list. Link to comment https://forums.phpfreaks.com/topic/208616-echo-a-unique-item/ Share on other sites More sharing options...
Alex Posted July 23, 2010 Share Posted July 23, 2010 $items = array(); while ($item_info = mysql_fetch_array($get_item_sql)) { $items[$item_info['id']] = $item_info; } You can then access items by their id like so: echo $items[5]['price']; // echo the price of the item with the id of 5 Link to comment https://forums.phpfreaks.com/topic/208616-echo-a-unique-item/#findComment-1089920 Share on other sites More sharing options...
scmeeker Posted July 23, 2010 Author Share Posted July 23, 2010 Thank you for your help! Link to comment https://forums.phpfreaks.com/topic/208616-echo-a-unique-item/#findComment-1089936 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.