mazman13 Posted October 30, 2007 Share Posted October 30, 2007 I want to display everything I have from a database except for the $var that contains "Self" I tried doing something like: foreach ($temp as $var) { if ($var != "Self") { echo"$var"; } } But it doesn't seem to work. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/75367-trying-not-to-show-a-var-in-a-loop/ Share on other sites More sharing options...
Orio Posted October 30, 2007 Share Posted October 30, 2007 The code is perfectly fine. There must be another problem. Either there's nothing that equals exactly "Self" in $temp, or you are not pulling the data correctly (the way you think you are supposed to). If "Self" is in the list, maybe there spaces around it or whatever. Check that. Orio. Quote Link to comment https://forums.phpfreaks.com/topic/75367-trying-not-to-show-a-var-in-a-loop/#findComment-381175 Share on other sites More sharing options...
cooldude832 Posted October 30, 2007 Share Posted October 30, 2007 more general solution <?php $bad_words = array("Self", "self"); $var = ""; //Come from what ever you want it to foreach($var as $value){ if(!in_array($value)){ echo $value."<br />"; } ?> And you can add to the array to make more words not show. Quote Link to comment https://forums.phpfreaks.com/topic/75367-trying-not-to-show-a-var-in-a-loop/#findComment-381185 Share on other sites More sharing options...
mazman13 Posted October 30, 2007 Author Share Posted October 30, 2007 Well I tried to make those work, but they didn't seem to. Can you guys check to see if I'm missing anything? It's kinda long I know. Sorry. foreach($insurance_comp as $insurance) { if($insurance != "Self"){ //Print name echo"<font face=\"Arial\" size=\"3\"><strong>$insurance</strong></font>"; //Start table echo"<table size=\"100%\"><tr><td>"; //Insurance total $query = "SELECT COUNT(paysource) AS insur_total FROM data WHERE paysource='$insurance' AND date BETWEEN '$year-$month-00' AND '$year-$month-32'"; $result = mysql_query($query)or die(mysql_error()); $row = mysql_fetch_assoc($result); extract($row); $i_total = ($insur_total * 2); //Get insurance handle echo"<font face=\"Arial\" size=\"1\"><strong>SATISFIED</strong></font></td>"; $query = "SELECT COUNT(paysource) AS iinsurance FROM data WHERE insurance='Y' AND paysource='$insurance' AND date BETWEEN '$year-$month-00' AND '$year-$month-32'"; $result = mysql_query($query)or die(mysql_error()); $row = mysql_fetch_assoc($result); extract($row); $i_insurance = number_format(($iinsurance * 100 / $insur_total),1)."%"; echo"<td><img src=\"images/insurance.gif\">"; $i = 1; while ($i <= $i_insurance) { echo"<img src=\"images/insurance.gif\">"; $i++;} echo" <font face=\"Arial\" size=\"2\"><strong>$i_insurance</strong></font>"; echo"</td></tr>"; echo"<tr><td>"; ///////Get Additional/Returns echo"<font face=\"Arial\" size=\"1\"><strong>REFER</strong></font></td>"; $query = "SELECT COUNT(recommend) AS irefer FROM data WHERE additional='Y' AND paysource='$insurance' AND date BETWEEN '$year-$month-00' AND '$year-$month-32'"; $result = mysql_query($query)or die(mysql_error()); $row = mysql_fetch_assoc($result); extract($row); $i_refer = number_format(($irefer * 100 / $insur_total),1)."%"; echo"<td><img src=\"images/insurance.gif\">"; $i = 1; while ($i <= $i_refer) { echo"<img src=\"images/insurance.gif\">"; $i++;} echo" <font face=\"Arial\" size=\"2\"><strong>$i_refer</strong></font>"; echo"</td></tr>"; //Overall Average echo"<tr><td>"; echo"<font face=\"Arial\" size=\"1\"><strong>OVERALL</strong></font></td>"; $new_insur_total = ($iinsurance + $irefer); $insur_overall = number_format(($new_insur_total * 100 / $i_total),1)."%"; echo"<td><strong><font face=\"Arial\" size=\"2\">$insur_overall</font></strong></td></tr>"; echo"</table><br>"; } } Quote Link to comment https://forums.phpfreaks.com/topic/75367-trying-not-to-show-a-var-in-a-loop/#findComment-381221 Share on other sites More sharing options...
atlanta Posted October 30, 2007 Share Posted October 30, 2007 Which loop do you want to be filtered? Quote Link to comment https://forums.phpfreaks.com/topic/75367-trying-not-to-show-a-var-in-a-loop/#findComment-381226 Share on other sites More sharing options...
mazman13 Posted October 30, 2007 Author Share Posted October 30, 2007 I want to filter to entire forloop. The for loop will pick name and if I don't want that name to be displayed, it won't continue the display and it will get another name...it works in theory...but I'm not sure why its still saying "Self"...maybe I'm just missing something. Quote Link to comment https://forums.phpfreaks.com/topic/75367-trying-not-to-show-a-var-in-a-loop/#findComment-381236 Share on other sites More sharing options...
Psycho Posted October 30, 2007 Share Posted October 30, 2007 In your HTML output what EXACTLY is between the STRONG tags when "Self" is displayed? Are there any leading or trailing spaces? Is the case the same? You could try this: <?php foreach($insurance_comp as $insurance) { $insurance = trim($insurance); if(strtolower($insurance) != "self"){ ?> Also you are running queries in a loop. That is very inefficient and there are better way to accomplish that. Quote Link to comment https://forums.phpfreaks.com/topic/75367-trying-not-to-show-a-var-in-a-loop/#findComment-381243 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.