SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    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'];

  2. #2
    SitePoint Evangelist Waffles's Avatar
    Join Date
    Nov 2005
    Posts
    435
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP 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'];
    }
    }
    ?>

  3. #3
    SitePoint Member
    Join Date
    Jul 2005
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks very much


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •