Interista Posted October 22, 2012 Share Posted October 22, 2012 Hello , I'm a newbie in PHP but I have tried so much but nth work ! I want to print out products into categories like this way : Category 1 : product 1 product 2 product 3 Category 2: product 5 product 7 and so on .. This is my code which I'm using : $get_products = mysql_query("select * from ((product join category on cid = p_cid) join restaurant on rid = c_rid) join restaurant_type on rtid = r_rtid where rid = '$rest_id' order by rid, c_sortval, p_sortval"); while ($get_productsrows = mysql_fetch_assoc($get_products)) { echo ' <div class="product-box" id="products-box"> <table width="100%;">'; echo '<tr id="'.$get_productsrows['pid'].'" rel="desc" title="' . $get_productsrows['p_desc'] . '" > <td style="font-weight: bold;font-size:13px;" ><span class="name">' . $get_productsrows['p_name'] . '</span></td> <td style="text-align:center;font-size:11px;" >JD <span class="price">' . $get_productsrows['p_price'] . '+</span></td> <td style="text-align:center;"><input type="submit" value="Add" class="btn-add"></td> </tr> </table></div>'; This is only print out the all products for all categories for the restaurant ID . Quote Link to comment https://forums.phpfreaks.com/topic/269781-print-out-products-into-categories/ Share on other sites More sharing options...
Barand Posted October 22, 2012 Share Posted October 22, 2012 pseudocode prev_cat = '' while (fetch next row) { if (category != prev_cat { print category prev_cat = category } print product } Quote Link to comment https://forums.phpfreaks.com/topic/269781-print-out-products-into-categories/#findComment-1386999 Share on other sites More sharing options...
Interista Posted October 22, 2012 Author Share Posted October 22, 2012 pseudocode prev_cat = '' while (fetch next row) { if (category != prev_cat { print category prev_cat = category } print product } U rock works great thank u so much for the help Quote Link to comment https://forums.phpfreaks.com/topic/269781-print-out-products-into-categories/#findComment-1387003 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.