squigs Posted March 31, 2011 Share Posted March 31, 2011 Hello, I've created a page search to return results from my database inventory. On top of these results I would like to display a seperate list of five products not included in the search results but share the same sub_category_b (a column in my SQL table). Posted below is my primary query of the database. If anyone can help me out with this it would be appreciated. $colname_product = "-1"; if (isset($_GET['title'])) { $colname_product = $_GET['title']; } mysql_select_db($database_inventory, $inventory); $query_product = sprintf("SELECT * FROM inventory WHERE item_name LIKE %s OR item_desc LIKE %s ", GetSQLValueString("%" . $colname_product . "%", "text"),GetSQLValueString("%" . $colname_product . "%", "text")); $product = mysql_query($query_product, $inventory) or die(mysql_error()); $row_product = mysql_fetch_assoc($product); I've fooled around with this one for some time and haven't come up with a clear cut answer. Thank you in advance! Link to comment https://forums.phpfreaks.com/topic/232261-creating-product-list-from-database/ Share on other sites More sharing options...
squigs Posted April 1, 2011 Author Share Posted April 1, 2011 If my question wasn't clear I will try to re-explain it. I'm hoping someone out there can give me a hand in learning the proper way to do this. The code in my previous post is my primary query that displays my results from my search bar ['title']. In mysql table there are multiple columns that I have already retrieved in my primary query such as [category], [sub_category_a], [sub_category_b], [item-name], [item_id] etc. With these values already being fetched is there someway to add another query into my page where I can use the value of [sub_category_a] from my first result and post five results in a different part of my page? I have been fooling with something like this. <?php $row_product = mysql_fetch_assoc($product); ("SELECT * FROM inventory WHERE sub_category_a = $row_product ORDER BY RAND() LIMIT 5 ") ?> Thanks for having a look at this abortion Link to comment https://forums.phpfreaks.com/topic/232261-creating-product-list-from-database/#findComment-1195641 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.