Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.
Moderator: General Moderators
-
PatJunkins
- Forum Newbie
- Posts: 9
- Joined: Sat Feb 07, 2004 5:44 pm
- Location: Maine
Post
by PatJunkins »
Trying to do an exact search on the partnnumber field then if not there in the description field.
Code: Select all
$pn = ($pn == "" ? $pn = "%" : $pn = $pn);
$description = ($description == "" ? $description = "%" : $description = $description);
$query = mysql_query("SELECT part_number,description,price,weight FROM suzukiparts WHERE part_number LIKE '%$pn%' AND description LIKE '%$description%'")or die(mysql_error());
if (mysql_num_rows($query) > 0) {
while(list($o_part_number,$o_description,$o_price,$o_weight) = mysql_fetch_row($query)) {
if (stristr($o_description, "USE PART#")) {
list($p1,$part_num) = explode("# ",$o_description);
print "<body bgcolor="orange"><table border="0"><font face="arial" size="-1"><center><b><h4>Updated Part Number, Click on new number <a href="spart3.php?pn=$part_num">$part_num</a>\n";
}
else {
print "<body bgcolor="yellow"><table border="0" width="100%" align="left"><tr valign="top"><td width="20%"><b><big>Part# </b></big> $o_part_number</td><td width="25%"><b><big>Desc </big></b> $o_description</td><td width="15%"><b><big>Price</big></b> $o_price</td><td width="5%"><b><big>Quantity </big></b></td><td width="20%"><form METHOD="POST" ACTION="http://www.alpha-sports.com/cgi-bin/cart.cgi" type="image" SRC="images/add2cart.gif" alt="Add to cart..." name="I1" target="_self"><input type="hidden" name="return" value="http://www.alpha-sports.com/footer.html"><input type="hidden" name="price" value="$o_price"><input type="hidden" name="name" value="$o_description"><INPUT TYPE="TEXT" NAME=quantity VALUE="1" SIZE="2" MAXLENGTH="2"><input type="hidden" name="custom1" value="$o_description"> <input type="hidden" name="custom2" value="Stock# $o_part_number"> <input type="hidden" name="sh" value="$o_weight"> <INPUT TYPE="HIDDEN" NAME="redirect" TARGET="main1" VALUE="1"> <input type="hidden" name="add" value="1"><input alt="Add to cart..." name="I3" src="images/add2cart.gif" type="image"><INPUT TYPE="hidden" name="redirect" value="2"></form><td width="5%"><form METHOD="POST" ACTION="http://www.alpha-sports.com/cgi-bin/cart.cgi" target="_top"><input alt="Go to shopping cart checkout..." name="I4" src="new_images/checkoutButton_61x22.gif" type="image"></form></td></tr></table>\n";
}
}
} else {
print "<body bgcolor="red"><table border="0"><font face="arial" size="-1"><center><b><h4>Part number is no longer in the price book. Email us the part number, model and description for the price.";
}
-
xisle
- Forum Contributor
- Posts: 249
- Joined: Wed Jun 25, 2003 1:53 pm
Post
by xisle »
so whats the problemo, any errors?
Also if you could put line breaks in your code, more people may try to help.
Ayup!

-
Draco_03
- Forum Regular
- Posts: 577
- Joined: Fri Aug 15, 2003 12:25 pm
- Location: Montreal, Canada
Post
by Draco_03 »
hey you should edit your post and insted of the tag
Code: Select all
it'll help for ppl who want to read it
-
PatJunkins
- Forum Newbie
- Posts: 9
- Joined: Sat Feb 07, 2004 5:44 pm
- Location: Maine
Post
by PatJunkins »
Code: Select all
<?php
$connect = mysql_connect("a", "b", "c");
mysql_select_db("m");
$part_number = ($part_number == "" ? $part_number = "%" : $part_number = $part_number);
$description = ($description == "" ? $description = "%" : $description = $description);
$query = mysql_query("SELECT part_number,description,price,weight FROM suzukiparts WHERE part_number LIKE '%$part_number%' AND description LIKE '%$description%'")or die(mysql_error());
if (mysql_num_rows($query) > 0) {
while(list($o_part_number,$o_description,$o_price,$o_weight) = mysql_fetch_row($query)) {
if (stristr($o_description, "USE PART#")) {
list($p1,$part_num) = explode("# ",$o_description);
print "<body bgcolor="orange"><table border="0"><font face="arial" size="-1"><center><b><h4>Updated Part Number, Click on new number <a href="spart.php?part_number=$part_num">$part_num</a>\n";
}
else {
print "<body bgcolor="yellow"><table border="0" width="100%" align="left"><tr valign="top"><td width="20%"><b><big>Part# </b></big> $o_part_number</td><td width="25%"><b><big>Desc </big></b> $o_description</td><td width="15%"><b><big>Price</big></b> $o_price</td><td width="5%"><b><big>Quantity </big></b></td><td width="20%"><form METHOD="POST" ACTION="http://www.alpha-sports.com/cgi-bin/cart.cgi" type="image" SRC="images/add2cart.gif" alt="Add to cart..." name="I1" target="_self"><input type="hidden" name="return" value="http://www.alpha-sports.com/footer.html"><input type="hidden" name="price" value="$o_price"><input type="hidden" name="name" value="$o_description"><INPUT TYPE="TEXT" NAME=quantity VALUE="1" SIZE="2" MAXLENGTH="2"><input type="hidden" name="custom1" value="$o_description"> <input type="hidden" name="custom2" value="Stock# $o_part_number"> <input type="hidden" name="sh" value="$o_weight"> <INPUT TYPE="HIDDEN" NAME="redirect" TARGET="main1" VALUE="1"> <input type="hidden" name="add" value="1"><input alt="Add to cart..." name="I3" src="images/add2cart.gif" type="image"><INPUT TYPE="hidden" name="redirect" value="2"></form><td width="5%"><form METHOD="POST" ACTION="http://www.alpha-sports.com/cgi-bin/cart.cgi" target="_top"><input alt="Go to shopping cart checkout..." name="I4" src="new_images/checkoutButton_61x22.gif" type="image"></form></td></tr></table>\n";
}
}
} else {
print "<body bgcolor="red"><table border="0"><font face="arial" size="-1"><center><b><h4>Part number is no longer in the price book. Email us the part number, model and description for the price.";
}
?>
?>
-
PatJunkins
- Forum Newbie
- Posts: 9
- Joined: Sat Feb 07, 2004 5:44 pm
- Location: Maine
Post
by PatJunkins »
That should be better... Sorry about that.

