SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Wizard GoldFire's Avatar
    Join Date
    Oct 2002
    Location
    Oklahoma City, OK
    Posts
    1,517
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question I Need Help With My Simple Containing Phrase Search Of Site Database

    I have made a search of the User Items (my site is a game) and made it containing phrase. I want it to show just one type of item at a time if there is more than one match and it doesn't seem to be doing that.

    PHP Code:
    if ($_POST['type'] == "containing")
     {
     
    $get_matches mysql_query("SELECT * FROM tblItems");
    print 
    "<table border=1 cellpadding=6 cellspacing=0 align=center width=700><tr><td width=25% align=center><b>Shop</b></td><td width=50% align=center><b>Item</b></td><td width=5% align=center><b>Stock</b></td><td width=20% align=center><b>Price</b></td></tr>";
      while (
    $matches mysql_fetch_array($get_matches))
      {
    if (
    preg_match("/".$_POST['item']."/i" $matches['name']))
    {
    $status "$matches[name]";
    }
    $get_item mysql_fetch_array(mysql_query("SELECT * FROM tblItems WHERE name = '$status' ORDER BY RAND() LIMIT 1"));
    $get_search_stuff mysql_query("SELECT * FROM tblUserShopsItems WHERE type_id = '$get_item[itemtypeid]' ORDER BY price ASC LIMIT 50");
    while (
    $result mysql_fetch_array($get_search_stuff))
    {
    $result2 mysql_fetch_array(mysql_query("SELECT * FROM tblUserShops WHERE username = '$result[username]'"));
    $result3 mysql_fetch_array(mysql_query("SELECT * FROM tblItems WHERE itemtypeid = '$result[type_id]'"));
    print 
    "<tr><td width=25% align=center><a href=""http://venetopia.com/user_shop.php?owner=$result[username]><b>$result2[title]</b></a></td><td width=50% align=center>$result3[name]</td><td width=5% align=center>$result[instock]</td><td width=20% align=center>$result[price]</td></tr>";
    }
      }
      print 
    "</table>";
     } 

  2. #2
    if($awake){code();} PHP John's Avatar
    Join Date
    Jul 2002
    Location
    Along the Wasatch Fault line.
    Posts
    1,771
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    if ($_POST['type'] == "containing" )
    {
      
    $get_matches mysql_query("SELECT * FROM tblItems" );
      print 
    "<table border='1' cellpadding='6' cellspacing='0' align='center' width='700'>
              <tr>
                <td width='25%' align='center'><b>Shop</b></td>
                <td width='50%' align='center'><b>Item</b></td>
                <td width='5%' align='center'><b>Stock</b></td>
                <td width='20%' align='center'><b>Price</b></td>
              </tr>
              "
    ;
      while (
    $matches mysql_fetch_array($get_matches))
      {
        if (
    preg_match("/".$_POST['item']."/i" $matches['name']))
        {
          
    $status $matches['name'];
        }
        
    $get_item mysql_fetch_array(mysql_query("SELECT * 
                                                   FROM tblItems 
                                                   WHERE
                                                     name = '
    $status
                                                   ORDER BY RAND() 
                                                   LIMIT 1" 
    ));
        
    $get_search_stuff mysql_query("SELECT * 
                                         FROM tblUserShopsItems 
                                         WHERE
                                           type_id = '
    $get_item[itemtypeid]
                                         ORDER BY price 
                                         ASC LIMIT 50" 
    );
        while (
    $result mysql_fetch_array($get_search_stuff))
        {
          
    $result2 mysql_fetch_array(mysql_query("SELECT * 
                                                    FROM tblUserShops 
                                                    WHERE
                                                      username = '
    $result[username]'" ));
          
    $result3 mysql_fetch_array(mysql_query("SELECT * 
                                                    FROM tblItems 
                                                    WHERE
                                                      itemtypeid = '
    $result[type_id]'" ));
          print 
    "<tr>
                  <td width='25%' align='center'><a href="
    <A href='http://venetopia.com/user_shop.php?owner=$result[username]">[b]$result2[title][/b]</a>http://venetopia.com/user_shop.php?owner=$result[username]"><b>$result2[title]</b></a></td>
                  <td width='
    50%' align='center'>$result3[name]</td>
                  <td width='
    5%' align='center'>$result[instock]</td>
                  <td width='
    20%' align='center'>$result[price]</td>
                </tr>
                ";
        }
      }
      print "</table>";

    Damn BBS software keeps parsing the href near the bottom of the script.

    I didn't change all that much except the formatting to make it more readable.
    John

  3. #3
    SitePoint Wizard GoldFire's Avatar
    Join Date
    Oct 2002
    Location
    Oklahoma City, OK
    Posts
    1,517
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by PHP John
    PHP Code:
    if ($_POST['type'] == "containing" )
    {
    $get_matches mysql_query("SELECT * FROM tblItems" );
    print 
    "<table border='1' cellpadding='6' cellspacing='0' align='center' width='700'>
    <tr>
    <td width='25%' align='center'><b>Shop</b></td>
    <td width='50%' align='center'><b>Item</b></td>
    <td width='5%' align='center'><b>Stock</b></td>
    <td width='20%' align='center'><b>Price</b></td>
    </tr>
    "
    ;
    while (
    $matches mysql_fetch_array($get_matches))
    {
    if (
    preg_match("/".$_POST['item']."/i" $matches['name']))
    {
    $status $matches['name'];
    }
    $get_item mysql_fetch_array(mysql_query("SELECT * 
    FROM tblItems 
    WHERE
    name = '
    $status
    ORDER BY RAND() 
    LIMIT 1" 
    ));
    $get_search_stuff mysql_query("SELECT * 
    FROM tblUserShopsItems 
    WHERE
    type_id = '
    $get_item[itemtypeid]
    ORDER BY price 
    ASC LIMIT 50" 
    );
    while (
    $result mysql_fetch_array($get_search_stuff))
    {
    $result2 mysql_fetch_array(mysql_query("SELECT * 
    FROM tblUserShops 
    WHERE
    username = '
    $result[username]'" ));
    $result3 mysql_fetch_array(mysql_query("SELECT * 
    FROM tblItems 
    WHERE
    itemtypeid = '
    $result[type_id]'" ));
    print 
    "<tr>
    <td width='25%' align='center'><a href="
    <A href='http://venetopia.com/user_shop.php?owner=$result[username]">[b]$result2[title][/b]</a>http://venetopia.com/user_shop.php?owner=$result[username]"><b>$result2[title]</b></a></td>
    <td width='
    50%' align='center'>$result3[name]</td>
    <td width='
    5%' align='center'>$result[instock]</td>
    <td width='
    20%' align='center'>$result[price]</td>
    </tr>
    ";
    }
    }
    print "</table>";

    Damn BBS software keeps parsing the href near the bottom of the script. [img]images/smilies/wink.gif[/img]

    I didn't change all that much except the formatting to make it more readable.

    But that still shows all items that match. I want it to just show one type of item at a time.

  4. #4
    ********* Genius Mike's Avatar
    Join Date
    Apr 2001
    Location
    Canada
    Posts
    5,458
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Like show one, with a link to show the next one?
    Mike
    It's not who I am underneath, but what I do that defines me.

  5. #5
    SitePoint Wizard GoldFire's Avatar
    Join Date
    Oct 2002
    Location
    Oklahoma City, OK
    Posts
    1,517
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by naramation
    Like show one, with a link to show the next one?
    what i mean is that I only want to show one type of item when they search.

    i.e. If someone searches with "l" and there is an Apple and a Bowl of Rice in people's shops, then I want the search results to be :

    Bob's shop Apple* 10 points 1 in stock
    Susan's shop Apple* 15 points 3 in stock
    etc....

    then if they refresh (this should work because of the RAND() in the mysql_query) it will then probably show :

    Bob's shop Bowl of Rice* 10 points 1 in stock
    Susan's shop Bowl of Rice* 15 points 3 in stock
    etc....

    *The bold is just to emphesize that it is just that type of item and that is not meant to be shown in actual results.

  6. #6
    SitePoint Wizard GoldFire's Avatar
    Join Date
    Oct 2002
    Location
    Oklahoma City, OK
    Posts
    1,517
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    myabe the problem could be how the code is arranged....can anyone think of another way to arrange the code?

  7. #7
    SitePoint Wizard GoldFire's Avatar
    Join Date
    Oct 2002
    Location
    Oklahoma City, OK
    Posts
    1,517
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Someone gave me the suggestion to use an array to solve the problem. I am not completely sure how this would be done, does anyone have any ideas?


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
  •