jaxdevil Posted February 22, 2008 Share Posted February 22, 2008 Where did I go wrong (all this code works, just not since I changed it to a LIKE statement. <?php mysql_connect(localhost,xxx_xxx,xxxxxx); // Use correct stuff there mysql_select_db(xxx_xxx) or die(mysql_error()); // Use Database Name $cat=products; // Select total results for pagination $result = mysql_query("SELECT count(*) FROM products WHERE `specs` LIKE '%$restaurant_equipment%'"); $num_records = mysql_result($result,0,0); // Set maximum number of rows and columns $max_num_rows = 1; $max_num_columns = 4; $per_page = $max_num_columns * $max_num_rows; // Work out how many pages there are $total_pages = ceil($num_records / $per_page); // Get the current page number if (isset($_GET['page'])) $page = $_GET['page']; else $page = 1; // Work out the limit offset $start = ($page - 1) * $per_page; // Select the results we want including limit and offset $result = mysql_query("SELECT `mod` FROM products WHERE `specs` LIKE '%$restaurant_equipment%' ORDER BY `mod` LIMIT $start, $per_page"); $named = mysql_query("SELECT `name` FROM products WHERE `specs` LIKE '%$restaurant_equipment%' ORDER BY `mod` LIMIT $start, $per_page"); $maker = mysql_query("SELECT `man` FROM products WHERE `specs` LIKE '%$restaurant_equipment%' ORDER BY `mod` LIMIT $start, $per_page"); $cost = mysql_query("SELECT `price` FROM products WHERE `specs` LIKE '%$restaurant_equipment%' ORDER BY `mod` LIMIT $start, $per_page"); $num_columns = ceil(mysql_num_rows($result)/$max_num_rows); $num_rows = ceil(mysql_num_rows($result)/$num_columns); // Echo the results ?> <br> <? echo "<center><table width=\"700\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" align=\"center\">\n"; for ($r = 0; $r < $max_num_rows; $r++){ echo "<tr>\n"; for ($c = 0; $c < $max_num_columns; $c++){ // 1 $x = $r * $max_num_columns + $c; if ($x < mysql_num_rows($result)){ // $y = mysql_result($result, $x, 0); // Commented out so I could show your example $num = mysql_result($result, $x, 0); $name = mysql_result($named, $x, 0); $make = mysql_result($maker, $x, 0); $price = mysql_result($cost, $x, 0); $unformated_price = $price; $price = number_format($unformated_price, 2, '.', ','); $y = <<<HTML <table cellpadding="0" cellspacing="0" border="0" width="174"> <tr valign="top" background="/images/mainimageerror.gif"> <td width="174" height="225" background="/productimages/{$num}_tn.jpg"> <a href="/productimages/{$num}.jpg"><img src="/productimages/overlay.png" border="0"></a> </td> </tr> <tr valign="top"> <td height="40"> <font face="Tahoma" color="#2b86c5" style="font-size:0.75em"><b> {$name} </font></b> </td> </tr> <tr> <td height="10"> <font face="Tahoma" color="#000000" style="font-size:0.60em"><b> {$make} </font></b> </td> </tr> <tr> <td height="10"> <font face="Tahoma" color="#000000" style="font-size:0.60em"><b> Model # {$num} </font></b> </td> </tr> <tr> <td height="10"> <font face="Tahoma" color="#94200d" style="font-size:0.70em"><b> $ {$price} </font></b> </td> </tr> <tr> <td> <a href="/product.php?restaurant_equipment={$num}"><img src="images/details.gif" border="0"></a> </td> <td> <img src="/images/spacer.gif" width="8"> </td> </tr> <tr> <td> <br style="line-height:3px;"> <form method="post" action="ShoppingCart.php" style="display: inline;"> <input name="Title" type="hidden" value="{$name}" /> <input name="SerialNum" type="hidden" value="{$num}" /> <input name="Price" type="hidden" value="{$unformated_price}" /> <input name="Shipping1" type="hidden" value="0.00" /> <input name="Shipping2" type="hidden" value="0.00" /> <input name="cmd" type="hidden" id="cmd" value="1" /> <input type="image" src="images/addtocart.gif" name="submit"> </form> </div> </td> <td> <img src="/images/spacer.gif" width="8"> </td> </tr> <tr> <td> <img src="images/spacer.gif" height="10"> </td> </tr> </table> HTML; } else { $y = '<table align="center" border="0" cellpadding="0" cellspacing="0" width="145"> <tr> <td width="16" align="center"><center></center></td> </tr> </table>'; } echo "<td>"; echo "$y"; echo "</td>"; } echo "</tr>\n"; } // Echo page numbers echo "</table></center>\n"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/92491-solved-like-statement-not-working/ Share on other sites More sharing options...
revraz Posted February 22, 2008 Share Posted February 22, 2008 What results are you seeing? Quote Link to comment https://forums.phpfreaks.com/topic/92491-solved-like-statement-not-working/#findComment-473883 Share on other sites More sharing options...
wildteen88 Posted February 22, 2008 Share Posted February 22, 2008 For one thing looking at your code, the following should be combined: $result = mysql_query("SELECT `mod` FROM products WHERE `specs` LIKE '%$restaurant_equipment%' ORDER BY `mod` LIMIT $start, $per_page"); $named = mysql_query("SELECT `name` FROM products WHERE `specs` LIKE '%$restaurant_equipment%' ORDER BY `mod` LIMIT $start, $per_page"); $maker = mysql_query("SELECT `man` FROM products WHERE `specs` LIKE '%$restaurant_equipment%' ORDER BY `mod` LIMIT $start, $per_page"); $cost = mysql_query("SELECT `price` FROM products WHERE `specs` LIKE '%$restaurant_equipment%' ORDER BY `mod` LIMIT $start, $per_page"); You are doing the same query each time, except you return a different row. You can return multiple rows from a query like so: $result = mysql_query("SELECT `mod`, `name`, `man`, `price` FROM products WHERE `specs` LIKE '%$restaurant_equipment%' ORDER BY `mod` LIMIT $start, $per_page"); Quote Link to comment https://forums.phpfreaks.com/topic/92491-solved-like-statement-not-working/#findComment-473890 Share on other sites More sharing options...
jaxdevil Posted February 22, 2008 Author Share Posted February 22, 2008 Nothing at all. When I place the codes back as they were ( `specs`='$restaurant_equipment' ) it shows me 4 items, the change makes it come up blank. The rest of the page still works so the php isn't broken anywhere, it just is incorrect in the format somehow. Help me please! SK Quote Link to comment https://forums.phpfreaks.com/topic/92491-solved-like-statement-not-working/#findComment-473895 Share on other sites More sharing options...
revraz Posted February 22, 2008 Share Posted February 22, 2008 Where is the code that sets $restaurant_equipment Quote Link to comment https://forums.phpfreaks.com/topic/92491-solved-like-statement-not-working/#findComment-473900 Share on other sites More sharing options...
jaxdevil Posted February 22, 2008 Author Share Posted February 22, 2008 Its transmitted via POST, the page is product.php?restaurant_equipment=SD-0603W , there are other codes that use that post on the page, they all work, and this one worked when it was looking for items that absolutely equaled that model (SD-0603W) but now that I changed it to look for any specs (product descriptions) that contain that model number (which would mean they are items related to the item, so thats why I am trying to display them in this section of the page) it pulls up nothing, even though there are definitely 20 or 30 items that should match it. The only thing I changed is it going from an = to a LIKE and adding the % before and after the term. Any ideas? Thanks for helping so far. SK Quote Link to comment https://forums.phpfreaks.com/topic/92491-solved-like-statement-not-working/#findComment-473902 Share on other sites More sharing options...
jaxdevil Posted February 22, 2008 Author Share Posted February 22, 2008 Maybe someone can do more with this info... I modified the code somewhat, it now pulls up info, but its all wildcards, just a % is searched for, but it pulls up entries. Now how can I get it to pull up entries related to the product number? Any time I place that variable in the results bring up nothing. <?php // Select total results for pagination $result = mysql_query("SELECT count(*) FROM products WHERE `specs` LIKE '%'") or die(mysql_error()); $num_records = mysql_result($result,0,0); // Set maximum number of rows and columns $max_num_rows = 1; $max_num_columns = 4; $per_page = $max_num_columns * $max_num_rows; // Work out how many pages there are $total_pages = ceil($num_records / $per_page); // Get the current page number if (isset($_GET['page'])) $page = $_GET['page']; else $page = 1; // Work out the limit offset $start = ($page - 1) * $per_page; // Select the results we want including limit and offset $result = mysql_query("SELECT `mod` FROM products WHERE `specs` LIKE '%' ORDER BY `mod` LIMIT $start, $per_page") or die(mysql_error()); $named = mysql_query("SELECT `name` FROM products WHERE `specs` LIKE '%' ORDER BY `mod` LIMIT $start, $per_page") or die(mysql_error()); $maker = mysql_query("SELECT `man` FROM products WHERE `specs` LIKE '%' ORDER BY `mod` LIMIT $start, $per_page") or die(mysql_error()); $cost = mysql_query("SELECT `price` FROM products WHERE `specs` LIKE '%' ORDER BY `mod` LIMIT $start, $per_page") or die(mysql_error()); $num_columns = ceil(mysql_num_rows($result)/$max_num_rows); $num_rows = ceil(mysql_num_rows($result)/$num_columns); // Echo the results ?> <br> <? echo "<center><table width=\"700\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" align=\"center\">\n"; for ($r = 0; $r < $max_num_rows; $r++){ echo "<tr>\n"; for ($c = 0; $c < $max_num_columns; $c++){ // 1 $x = $r * $max_num_columns + $c; if ($x < mysql_num_rows($result)){ // $y = mysql_result($result, $x, 0); // Commented out so I could show your example $num = mysql_result($result, $x, 0); $name = mysql_result($named, $x, 0); $make = mysql_result($maker, $x, 0); $price = mysql_result($cost, $x, 0); $unformated_price = $price; $price = number_format($unformated_price, 2, '.', ','); $y = <<<HTML <table cellpadding="0" cellspacing="0" border="0" width="174"> <tr valign="top" background="/images/mainimageerror.gif"> <td width="174" height="225" background="/productimages/{$num}_tn.jpg"> <a href="/productimages/{$num}.jpg"><img src="/productimages/overlay.png" border="0"></a> </td> </tr> <tr valign="top"> <td height="40"> <font face="Tahoma" color="#2b86c5" style="font-size:0.75em"><b> {$name} </font></b> </td> </tr> <tr> <td height="10"> <font face="Tahoma" color="#000000" style="font-size:0.60em"><b> {$make} </font></b> </td> </tr> <tr> <td height="10"> <font face="Tahoma" color="#000000" style="font-size:0.60em"><b> Model # {$num} </font></b> </td> </tr> <tr> <td height="10"> <font face="Tahoma" color="#94200d" style="font-size:0.70em"><b> $ {$price} </font></b> </td> </tr> <tr> <td> <a href="/product.php?restaurant_equipment={$num}"><img src="images/details.gif" border="0"></a> </td> <td> <img src="/images/spacer.gif" width="8"> </td> </tr> <tr> <td> <br style="line-height:3px;"> <form method="post" action="ShoppingCart.php" style="display: inline;"> <input name="Title" type="hidden" value="{$name}" /> <input name="SerialNum" type="hidden" value="{$num}" /> <input name="Price" type="hidden" value="{$unformated_price}" /> <input name="Shipping1" type="hidden" value="0.00" /> <input name="Shipping2" type="hidden" value="0.00" /> <input name="cmd" type="hidden" id="cmd" value="1" /> <input type="image" src="images/addtocart.gif" name="submit"> </form> </div> </td> <td> <img src="/images/spacer.gif" width="8"> </td> </tr> <tr> <td> <img src="images/spacer.gif" height="10"> </td> </tr> </table> HTML; } else { $y = '<table align="center" border="0" cellpadding="0" cellspacing="0" width="145"> <tr> <td width="16" align="center"><center></center></td> </tr> </table>'; } echo "<td>"; echo "$y"; echo "</td>"; } echo "</tr>\n"; } // Echo page numbers echo "</table></center>\n"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/92491-solved-like-statement-not-working/#findComment-473939 Share on other sites More sharing options...
jaxdevil Posted February 22, 2008 Author Share Posted February 22, 2008 I figured it out. In case anyone is interested.... <?php // Select total results for pagination $result = mysql_query("SELECT count(*) FROM products WHERE `specs` LIKE '%$restaurant_equipment%' OR `man` LIKE '%$restaurant_equipment%' OR `mod` LIKE '%$restaurant_equipment%' OR `name` LIKE '%$restaurant_equipment%'") or die(mysql_error()); $num_records = mysql_result($result,0,0); // Set maximum number of rows and columns $max_num_rows = 1; $max_num_columns = 4; $per_page = $max_num_columns * $max_num_rows; // Work out how many pages there are $total_pages = ceil($num_records / $per_page); // Get the current page number if (isset($_GET['page'])) $page = $_GET['page']; else $page = 1; // Work out the limit offset $start = ($page - 1) * $per_page; // Select the results we want including limit and offset $result = mysql_query("SELECT `mod` FROM products WHERE `specs` LIKE '%$restaurant_equipment%' OR `man` LIKE '%$restaurant_equipment%' OR `mod` LIKE '%$restaurant_equipment%' OR `name` LIKE '%$restaurant_equipment%' ORDER BY `mod` LIMIT $start, $per_page") or die(mysql_error()); $named = mysql_query("SELECT `name` FROM products WHERE `specs` LIKE '%$restaurant_equipment%' OR `man` LIKE '%$restaurant_equipment%' OR `mod` LIKE '%$restaurant_equipment%' OR `name` LIKE '%$restaurant_equipment%' ORDER BY `mod` LIMIT $start, $per_page") or die(mysql_error()); $maker = mysql_query("SELECT `man` FROM products WHERE `specs` LIKE '%$restaurant_equipment%' OR `man` LIKE '%$restaurant_equipment%' OR `mod` LIKE '%$restaurant_equipment%' OR `name` LIKE '%$restaurant_equipment%' ORDER BY `mod` LIMIT $start, $per_page") or die(mysql_error()); $cost = mysql_query("SELECT `price` FROM products WHERE `specs` LIKE '%$restaurant_equipment%' OR `man` LIKE '%$restaurant_equipment%' OR `mod` LIKE '%$restaurant_equipment%' OR `name` LIKE '%$restaurant_equipment%' ORDER BY `mod` LIMIT $start, $per_page") or die(mysql_error()); $num_columns = ceil(mysql_num_rows($result)/$max_num_rows); $num_rows = ceil(mysql_num_rows($result)/$num_columns); // Echo the results ?> <br> <? echo "<center><table width=\"700\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" align=\"center\">\n"; for ($r = 0; $r < $max_num_rows; $r++){ echo "<tr>\n"; for ($c = 0; $c < $max_num_columns; $c++){ // 1 $x = $r * $max_num_columns + $c; if ($x < mysql_num_rows($result)){ // $y = mysql_result($result, $x, 0); // Commented out so I could show your example $num = mysql_result($result, $x, 0); $name = mysql_result($named, $x, 0); $make = mysql_result($maker, $x, 0); $price = mysql_result($cost, $x, 0); $unformated_price = $price; $price = number_format($unformated_price, 2, '.', ','); $y = <<<HTML <table cellpadding="0" cellspacing="0" border="0" width="174"> <tr valign="top" background="/images/mainimageerror.gif"> <td width="174" height="225" background="/productimages/{$num}_tn.jpg"> <a href="/productimages/{$num}.jpg"><img src="/productimages/overlay.png" border="0"></a> </td> </tr> <tr valign="top"> <td height="40"> <font face="Tahoma" color="#2b86c5" style="font-size:0.75em"><b> {$name} </font></b> </td> </tr> <tr> <td height="10"> <font face="Tahoma" color="#000000" style="font-size:0.60em"><b> {$make} </font></b> </td> </tr> <tr> <td height="10"> <font face="Tahoma" color="#000000" style="font-size:0.60em"><b> Model # {$num} </font></b> </td> </tr> <tr> <td height="10"> <font face="Tahoma" color="#94200d" style="font-size:0.70em"><b> $ {$price} </font></b> </td> </tr> <tr> <td> <a href="/product.php?restaurant_equipment={$num}"><img src="images/details.gif" border="0"></a> </td> <td> <img src="/images/spacer.gif" width="8"> </td> </tr> <tr> <td> <br style="line-height:3px;"> <form method="post" action="ShoppingCart.php" style="display: inline;"> <input name="Title" type="hidden" value="{$name}" /> <input name="SerialNum" type="hidden" value="{$num}" /> <input name="Price" type="hidden" value="{$unformated_price}" /> <input name="Shipping1" type="hidden" value="0.00" /> <input name="Shipping2" type="hidden" value="0.00" /> <input name="cmd" type="hidden" id="cmd" value="1" /> <input type="image" src="images/addtocart.gif" name="submit"> </form> </div> </td> <td> <img src="/images/spacer.gif" width="8"> </td> </tr> <tr> <td> <img src="images/spacer.gif" height="10"> </td> </tr> </table> HTML; } else { $y = '<table align="center" border="0" cellpadding="0" cellspacing="0" width="145"> <tr> <td width="16" align="center"><center></center></td> </tr> </table>'; } echo "<td>"; echo "$y"; echo "</td>"; } echo "</tr>\n"; } // Echo page numbers echo "</table></center>\n"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/92491-solved-like-statement-not-working/#findComment-473949 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.