Darkwoods Posted February 23, 2010 Share Posted February 23, 2010 hey how do i stop echoing a specific id for example i dont want the id 6 to display with the others ids thanks Quote Link to comment Share on other sites More sharing options...
aleX_hill Posted February 23, 2010 Share Posted February 23, 2010 There isnt a lot of information here on what you are trying to do, but I assume something like this will work (although I am not the best coder, so there could be a more effective way). while($i=0; $i<$numberOfIds; $i++) //Cycle through each "thing" { //do something here to initialize the $id variable, maybe get some mysql information if($id != 6) //If the id is 6, we will skip it { echo $id; } } If you give a little bit more info I can try and expand. Quote Link to comment Share on other sites More sharing options...
aleX_hill Posted February 23, 2010 Share Posted February 23, 2010 I just had a look through your posts and found the following code, which I assume you are using. I have put the if statement in for you. ?php $result = mysql_query("SELECT * FROM cat_foodmenu ",$connect); while($row = mysql_fetch_array($result)) { $id = $row['id']; $title = $row['title']; if($id != '6') { echo '<h1>'. $title . '</h1>'; $result = mysql_query("SELECT * FROM food_menu WHERE cat_id='$title' ORDER BY id ASC",$connect); while ($row = mysql_fetch_array($result)) { $id = $row['id']; $title = $row['title']; $price = $row['price']; $info = $row['info']; echo '<div class="recipe"><span class="name_of_the_recipe">' .$title .'</span>'; echo '<div class="price">$' . $price .'</div>'; echo '<div class="recipe_bg"> </div><div class="clear_container"></div></div>'; echo '<p>(' . $info .')</p><br />'; } } } ?> Quote Link to comment Share on other sites More sharing options...
Darkwoods Posted February 23, 2010 Author Share Posted February 23, 2010 Hey thanks... here is the code im using.. the code you wrote makes alot of sense but how can imlpent it with the while when i already have ($row = mysql_fetch_array($result2)? <?php echo '</h1><img class="section_img" src="images/index_img.jpg" alt="Menu" />'; $result = mysql_query("SELECT * FROM cat_foodmenu ",$connect); while ($row = mysql_fetch_array($result)) { $id_c = $row['id']; $title = $row['title']; echo '<h1><a name="'. $title .'">'. $title .'</a></h1>'; echo ''; $result2 = mysql_query("SELECT * FROM food_menu WHERE cat_id='$id_c' ORDER BY id ASC",$connect); while ($row = mysql_fetch_array($result2)) { $id = $row['id']; $food_title = $row['title']; $price = $row['price']; $info = $row['info']; $cat = $row['cat_id']; echo '<div class="recipe"><span class="name_of_the_recipe">' .$food_title.'</span>'; if ($cat != 7){ echo '<div class="price">$' . $price .'</div>'; } else { echo '<div class="price2">$' . $price .' <font style="color:#333; font:Verdana; font-size:9px;">Per Person</font></div>'; } echo '<div class="recipe_bg"> </div><div class="clear_container"></div></div>'; echo '<p>(' . $info .')</p><br />'; } } ?> Quote Link to comment Share on other sites More sharing options...
Darkwoods Posted February 23, 2010 Author Share Posted February 23, 2010 oh thanks man i dont need to use the while if($id != '6') will do the whole job great maybe i should just use more my head to figure out PHP thanks anyway Quote Link to comment Share on other sites More sharing options...
aleX_hill Posted February 23, 2010 Share Posted February 23, 2010 I would still get the item from the database, so in your case keep the code you have, and just put the if statement just before you output the data. So, get each category, then under each category get each item, but if that item's id = 6, just dont output anything. Quote Link to comment Share on other sites More sharing options...
Darkwoods Posted February 23, 2010 Author Share Posted February 23, 2010 thanks it is working just as i wanted Karma Quote Link to comment 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.