tj71587 Posted October 11, 2007 Share Posted October 11, 2007 I'm getting kinda frustrated and wondering what I am doing wrong. I have a form that posts two values, tech and site and named them accordingly. When I enter in both a tech and a site the code works or when I enter in neither the code works, when I enter in one or the other and leave the value to all for either I am unable to get any return. I believe my syntax is right and have tried all the versions of the does not equal sign. If anyone could help I would really appreciate it. Thanks, T.J. <?php include 'includes/config.php'; include 'includes/opendb.php'; $tech1=$_POST['tech']; $site1=$_POST['site']; echo $site1; echo $tech1; if ($site1 <> 'All' && $tech1 == 'All') { $query ="SELECT * FROM helpdesk h WHERE h.site = '$site1'"; } if ($site1 == 'All' && $tech1 <> 'All') { $query ="SELECT * FROM helpdesk h WHERE h.tech = '$tech1'"; } if ($site1 == 'All' && $tech1 == 'All') { $query ="SELECT * FROM helpdesk h"; } else { $query ="SELECT * FROM helpdesk h WHERE h.tech = '$tech1' AND h.site = '$site1'"; } $result = mysql_query($query); while($r=mysql_fetch_array($result)) { //the format is $variable = $r["nameofmysqlcolumn"]; //modify these to match your mysql table columns $tech=$r["tech"]; $ticketno=$r["ticketno"]; $connect=$r["connect"]; $date=$r["date"]; $site=$r["site"]; $rmnum=$r["rmnum"]; $problem=$r["problem"]; $resolution=$r["resolution"]; $connected=$r["connected"]; //display the row echo "<tr>"; echo "<td>"; echo $tech; echo "</td>"; echo "<td>"; echo $ticketno; echo "</td>"; echo "<td>"; echo $connect; echo "</td>"; echo "<td>"; echo $date; echo "</td>"; echo "<td>"; echo $site; echo "</td>"; echo "<td>"; echo $rmnum; echo "</td>"; echo "<td>"; echo $problem; echo "</td>"; echo "<td>"; echo $resolution; echo "</td>"; echo "<td>"; echo $connected; echo "</td>"; } include 'includes/closedb.php'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/72802-solved-help-please/ Share on other sites More sharing options...
thedarkwinter Posted October 11, 2007 Share Posted October 11, 2007 i cant remember off hand how php deals with and's and or's and whether you need brackets or not, but try doing this <?php //... if ( ($site1 == 'All') and ($tech1 <> 'All') ) ... etc for all of those statements Quote Link to comment https://forums.phpfreaks.com/topic/72802-solved-help-please/#findComment-367151 Share on other sites More sharing options...
tj71587 Posted October 11, 2007 Author Share Posted October 11, 2007 Thanks for the suggestion, but still no go. Quote Link to comment https://forums.phpfreaks.com/topic/72802-solved-help-please/#findComment-367156 Share on other sites More sharing options...
thedarkwinter Posted October 11, 2007 Share Posted October 11, 2007 ... also i think <> should be replaces with != Quote Link to comment https://forums.phpfreaks.com/topic/72802-solved-help-please/#findComment-367164 Share on other sites More sharing options...
tj71587 Posted October 11, 2007 Author Share Posted October 11, 2007 I've tried using all different kinds of not equal, <>, !=, and !== and none do the trick. Quote Link to comment https://forums.phpfreaks.com/topic/72802-solved-help-please/#findComment-367166 Share on other sites More sharing options...
thedarkwinter Posted October 11, 2007 Share Posted October 11, 2007 k i think ive got it this time you need to put else's before the second and third if because its defaulting to the last "else" if this doesn't work then maybe i stop giving stupid suggestions <?php /... if ($site1 <> 'All' && $tech1 == 'All') { $query ="SELECT * FROM helpdesk h WHERE h.site = '$site1'"; } else if ($site1 == 'All' && $tech1 <> 'All') { $query ="SELECT * FROM helpdesk h WHERE h.tech = '$tech1'"; } else if ($site1 == 'All' && $tech1 == 'All') { $query ="SELECT * FROM helpdesk h"; } else { $query ="SELECT * FROM helpdesk h WHERE h.tech = '$tech1' AND h.site = '$site1'"; } Quote Link to comment https://forums.phpfreaks.com/topic/72802-solved-help-please/#findComment-367171 Share on other sites More sharing options...
tj71587 Posted October 11, 2007 Author Share Posted October 11, 2007 You got it, thanks so much. Quote Link to comment https://forums.phpfreaks.com/topic/72802-solved-help-please/#findComment-367179 Share on other sites More sharing options...
ingeva Posted October 11, 2007 Share Posted October 11, 2007 Before you believe all errors are gone, take a look at this: if ($site1 == 'All' && $tech1 == 'All') { $query ="SELECT * FROM helpdesk h"; } See the FROM helpdesk line; there's an extra double quote. If this is a copy/paste from your original script, you should check that. php will be looking for the next double quote.... Quote Link to comment https://forums.phpfreaks.com/topic/72802-solved-help-please/#findComment-367187 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.