-
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>";
}
?>
-
I use
while($row=mysql_fetch_array($result)){
,,.,,
}
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
Bookmarks