Hi!
Can someone please help me out with the following snipplet. I am still learning php, and I am a bit confused with the changes I have made. Mainly with $getrows and $query.
Here is what I want to do:
I want my customer to be able to search the products database (through a form) by the partial/full description of the product (desciption field name: descr) and get the results back in a nicely formated search result page. The results should also display the cost, manu_part, part_num fields (also in the same table).
I don't yet understand how to get a partial description query to work, and a displaying multipal results onto a page. I think I need to use the LIKE command to this?
Any help will be greatly appreciated.
Thanks!
Syed
-----Begin Search.php3-----
<FORM ACTION="./Search_Descr.php3" METHOD="GET">
<INPUT TYPE="text" NAME="descr" SIZE="25" MAXLENGTH="115" VALUE=http://www.phpbuilder.com/board/archive/index.php/"Enter Description">
<INPUT TYPE="submit" VALUE="Submit">
<INPUT TYPE="reset" VALUE="Rest">
</FORM>
-----End Search.php3-----
-----Begin Search_Descr.php3-----
<?
$server = "localhost";
$userid = "root";
$pass = "";
$database = "XYZ";
$dbtable = "products";
$limit = 20;
$con = mysql_connect("$server","$userid","$pass") or die ("Huh? What Server");
$db = mysql_select_db("$database",$con) or die("I said WHAT database");
if (empty($offset) || $offset< 0) {
$offset=0;
}
if (empty($index)) $index=0;
$getrows = mysql_query("SELECT * from products", $con);
$numrows=mysql_num_rows($getrows);
$query = mysql_query("SELECT descr, cost, manu_part, part_num from products where descr='$descr' limit $offset,$limit", $con);
while ($result=mysql_fetch_array($query)){
$index++;
}
if ($numrows <= $limit) {
}
else {
if ($offset!=0) {
$prevoffset=$offset-$limit;
echo "<a onMouseOver=\"window.status='Previous $limit Results'; return true\"; href=http://www.phpbuilder.com/board/archive/index.php/\"$PHP_SELF?offset=$prevoffset&index=$prevoffset\"><B>[Previous]</B></a>   ";
}
else echo "<b><font color=666666>[Previous]</font></b>   ";
$pages = intval($numrows/$limit);
if ($numrows%$limit) {
$pages++;
}
for ($i=1;$i<=$pages;$i++) {
if (($offset/$limit) == ($i-1)) {
echo " <b><font color=666666>$i</font></b> ";
} else {
$newoffset=$limit*($i-1);
echo " <a onMouseOver=\"window.status='Page $i Results'; return true\"; href=http://www.phpbuilder.com/board/archive/index.php/\"$PHP_SELF?offset=$newoffset&index=$newoffset\"><B>$i</B></a> \n";
}
}
if (!((($offset/$limit)+1)==$pages) && $pages!=1) {
$newoffset=$offset+$limit;
echo "    <a onMouseOver=\"window.status='Next $limit Results'; return true\"; href=http://www.phpbuilder.com/board/archive/index.php/\"$PHP_SELF?offset=$newoffset&index=$newoffset\"><B>[Next]</B></a><p>\n";
}
else echo "   <b><font color=666666>[Next]</font></b>";
}
mysql_close($con);
?>
-----End Search_Descr.php3-----
Can someone please help me out with the following snipplet. I am still learning php, and I am a bit confused with the changes I have made. Mainly with $getrows and $query.
Here is what I want to do:
I want my customer to be able to search the products database (through a form) by the partial/full description of the product (desciption field name: descr) and get the results back in a nicely formated search result page. The results should also display the cost, manu_part, part_num fields (also in the same table).
I don't yet understand how to get a partial description query to work, and a displaying multipal results onto a page. I think I need to use the LIKE command to this?
Any help will be greatly appreciated.
Thanks!
Syed
-----Begin Search.php3-----
<FORM ACTION="./Search_Descr.php3" METHOD="GET">
<INPUT TYPE="text" NAME="descr" SIZE="25" MAXLENGTH="115" VALUE=http://www.phpbuilder.com/board/archive/index.php/"Enter Description">
<INPUT TYPE="submit" VALUE="Submit">
<INPUT TYPE="reset" VALUE="Rest">
</FORM>
-----End Search.php3-----
-----Begin Search_Descr.php3-----
<?
$server = "localhost";
$userid = "root";
$pass = "";
$database = "XYZ";
$dbtable = "products";
$limit = 20;
$con = mysql_connect("$server","$userid","$pass") or die ("Huh? What Server");
$db = mysql_select_db("$database",$con) or die("I said WHAT database");
if (empty($offset) || $offset< 0) {
$offset=0;
}
if (empty($index)) $index=0;
$getrows = mysql_query("SELECT * from products", $con);
$numrows=mysql_num_rows($getrows);
$query = mysql_query("SELECT descr, cost, manu_part, part_num from products where descr='$descr' limit $offset,$limit", $con);
while ($result=mysql_fetch_array($query)){
$index++;
}
if ($numrows <= $limit) {
}
else {
if ($offset!=0) {
$prevoffset=$offset-$limit;
echo "<a onMouseOver=\"window.status='Previous $limit Results'; return true\"; href=http://www.phpbuilder.com/board/archive/index.php/\"$PHP_SELF?offset=$prevoffset&index=$prevoffset\"><B>[Previous]</B></a>   ";
}
else echo "<b><font color=666666>[Previous]</font></b>   ";
$pages = intval($numrows/$limit);
if ($numrows%$limit) {
$pages++;
}
for ($i=1;$i<=$pages;$i++) {
if (($offset/$limit) == ($i-1)) {
echo " <b><font color=666666>$i</font></b> ";
} else {
$newoffset=$limit*($i-1);
echo " <a onMouseOver=\"window.status='Page $i Results'; return true\"; href=http://www.phpbuilder.com/board/archive/index.php/\"$PHP_SELF?offset=$newoffset&index=$newoffset\"><B>$i</B></a> \n";
}
}
if (!((($offset/$limit)+1)==$pages) && $pages!=1) {
$newoffset=$offset+$limit;
echo "    <a onMouseOver=\"window.status='Next $limit Results'; return true\"; href=http://www.phpbuilder.com/board/archive/index.php/\"$PHP_SELF?offset=$newoffset&index=$newoffset\"><B>[Next]</B></a><p>\n";
}
else echo "   <b><font color=666666>[Next]</font></b>";
}
mysql_close($con);
?>
-----End Search_Descr.php3-----