SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Jan 2003
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    better code???????

    Hi-
    When i run a querry from mysql command line using the following:
    "select * from stock_item where part_number='abcd';"

    i get a result returned in .2 seconds.

    when i use the following code it seems to take a long long time. Can someone please help?

    <?
    if (!
    $searchtype || !$searchterm)
    {
    echo
    "You have not entered search details. Please go back and try again.";
    exit;
    }
    $searchtype = addslashes($searchtype);
    $searchterm = addslashes($searchterm);
    @
    $db = mysql_pconnect("localhost", "p", "n");
    if (!
    $db)
    {
    echo
    "Error: Could not connect to database. Please try again.";
    exit;
    }
    mysql_select_db(
    "inventory");
    $query = "select * from stock_item where part_number like ".$searchterm.";
    $result = mysql_query($query);
    $num_results = mysql_num_rows($result);
    echo "
    <p>Number found: ".$num_results."</p>";
    for (
    $i=0; $i <$num_results; $i++)
    {
    $row = mysql_fetch_array($result);
    echo "
    <p><strong>".($i+1).". Part Number: ";
    echo stripslashes(
    $row["part_number"]);
    echo "
    <br></strong><strong>-- Manufacturer: </strong>";
    echo stripslashes(
    $row["mfg"]);
    echo "
    <br></strong><strong>-- Description: </strong>";
    echo stripslashes(
    $row["description"]);
    echo "
    <br></strong><strong>-- Mfg List Price: </strong>";
    echo stripslashes(
    $row["list"]);

    echo "
    </p>";
    }
    ?>

  2. #2
    SitePoint Guru
    Join Date
    Jan 2001
    Location
    Alkmaar, Netherlands
    Posts
    710
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I use
    while($row=mysql_fetch_array($result)){
    ,,.,,
    }

    Do you have index on part_number in database?

  3. #3
    SitePoint Member
    Join Date
    Jan 2003
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i changed my original query to the following and it works very very fast now:

    $query = "select * from temp_item where part_number = '".$searchterm."'";

    But i have 2 new problems.

    1- if i search a number like 519806-3 only the base number of 519806 is returned.

    2- if i look for an alphanumeric number like P504 the entire database is being returned.

    is it possible i need to change my part_number row to blob or something? it is set as interger now.

  4. #4
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,608
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    If part_number is set as an Integer then there won't be any data values like 519806-3 or P504 since these are not integer number values.
    Ian Anderson
    www.siteguru.co.uk


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
  •