bakhtn Posted December 3, 2011 Share Posted December 3, 2011 while ( $categories = $category_result -> fetch_assoc() ) { $menu_sql = "select * from menu where category_id = {$categories['category_id']}"; $menu_result = $handle -> query( $menu_sql ); $category2 = strtoupper($categories['category']); echo '<h3 id="' . $category2 . '">' . $category2 . '</h3>'; while ($menu = $menu_result -> fetch_assoc()) { echo $menu['item_name'] . ' '; $size_sql = "select distinct size from size where category_id = {$categories['category_id']} order by size desc"; $size_result = $handle -> query( $size_sql ); while ($size = $size_result -> fetch_row()) { echo $size[0] . ' '; } //get base type from base_type table for the pizza category $type_sql = "select type from base_type where category_id = {$categories['category_id']}"; $type_result = $handle -> query( $type_sql ); while ($type = $type_result -> fetch_row()) { echo $type[0] . ' '; } //get price for each item from menu if it is not null $price_sql = "select price from menu where item_name = '{$menu['item_name']}'"; $price_result = $handle -> query( $price_sql ); while ($price = $price_result -> fetch_row()) { echo $price[0] . ' '; if( is_null( $price[0] ) ) { //get price from size table if price is null in menu table; //$categories = $category_result -> data_seek(0); $size = "double"; $category_id = $categories['category_id']; $item_id = $menu['item_id']; $type = 'deep'; echo $menu['item_id']; $price_size_sql = "select price from size where size = '$size' and category_id = $category_id and item_id = $item_id"; $price_size_result = $handle -> query( $price_size_sql ); while ($price_size = $price_size_result -> fetch_assoc()) { echo " {$price_size['price']} "; } } } echo '<br />'; } echo '<br />'; } I get duplicate vakues for $category_id = $categories['category_id']; $item_id = $menu['item_id']; dont know whats wrong it works for pizzas but not burgers, please help me. Quote Link to comment https://forums.phpfreaks.com/topic/252406-php-and-mysql-i-get-duplicate-values-even-if-there-is-no-duplicates-on-db/ Share on other sites More sharing options...
bakhtn Posted December 3, 2011 Author Share Posted December 3, 2011 solved it, databse had a duplicate name burger, although had a unique primary key, should not have cuased problems, i dont know why though, please can you explain to me why this happened. Quote Link to comment https://forums.phpfreaks.com/topic/252406-php-and-mysql-i-get-duplicate-values-even-if-there-is-no-duplicates-on-db/#findComment-1294087 Share on other sites More sharing options...
scootstah Posted December 4, 2011 Share Posted December 4, 2011 That is a disturbing amount of loops within loops within loops o.O Quote Link to comment https://forums.phpfreaks.com/topic/252406-php-and-mysql-i-get-duplicate-values-even-if-there-is-no-duplicates-on-db/#findComment-1294142 Share on other sites More sharing options...
bakhtn Posted December 4, 2011 Author Share Posted December 4, 2011 do you think i could have done it withou all those loops, any suggestions will be appreciated, Quote Link to comment https://forums.phpfreaks.com/topic/252406-php-and-mysql-i-get-duplicate-values-even-if-there-is-no-duplicates-on-db/#findComment-1294385 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.