Jump to content

[SOLVED] search results ... display issue


kevinritt

Recommended Posts

First, I have to say thank you to all the people that have helped in these forums. I've learned a lot and with the help you've given me, I've been able to accomplish what I set out to do. That being said, I have a search form which works fine. I have 2 questions. How/ where can I add something that will echo "No results found" - I've tried a couple of things and they didn't work - I kept getting errors. Also, the display of the search results goes across the page horizontally but I want it to show vertically.

Here's the form:

  <form action="./includes/update2.php?action=searchlastname" method="post"> 
     Enter a last name: <input type="text" name="lastName" /><br />  
    <input type="submit" name="submit" value="Submit" /> 
   </form>

Here's the query:

case 'searchlastname':
foreach($_POST as $key=>$value){
$$key = $value;
}

// if the form has been submited ($_POST['Submit) 
if(isset($Submit))

// if form has been submited process the form
 {
foreach($_POST as $key=>$value){
$$key = ValidateInput($value);
}
}
$lastName = mysql_real_escape_string($_POST['lastName']);
$sql = mysql_query("SELECT * FROM memberships WHERE lastName LIKE'%$lastName%'");   
// start the while statement to get results from database
  

while ($row = mysql_fetch_array($sql)) {
// foreach row in the while loop..
foreach($row as $key=>$value){
$$key = ValidateOutput($value);
}





// display data in an HTML table for viewing
?>
<table width="400" align="left" cellpadding="4" cellspacing="1">
<?
echo '<tr>
<td bgcolor="#CCCCCC">Member ID:</td>
<td bgcolor="#CCCCCC"><a href="./update2.php?action=editmembers&edit=edit&memberID='.$memberID.'">'.$memberID.'</a></td>
</tr>
<tr><td bgcolor="#CCCCCC">Name</td>
<td bgcolor="#CCCCCC">'.$firstName.' '.' '.$lastName.'</td>
</tr>
<tr><td bgcolor="#CCCCCC">Name (2):</td>
<td bgcolor="#CCCCCC">'.$firstName2.' '.' '.$lastName2.'</td>
</tr>
<tr><td bgcolor="#CCCCCC">Address</td>
<td bgcolor="#CCCCCC">'.$address.' <br> 
  '.$city.' '.' '.$state.' '.' '.$zip.'</td></tr>
<tr><td bgcolor="#CCCCCC">Phone:</td>
<td bgcolor="#CCCCCC">'.$telephone.'</td>
</tr>
<tr><td bgcolor="#CCCCCC">Email:</td>
<td bgcolor="#CCCCCC"><a href="mailto:'.$email.'">'.$email.'</a></td>
</tr>
<tr><td bgcolor="#CCCCCC">Exp Date:</td>
<td bgcolor="#CCCCCC">'.$expiration.'</td>
</tr>
<tr><td bgcolor="#CCCCCC">Membership Type:</td>
<td bgcolor="#CCCCCC">'.$type.'</td>
</tr>
<tr><td bgcolor="#CCCCCC">Child(ren)(s) Name:</td>
<td bgcolor="#CCCCCC">'.$childName.'</td>
</tr>
<tr><td bgcolor="#CCCCCC">Interests:</td>
<td bgcolor="#CCCCCC">'.$interests.'</td>
</tr>
<tr><td bgcolor="#CCCCCC">Date Added:</td>
<td bgcolor="#CCCCCC">'.$dateAdded.'</td>
</tr>
<tr><td bgcolor="#CCCCCC">Updated:</td>
<td bgcolor="#CCCCCC">'.$updated.'</td>
</tr>
<tr><td bgcolor="#CCCCCC">Additional Notes:</td>
<td bgcolor="#CCCCCC">'.$additionalNotes.'</td>
</tr>
';
}
?>
</table>
<?
break;

 

Sorry for the long post  ???

Link to comment
https://forums.phpfreaks.com/topic/146012-solved-search-results-display-issue/
Share on other sites

Hi,

 

This should do it.


<?php

case 'searchlastname':
    foreach($_POST as $key=>$value){
        $$key = $value;
    }    
    // if the form has been submited ($_POST['Submit) 
    if(isset($Submit))    
    // if form has been submited process the form
    {
        foreach($_POST as $key=>$value){
            $$key = ValidateInput($value);
        }
    }
    $lastName = mysql_real_escape_string($_POST['lastName']);
    $sql = mysql_query("SELECT * FROM memberships WHERE lastName LIKE'%$lastName%'");
    if (mysql_num_rows($sql) > 0){
        while ($row = mysql_fetch_array($sql)){

            // dsiplay your result how ever you wand e.g
            print $row['firstName'] . " " . $row['lastName'] . "<br />";
        
        }
        mysql_free_result($sql);
    }
    else {
        //Display the "No Results Mesage"
        print "<font color=\"red\" size=\"14px\">Your search for $lastName returned no results</font><br />";
    
    }
    ?>

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.