+ Reply to Thread
Results 1 to 3 of 3

Thread: PHP Search result help?

  1. #1
    Kelly H is offline Junior Member Kelly H is on a distinguished road
    Join Date
    Oct 2009
    Posts
    2

    Default PHP Search result help?

    Here is the code i have


    <?php
    mysql_connect ("localhost", "***********","**********") or die (mysql_error());
    mysql_select_db ("kelly");

    $term = $_POST['term'];

    $sql = mysql_query("select * from text where Color like '%$term%' or ItemNumber like '%$term%' or Discription like '%$term%'or Price like '%$term%' or Information like '%$term%' ");


    while ($row = mysql_fetch_array($sql)){
    echo ''.$row['URL'];
    echo '<br/> Discription:&nbsp '.$row['Discription'];
    echo '<br/> ItemNumber:&nbsp '.$row['ItemNumber'];
    echo '<br/> Price:&nbsp$ '.$row['Price'];
    echo '<br/><br/>';
    }

    ?>



    Here is what i need it to do.
    Say you do a search for oreo cookie this is going to search my DB well the only problem is that i dont have any thing close to oreo cookie in there. Right now if i were to do a search for it it would just give me a blank result. What code would i need to add to my code to have it say " The search you just made did not find any thing Please try again"

  2. #2
    eric is offline Junior Member eric is on a distinguished road
    Join Date
    Feb 2007
    Posts
    13

    Default

    if(mysql_num_rows($sql) == 0)
    echo("The search you just made did not find any thing Please try again");

  3. #3
    chris b is offline Junior Member chris b is on a distinguished road
    Join Date
    Mar 2008
    Posts
    8

    Default

    Try this:
    <?php
    mysql_connect ("localhost", "***********","**********") or die (mysql_error());
    mysql_select_db ("kelly");
    $term = $_POST['term'];
    $sql = mysql_query("select * from text where Color like '%$term%' or ItemNumber like '%$term%' or Discription like '%$term%'or Price like '%$term%' or Information like '%$term%' ");
    if(!mysql_fetch_array($sql)){
    echo "Your search did not match with anything. Please try again";
    }else{
    while(list($url,$description,$itemNumber,$price)=m ysql_fetch_array($sql)){
    echo ''.$url;
    echo '<br/> Discription:&nbsp '.$description;
    echo '<br/> ItemNumber:&nbsp '.$itemNumber;
    echo '<br/> Price:&nbsp$ '.$price;
    echo '<br/><br/>';
    }
    }
    ?>
    I cannot guarantee if your code is correct.
    If it doesn't Create another query, except where it says "SELECT * FROM", do "SELECT COUNT(*) FROM".
    $sql = SELECT COUNT(*) FROM...
    $result = mysql_fetch_array($sql);
    $result = $result[0];
    if($result != 0){ ... display results... }else{...no matches...}
    Good Luck!
    If you need further assistance/advice, feel free to contact me.

+ Reply to Thread

Similar Threads

  1. Replies: 0
    Last Post: 02-01-2010, 03:27 PM
  2. Promoting and marketing online, what are the best result oriented tools are
    By Anon in forum SEO - Search Engine Optimization
    Replies: 0
    Last Post: 01-21-2010, 08:42 AM
  3. Replies: 0
    Last Post: 12-25-2009, 06:50 PM
  4. Replies: 0
    Last Post: 01-23-2009, 05:23 PM
  5. Replies: 0
    Last Post: 07-19-2008, 07:21 PM

Posting Permissions

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