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.";
$searchtype = addslashes($searchtype);
$searchterm = addslashes($searchterm);
@ $db = mysql_pconnect("localhost", "p", "n");
echo "Error: Could not connect to database. Please try again.";
$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 "<br></strong><strong>-- Manufacturer: </strong>";
echo "<br></strong><strong>-- Description: </strong>";
echo "<br></strong><strong>-- Mfg List Price: </strong>";
Do you have index on part_number in database?
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.
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.