|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
One small problem...
I'm working a script that can sort through dB results that the user specifies on a form. I had it working, but then I wanted to add one more criteria and now it's having problems with the query string. All I did was add a small part to the query - and it doesn't work anymore. This is what I added:
AND weight>=$wl AND weight<=$wh the variables $wl and $wh are specified above. Here is the new script: <?php require_once('../Connections/tvspec.php'); ?> <?php //defines type of use to recommended category and resolution if ($use == ht) { $cat="Home Theater"; $res = "(resolution = 'SVGA' OR resolution = 'XGA' OR resolution = 'SXGA' OR resolution = 'Other' OR resolution = 'WXGA')"; } elseif ($use == bus) { $cat="Business"; $res = "(resolution = 'XGA' OR resolution = 'SXGA' OR resolution = 'Other' OR resolution = 'WXGA')"; } elseif ($use == lv) { $cat="Business"; $res= "(resolution = 'XGA' OR resolution = 'SXGA' OR resolution = 'Other' OR resolution = 'WXGA')"; } //defines room condition to ansi lumen recommendation if ($rcondition == sr) {$lumens=0;} elseif ($rcondition == mr) {$lumens=1500;} elseif ($rcondition == la) {$lumens=3000;} //defines lighting condition to ansi lumen recommendation if ($lighting == cl) {$ansi=0;} elseif ($lighting == sc) {$ansi=1500;} elseif ($lighting== nc) {$ansi=3000;} //calculates average of ansi lumens $ansi_lumens = ($lumens + $ansi)/2; //gives $ansi_lumens a value if ($ansi_lumens<1500) {$lower = 0; $upper = 8000;} elseif ($ansi_lumens>=1500&& $ansi_lumens<3000) {$lower = 1500; $upper = 8000;} elseif ($ansi_lumens>=3000) {$lower = 3000; $upper = 8000;} //gives $weight high and low values if ($weight == 1) {$wh=5; $wl=0;} elseif($weight ==2) {$wh=10; $wl = 5;} elseif($weight == 3) {$wh=20; $wl = 10;} elseif($weight==4) {$wh=100; $wl=0;} $maxRows_Recordset1 = 80; $pageNum_Recordset1 = 0; if (isset($HTTP_GET_VARS['pageNum_Recordset1'])) { $pageNum_Recordset1 = $HTTP_GET_VARS['pageNum_Recordset1']; } $startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1; mysql_select_db($database_tvspec, $tvspec); $query_Recordset1 = "SELECT * FROM projectors WHERE FIND_IN_SET('$cat',projectors.category)>0 AND $res AND lumens>=$lower AND lumens<=$upper AND weight>=$wl AND weight<=$wh ORDER BY list_price ASC"; $query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1); $Recordset1 = mysql_query($query_limit_Recordset1, $tvspec) or die(mysql_error()); if (isset($HTTP_GET_VARS['totalRows_Recordset1'])) { $totalRows_Recordset1 = $HTTP_GET_VARS['totalRows_Recordset1']; } else { $all_Recordset1 = mysql_query($query_Recordset1); $totalRows_Recordset1 = mysql_num_rows($all_Recordset1); } $totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1; $maxRows_Recordset1 = 80; $pageNum_Recordset1 = 0; if (isset($HTTP_GET_VARS['pageNum_Recordset1'])) { $pageNum_Recordset1 = $HTTP_GET_VARS['pageNum_Recordset1']; } $startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1; $maxRows_Recordset1 = 80; $pageNum_Recordset1 = 0; if (isset($HTTP_GET_VARS['pageNum_Recordset1'])) { $pageNum_Recordset1 = $HTTP_GET_VARS['pageNum_Recordset1']; } $startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1; if (isset($HTTP_GET_VARS['totalRows_Recordset1'])) { $totalRows_Recordset1 = $HTTP_GET_VARS['totalRows_Recordset1']; } else { $all_Recordset1 = mysql_query($query_Recordset1); $totalRows_Recordset1 = mysql_num_rows($all_Recordset1); } $totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1; ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html><!-- InstanceBegin template="/Templates/main.dwt" codeOutsideHTMLIsLocked="false" --> <head> <!-- InstanceBeginEditable name="doctitle" --> <title>Untitled Document</title> <!-- InstanceEndEditable --> <meta http-equiv="window-target" content="_top"> <meta http-equiv="cache control" content="no-cache"> <meta name="robots" content="index, follow"> <meta name="mssmarttagspreventparsing" content="true"> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <script language="JavaScript" type="text/JavaScript"> <!-- function MM_swapImgRestore() { //v3.0 var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc; } function MM_preloadImages() { //v3.0 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array(); var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++) if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}} } function MM_findObj(n, d) { //v4.01 var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) { d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);} if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n]; for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); if(!x && d.getElementById) x=d.getElementById(n); return x; } function MM_swapImage() { //v3.0 var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3) if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];} } //--> </script> <!-- InstanceParam name="about_s" type="boolean" value="false" --><!-- InstanceParam name="about" type="boolean" value="true" --><!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable --><!-- InstanceParam name="seminars_s" type="boolean" value="false" --><!-- InstanceParam name="seminars" type="boolean" value="true" --><!-- InstanceParam name="news_s" type="boolean" value="false" --><!-- InstanceParam name="news" type="boolean" value="true" --><!-- InstanceParam name="service_s" type="boolean" value="false" --><!-- InstanceParam name="service" type="boolean" value="true" --><!-- InstanceParam name="jobs_s" type="boolean" value="false" --><!-- InstanceParam name="jobs" type="boolean" value="true" --><!-- InstanceParam name="faqs_s" type="boolean" value="false" --><!-- InstanceParam name="faqs" type="boolean" value="true" --> <link href="/css/seminardb.css" rel="stylesheet" type="text/css"> </head> <body text="#000000" link="#0000FF" onLoad="MM_preloadImages('/fireworks/images/about_f2.gif','/fireworks/images/mainmenu_r1_c4_f2.gif','/fireworks/images/news_f2.gif','/fireworks/images/service_f2.gif','/fireworks/images/mainmenu_r1_c11_f2.gif','/fireworks/images/faqs_f2.gif')"> <center> <table width="724" border="0" cellpadding="0" cellspacing="0"> <tr> <td><center> <table border="0" cellpadding="0" cellspacing="0" width="725"> <!-- fwtable fwsrc="template.png" fwbase="template.jpg" fwstyle="Dreamweaver" fwdocid = "742308039" fwnested="1" --> <tr> <td><a href="/default.htm"><img name="mainlogo" src="../fireworks/images/mainlogo.gif" width="449" height="90" border="0" alt=""></a></td> <td><table border="0" cellpadding="0" cellspacing="0" width="276"> <tr> <td><img name="options" src="../fireworks/images/options.gif" width="276" height="41" border="0" usemap="#m_options" alt=""></td> </tr> <tr> <td><!-- InstanceBeginEditable name="tag" --><a href="/default.htm"><img name="foundedtag" src="/fireworks/images/foundedtag.gif" width="276" height="49" border="0" alt="Founded in 1953"></a><!-- InstanceEndEditable --></td> </tr> </table> </td> </tr> <map name="m_options"> <area shape="poly" coords="107,11,156,11,156,22,107,22,107,11" href="../linecard.php" title="TV Specialists, Inc. Linecard" alt="TV Specialists, Inc. Linecard" > <area shape="rect" coords="157,11,220,22" href="../contact.php" title="Contact Us" alt="Contact Us" > <area shape="rect" coords="220,11,265,22" href="../search.php" title="Search the TV Specialists, Inc. Web Site" alt="Search the TV Specialists, Inc. Web Site" > </map> </table> </center></td> </tr> <tr> <td><center> <table border="0" cellpadding="0" cellspacing="0" width="725"> <!-- fwtable fwsrc="mainmenu.png" fwbase="mainmenu.jpg" fwstyle="Dreamweaver" fwdocid = "742308039" fwnested="1" --> <tr> <td><img name="mainmenu_r1_c1" src="/fireworks/images/mainmenu_r1_c1.jpg" width="130" height="20" border="0" alt=""></td> <td><a href="/about.php" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('about','','/fireworks/images/about_f2.gif',1)"><img name="about" src="/fireworks/images/about.gif" width="100" height="20" border="0" alt="About TV Specialists, Inc."></a></td> <td><a href="/seminars.php" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('mainmenu_r1_c4','','/fireworks/images/mainmenu_r1_c4_f2.gif',1)"><img name="mainmenu_r1_c4" src="/fireworks/images/mainmenu_r1_c4.gif" width="97" height="20" border="0" alt="Seminars & Events"></a></td> <td><a href="/news.php" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('news','','/fireworks/images/news_f2.gif',1)"><img name="news" src="/fireworks/images/news.gif" width="99" height="20" border="0" alt="News & Press"></a></td> <td><a href="/service.php" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('service','','/fireworks/images/service_f2.gif',1)"><img name="service" src="/fireworks/images/service.gif" width="100" height="20" border="0" alt="Service & Support"></a></td> <td><a href="/jobs.php" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('mainmenu_r1_c11','','/fireworks/images/mainmenu_r1_c11_f2.gif',1)"><img name="mainmenu_r1_c11" src="/fireworks/images/mainmenu_r1_c11.gif" width="98" height="20" border="0" alt="Employment"></a></td> <td><a href="/faqs.php" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('faqs','','/fireworks/images/faqs_f2.gif',1)"><img name="faqs" src="/fireworks/images/faqs.gif" width="100" height="20" border="0" alt="TV Specialists, Inc. FAQs"></a></td> <td><img name="mainmenu_r1_c14" src="/fireworks/images/mainmenu_r1_c14.jpg" width="1" height="20" border="0" alt=""></td> </tr> </table> </center></td> </tr> <tr> <td><center> <!-- InstanceBeginEditable name="content" --> <table width="722" border="1" cellspacing="0" cellpadding="0"> <tr> <td width="743"> <table width="700" border="0" cellspacing="0" cellpadding="10"> <tr> <td><span class="title">Recommended Projectors: </span><br> <span class="articleentry">Click on a model to see details : </span> <hr></td> </tr> <tr> <td><div align="center"> <table width="576" border="1" cellspacing="0" cellpadding="3"> <tr bgcolor="#CCCCCC" class="topics"> <td width="119"> <div align="center"><font color="#CCCCCC"><font color="#000000">Model</font></font></div></td> <td width="62"> <div align="center"><font color="#CCCCCC"><font color="#000000">Type</font></font></div></td> <td width="81"> <div align="center"><font color="#CCCCCC"><font color="#000000">Manufacturer</font></font></div></td> <td width="62"> <div align="center"><font color="#CCCCCC"><font color="#000000">Lumens</font></font></div></td> <td width="65"> <div align="center"><font color="#CCCCCC"><font color="#000000">Resolution</font></font></div></td> <td width="65"> <div align="center"><font color="#CCCCCC"><font color="#000000">Weight</font></font></div></td> <td width="64"> <div align="center"><font color="#CCCCCC"><font color="#000000">List Price </font></font></div></td> <td width="64"><font color="#000000">Your Price</font></td> </tr> <?php while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)) { ?> <tr class="articleentry"> <td> <div align="center"><a href="/projectorguide/projectors_ID.php?projID=<?php echo $row_Recordset1['model']; ?>"><?php echo $row_Recordset1['model']; ?></a></div></td> <td> <div align="center"><?php echo $row_Recordset1['type']; ?></div></td> <td> <div align="center"><?php echo $row_Recordset1['manufacturer']; ?></div></td> <td> <div align="center"><?php echo $row_Recordset1['lumens']; ?></div></td> <td> <div align="center"><?php echo $row_Recordset1['resolution']; ?></div></td> <td> <div align="center"><?php echo $row_Recordset1['weight']; ?> lbs</div></td> <td> <div align="center"><?php echo $row_Recordset1['list_price']; ?></div></td> <td>Please call</td> </tr> <?php } ?> </table> <p><span class="articleentry">Total Projectors that we recommend for your use: <?php echo $totalRows_Recordset1 ?></span> <br> <span class="entries"><a href="javascript:history.go(-1);">Go Back</a> </span></p> </div></td> </tr> </table></td> </tr> </table> <!-- InstanceEndEditable --> </center></td> </tr> <tr> <td height="57"><center> <!-- #BeginLibraryItem "/Library/phplogger.lbi" --><!-- PowerPhlogger Code START --> <script language="JavaScript" type="text/javascript" src="/Templates/pphlogger.js"></script> <noscript><img alt="" src="http://www.estats4all.com/pph/pphlogger.php?id=newtvspec&st=img"></noscript> <!-- PowerPhlogger Code END --><!-- #EndLibraryItem --><br> <!-- #BeginLibraryItem "/Library/links.lbi" --> <center> <a href="/default.htm"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Home Page</font></a><font size="1" face="Verdana, Arial, Helvetica, sans-serif"> | <a href="/home/default.htm">Home A/V Electronics</a> | <a href="/business/default.htm">Business & Professional</a> | <a href="/rentals/default.htm">Rentals </a></font> </center> <!-- #EndLibraryItem --><!-- #BeginLibraryItem "/Library/copyright.lbi" --> <center> <p><font size="1" face="Verdana, Arial, Helvetica, sans-serif"> <a href="/privacy.htm">Privacy Notice</a> | <a href="http://www.mapquest.com/maps/map.adp?ovi=1&zoom=7&mapdata=OE4WNszgW9y763X71e1WB9jkgf0hfR97EHunf0mU2e Qz6UsQObyXVX4o2M9fJh3DhGIi97gbCYmkqBbL0oBeysFMaLcF zkNj%2BPqYP1LDc2jV7nNnByAomBwAH6IKBYZJpLNJochFE6qZ 07wBvc2MA1vev3WEoiI0MzI5lCwI/7z%2BUf3qDO1ubW%2BEUmjTtq%2Bo2HniFcPUXpNJGvtk7y7lj JVUHX9wDu4T0vc4AV3%2BeZSQzMr8RhkYdiZ%2B2JW/HKXlGXjaFQ6raV4lcByciQRLmpBDmPlX81aWtBTO6P0lTYpoU8 JWO%2B5RMHlWRY7xughcr3FeW0PPFWA=" target="_blank">Locate Us</a><strong> | </strong><a href="http://server1.tvspecialists.com/v-webmail/htdocs/login.php">Employee Login</a><strong><br> © 2004-2006 TV Specialists, Inc. All rights reserved.</strong> <br> All materials on this web site, unless otherwise noted, are Copyright © 2004-2006 TV Specialists, Inc.<br> Any other trademarks used on this site are the property of their respective owners. </font></p> </center> <!-- #EndLibraryItem --> </center></td> </tr> </table> </center> </body> <!-- InstanceEnd --></html> <?php mysql_free_result($Recordset1); ?> This is the page with the form on it that takes you to the page with that script: http://tvspec.midnight007.com/projectorguide/default2.php I need to know why it isn't working or what is wrong! If you'd like to see the form that works, let me know I can send you the link and/or the scripts. |
|
#2
|
||||
|
||||
|
RE: One small problem...
Haven't looked at all the code but you might want to echo the weight value
It might be empty. Also for the code u use to set $wh etc you might want to add a default value. |
|
#3
|
|||
|
|||
|
RE: One small problem...
Now when I go through and submit the form I get this erro:
Parse error: parse error, expecting `','' or `';'' in /home/midnigh/public_html/tvspec/projectorguide/recommend2.php on line 58 - but I don't see a problem there. 47 //gives $weight high and low values 48 if ($weight == 1) 49 {$wh=5; $wl=0;} 50 elseif($weight ==2) 51 {$wh=10; $wl = 5;} 52 elseif($weight == 3) 53 {$wh=20; $wl = 10;} 54 elseif($weight==4) 55 {$wh=100; $wl=0;} 56 echo $weight 57 $maxRows_Recordset1 = 80; 58 $pageNum_Recordset1 = 0; 59 if (isset($HTTP_GET_VARS['pageNum_Recordset1'])) { 60 $pageNum_Recordset1 = $HTTP_GET_VARS['pageNum_Recordset1']; 61 } 62 $startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1; 63 64 mysql_select_db($database_tvspec, $tvspec); 65 $query_Recordset1 = "SELECT * FROM projectors WHERE FIND_IN_SET('$cat',projectors.category)>0 AND $res AND lumens>=$lower AND lumens<=$upper AND 66 weight>=$wl AND weight<=$wh ORDER BY list_price ASC"; |
|
#4
|
||||
|
||||
|
RE: One small problem...
line 56 is missing it's end ;
|
|
#5
|
|||
|
|||
|
RE: One small problem...
Ok now I'm getting this error:
You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND weight<= ORDER BY list_price ASC LIMIT 0, 80' at line 1 Here is my query string: $query_Recordset1 = "SELECT * FROM projectors WHERE FIND_IN_SET('$cat',projectors.category)>0 AND $res AND lumens>=$lower AND lumens<=$upper AND weight>=$wl AND weight<=$wh ORDER BY list_price ASC"; |
|
#6
|
|||
|
|||
|
RE: One small problem...
$wh does not have a value stored in it..that causes the error.
|
|
#7
|
|||
|
|||
|
RE: One small problem...
Shouldn't this bit of code assign a value to it?
if ($weight == 1) {$wh=5; $wl=0;} elseif($weight ==2) {$wh=10; $wl = 5;} elseif($weight == 3) {$wh=20; $wl = 10;} elseif($weight==4) {$wh=100; $wl=0;} |
|
#8
|
|||
|
|||
|
RE: One small problem...
Again I have to repeat what Nicky said in her first reply.
Quote:
I know you are setting value in $wh with few IF conditions. What happens in case value stored in $weight doesn't match any of your IF,ELSEIF conditions? You should use a ELSE part, I guess. eg.Note: Above one is only an example. |
|
#9
|
|||
|
|||
|
RE: One small problem...
The code is working, values are being passed - and even the right ones. So that variable isn't the problem. But I am still getting an error in mysql ONLY when I test it in Dreamweaver - it doesn't show up online. This is the error Dreamweaver gives me:
You have an error in your syntax. Check the manual that corresponds to your MYSQL server version for the right syntax to use near'AND lumens>=0 AND lumens<=8000 ORDER BY list_price ASC LIMIT 0' Here is my query string: $query_Recordset1 = "SELECT * FROM projectors WHERE FIND_IN_SET('$cat',projectors.category)>0 AND $res AND lumens>=$lower AND lumens<=$upper ORDER BY list_price ASC "; I'm using MySQL version 4.0.18 and PHP version 4.3.4 |
|
#10
|
|||||
|
|||||
|
RE: One small problem...
Try this:
php Code:
$res might also be 0 Try echoing the $query_Recordset1 to the screen to see that actual text. Please post it here as well. |
|
#11
|
|||
|
|||
|
RE: One small problem...
Still getting an error - but now it says this:
You have an error in your syntax. Check the manual that corresponds to your MYSQL server version for the right syntax to use near'AND (lumens>=0) AND (lumens<=8000) ORDER BY list_price ASC LIMIT 0' |
|
#12
|
|||
|
|||
|
RE: One small problem...
AND since I didn't realize I was logged in under anonymous and can't edit my message:
Here is the query string: $query_Recordset1 = "SELECT * FROM projectors WHERE (FIND_IN_SET('$cat',projectors.category)>0) AND $res AND (lumens>=$lower) AND (lumens<=$upper) AND (weight>=$wl) AND (weight<=$wh) ORDER BY list_price ASC "; I'm also now echoing the recordset on the page: http://tvspec.midnight007.com/projectorguide/default2.php (make some selections and submit it) |