SitePoint Sponsor |
|
User Tag List
Results 1 to 3 of 3
Thread: problem with search script
-
Apr 25, 2006, 06:16 #1
- Join Date
- Jul 2005
- Posts
- 2
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
problem with search script
Hi , I'm using a script from Kevin Yanks 'build your own database driven website' to search a database of clients by name, it works ok, but if the entered name is not in the database, it returns a blank, I'd to get a message back to say, name not found, is there an opposite of the LIKE operator? or how could I do this?
If anyone can point me in the right direction with this I'd really appreciate it.
$select = 'SELECT DISTINCT id, name, firstnames, phone';
$from = ' FROM clientinfo';
$where = ' WHERE 1=1';
$searchtext = $_POST['searchtext'];
if ($searchtext != '') { // Some search text was specified
$where .= "AND name LIKE '$name'";
}
?>
</p>
<table width="450">
<?php
$clients = @mysql_query($select . $from . $where);
if (!$clients) {
echo '</table>';
exit('<p>Error retrieving info from database!<br />'.
'Error: ' . mysql_error() . '</p>');
}
while ($client = mysql_fetch_array($clients)) {
echo "<tr valign='top'>\n";
$id = $client['id'];
$name = $client['name'];
$firstnames = $client['firstnames'];
$phone = $client['phone'];
-
Apr 25, 2006, 06:18 #2PHP Code:
<?
$select = 'SELECT DISTINCT id, name, firstnames, phone';
$from = ' FROM clientinfo';
$where = ' WHERE 1=1';
$searchtext = $_POST['searchtext'];
if ($searchtext != '') { // Some search text was specified
$where .= "AND name LIKE '$name'";
}
?>
</p>
<table width="450">
<?php
$clients = @mysql_query($select . $from . $where);
if (!$clients) {
echo '</table>';
exit('<p>Error retrieving info from database!<br />'.
'Error: ' . mysql_error() . '</p>');
}
/* I added this -----------------*/
$result = mysql_num_rows($clients);
if($result < 1) {
exit('Sorry, no user found.');
} else {
/* ------------------- */
while ($client = mysql_fetch_array($clients)) {
echo "<tr valign='top'>\n";
$id = $client['id'];
$name = $client['name'];
$firstnames = $client['firstnames'];
$phone = $client['phone'];
}
}
?>
-
Apr 25, 2006, 06:58 #3
- Join Date
- Jul 2005
- Posts
- 2
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
thanks very much
Bookmarks