Thread: Search problem

    #1
  1. No Profile Picture
    The Dude Abides
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Feb 2000
    Location
    grass valley,ca
    Posts
    1,062
    Rep Power
    16
    I'm having a problem with a php3/mysql results display. The problem seems to lie in the search parameters passed to the script, and the Next/Previous links. The parameters are passed from a dropdown boxed called "prodname". The results display aren't relevant to the queries, and somethings aren't displayed at all (even with the wildcard). I've tried different variations on the $prodname%, but with no improvement. Any help is appreciated.


    <?php
    mysql_connect (xxxxx);

    mysql_select_db (xxxxx);
    if ($prodname == "")
    {$prodname = '$prodname%';}

    //Count results and limit rows in html output
    $limit=2; // rows to return
    $numresults=mysql_query("select count(prodname) from table ");
    $numrows=mysql_result($numresults,0,"count(prodname)");

    // next determine if offset has been passed to script, if not use 0
    if (empty($offset)) {
    $offset=0;
    }

    // 43 get results
    $result=mysql_query( "select prodname,prodnumber,description,image,price,shipcode,status ".
    "from table WHERE prodname LIKE '$prodname%' ".
    "limit $offset,$limit");

    // now you can display the results returned
    if ($row = mysql_fetch_array($result)) {
    do
    {
    //html formatting
    }

    while ($row=mysql_fetch_array($result));
    }

    //end results
    //next we need to do the links to other results

    if ($offset > 1) { // bypass PREV link if offset is 0
    $prevoffset=$offset-$limit;
    // print "<a href="$PHP_SELF?offset=$prevoffset">PREV</a> * n";
    }

    for ($i=1;$i<=$pages;$i++) { // loop thru
    $newoffset=$limit*($i-1);
    print "<a href="$PHP_SELF?offset=$newoffset">$i</a> * n";
    }

    // check to see if last page
    if (!(($offset/$limit)==$pages) && $pages!=1) {
    // not last page so give NEXT link
    $newoffset=$offset+$limit;
    if ( $newoffset < $numrows )
    print "<a href="$PHP_SELF?offset=$newoffset">NEXT</a><p>n";
    }
    ?>

    Thanks

    ------------------
    Chris Staniar

    [This message has been edited by thedude (edited March 24, 2000).]
  2. #2
  3. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15

    use a % infront of argument like this:
    '%$prodname%'.


    $result=mysql_query( "select prodname,prodnumber,description,image,price,shipcode,status ".
    "from table WHERE prodname LIKE
    '%$prodname%' ".
    "limit $offset,$limit");


  4. #3
  5. No Profile Picture
    The Dude Abides
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Feb 2000
    Location
    grass valley,ca
    Posts
    1,062
    Rep Power
    16
    Thanks Shiju, unfortunately I've tried that one before. I'm pretty new to php/mysql, but from what I can tell there are some errors that go a little deeper then just the search query.

    I believe I need a where/like statement in the line that counts the result rows, I think.

    Thanks again

    ------------------
    Chris Staniar

    [This message has been edited by thedude (edited March 24, 2000).]

Similar Threads

  1. Highlight search result from mysql database search
    By Gurt in forum PHP Development
    Replies: 3
    Last Post: February 17th, 2004, 04:39 AM
  2. UTF-8 problem in 4.1.1a
    By mehran20 in forum MySQL Help
    Replies: 1
    Last Post: February 8th, 2004, 03:21 PM
  3. Database search highlighting problem - Stuck!
    By nro in forum PHP Development
    Replies: 5
    Last Post: January 30th, 2004, 09:44 PM
  4. mysql problem with joining tables , complicated!
    By toxical in forum PHP Development
    Replies: 6
    Last Post: January 27th, 2004, 04:43 PM
  5. Cgi Search feature script
    By butsy_7 in forum Perl Programming
    Replies: 5
    Last Post: January 22nd, 2004, 08:43 PM

IMN logo majestic logo threadwatch logo seochat tools logo