Jump to content

elseif Statement


savagenoob

Recommended Posts

Why am I getting an error on this elseif statement? I know its something simple....

 

$agency=$_SESSION['SESS_AGENCY'];
$search=$_POST["keyword"];
$field=$_POST["field"];

if($field == "PolNum"){
     echo  "<table>";
	$query = "SELECT auto.ClientID, home.ClientID, auto.PolNum, home.PolNum FROM auto, home WHERE auto.'$field' OR home.'$field' LIKE '%$search%' AND Agency = '$agency'";
$result = mysql_query($query)or die(mysql_error());
    $numrows = mysql_num_rows($result);
	if($numrows == 0){ echo "No results returned for " . $search; }

while($myrow = mysql_fetch_assoc($result)) {
	$clientid = $myrow['ClientID'];
	$clientdata = mysql_query("SELECT * FROM clients WHERE ID ='$clientid'")or die(mysql_error());
	$client = mysql_fetch_assoc($clientdata);

  echo "<tr><td><a href=\"client.php?ID=$clientid\">" . $client['First_Name'] . " " . $client['Last_Name'] . " " . $myrow['PolNum'] . "</a></td></tr>\""   ;         
        


}
elseif($field == "Last_Name")
{
	?>
        <table>
        <?php
$query = "SELECT * FROM clients WHERE $field LIKE '%$search%' AND Agency = '$agency'";
$result = mysql_query($query)or die(mysql_error());


 while($myrow = mysql_fetch_assoc($result)) 
             {//begin of loop 

echo "<tr><td><a href=\"client.php?ID=\"" . $myrow['ID'] . "\">" . $myrow['First_Name'] . " " . $myrow['Last_Name'] . "</a></td></tr> "; 

}
}
?>

Link to comment
Share on other sites

Why are you using "else if" ?

 

<?php
$agency=$_SESSION['SESS_AGENCY'];



$search=$_POST["keyword"];



$field=$_POST["field"];



if($field == "PolNum"){
     echo  "<table>";





$query = "SELECT auto.ClientID, home.ClientID, auto.PolNum, home.PolNum FROM auto, home WHERE auto.'$field' OR home.'$field' LIKE '%$search%' AND Agency = '$agency'";



$result = mysql_query($query)or die(mysql_error());
    $numrows = mysql_num_rows($result);





if($numrows == 0){ echo "No results returned for " . $search; }



while($myrow = mysql_fetch_assoc($result)) {





$clientid = $myrow['ClientID'];





$clientdata = mysql_query("SELECT * FROM clients WHERE ID ='$clientid'")or die(mysql_error());





$client = mysql_fetch_assoc($clientdata);

  echo "<tr><td><a href=\"client.php?ID=$clientid\">" . $client['First_Name'] . " " . $client['Last_Name'] . " " . $myrow['PolNum'] . "</a></td></tr>\""   ;         
        






}


if($field == "Last_Name")



{





?>
        <table>
        <?php



$query = "SELECT * FROM clients WHERE $field LIKE '%$search%' AND Agency = '$agency'";



$result = mysql_query($query)or die(mysql_error());









while($myrow = mysql_fetch_assoc($result)) 
             {//begin of loop 

echo "<tr><td><a href=\"client.php?ID=\"" . $myrow['ID'] . "\">" . $myrow['First_Name'] . " " . $myrow['Last_Name'] . "</a></td></tr> "; 

}



}
}
?>

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.