Jump to content

Trying not to show a $var in a loop


mazman13

Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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>";
	}
}

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.