-
Draco_03
- Forum Regular
- Posts: 577
- Joined: Fri Aug 15, 2003 12:25 pm
- Location: Montreal, Canada
Post
by Draco_03 »
i don't know what s your probleme but there's error in your html code..
you don't close your form, and you don t close the end of the last line
Code: Select all
<?php
$connect = mysql_connect("a", "b", "c");
mysql_select_db("m");
$part_number = ($part_number == "" ? $part_number = "%" : $part_number = $part_number);
$description = ($description == "" ? $description = "%" : $description = $description);
$query = mysql_query("SELECT part_number,description,price,weight FROM suzukiparts WHERE part_number LIKE '%$part_number%' AND description LIKE '%$description%'")or die(mysql_error());
if (mysql_num_rows($query) > 0) {
while(list($o_part_number,$o_description,$o_price,$o_weight) = mysql_fetch_row($query)) {
if (stristr($o_description, "USE PART#")) {
list($p1,$part_num) = explode("# ",$o_description);
print "<body bgcolor="orange"><table border="0"><font face="arial" size="-1"><center><b><h4>Updated Part Number, Click on new number <a href="spart.php?part_number=$part_num">$part_num</a>\n";
}
else {
print "
<body bgcolor="yellow">
<table border="0" width="100%" align="left">
<tr valign="top">
<td width="20%"><b><big>Part# </b></big>$o_part_number</td>
<td width="25%"><b><big>Desc </big></b> $o_description</td>
<td width="15%"><b><big>Price</big></b> $o_price</td>
<td width="5%"><b><big>Quantity </big></b></td>
<td width="20%">
<form METHOD="POST" ACTION="http://www.alpha-sports.com/cgi-bin/cart.cgi" type="image" SRC="images/add2cart.gif" alt="Add to cart..." name="I1" target="_self">
<input type="hidden" name="return" value="http://www.alpha-sports.com/footer.html">
<input type="hidden" name="price" value="$o_price">
<input type="hidden" name="name" value="$o_description">
<INPUT TYPE="TEXT" NAME=quantity VALUE="1" SIZE="2" MAXLENGTH="2">
<input type="hidden" name="custom1" value="$o_description">
<input type="hidden" name="custom2" value="Stock# $o_part_number">
<input type="hidden" name="sh" value="$o_weight">
<INPUT TYPE="HIDDEN" NAME="redirect" TARGET="main1" VALUE="1">
<input type="hidden" name="add" value="1"><input alt="Add to cart..." name="I3" src="images/add2cart.gif" type="image">
<INPUT TYPE="hidden" name="redirect" value="2"></form><td width="5%">
//Should you close your form ???
</form>
<form METHOD="POST" ACTION="http://www.alpha-sports.com/cgi-bin/cart.cgi" target="_top">
<input alt="Go to shopping cart checkout..." name="I4" src="new_images/checkoutButton_61x22.gif" type="image"></form></td></tr></table>\n";
}
}
} else {
print "
<body bgcolor="red">
<table border="0"><font face="arial" size="-1">
<center><b><h4>Part number is no longer in the price book. Email us the part number, model and description for the price.";
// this has to be in to.. unless you have it after the code you posted
</h4></b></center>
}
?>
-
PatJunkins
- Forum Newbie
- Posts: 9
- Joined: Sat Feb 07, 2004 5:44 pm
- Location: Maine
Post
by PatJunkins »
What about the search logic though... I come up with multiple results instead of just one. Want to find exact or look in description...
THX
-
Draco_03
- Forum Regular
- Posts: 577
- Joined: Fri Aug 15, 2003 12:25 pm
- Location: Montreal, Canada
Post
by Draco_03 »
i m not sure at all.. but a hint is iin your query put LIMIT 1 ..
-
llanitedave
- Forum Commoner
- Posts: 78
- Joined: Thu Jan 15, 2004 11:24 am
- Location: Las Vegas, NV.
Post
by llanitedave »
It's hard to read your logic -- apparently it is for you as well.
You need more white space, and some well-placed comments.
(I'm not all that accomplished at sight-reading code yet)
Do you want to find an exact match for the part number?
Failing that, to find an exact match for description?
If so, don't use "Like %$part_number%" in your queries.
Use "= $part_number" instead.
Otherwise, you're almost guaranteed to find multiple results.
-
PatJunkins
- Forum Newbie
- Posts: 9
- Joined: Sat Feb 07, 2004 5:44 pm
- Location: Maine
Post
by PatJunkins »
I did try that but then it wouldn't find anything. Do I have to trim the data of white spaces or is PHP and MySql a little more forgiving?
TIA