impfut Posted December 21, 2008 Share Posted December 21, 2008 Hi guys, looks a cool forum full of people. I've just started getting into PHP. It's really cool (reminds me of building lego when I was a kid) BUT I'm having problems with simple things at the moment. I want to be able to select all records from my table based on whether the value in a column called "Total" is greater than X but less than Y. No idea how to do it though ??? Here's my code, can a guru help me please? <?php include("../opendb.php"); mysql_select_db($dbname2); $tbl_name = "applications"; $low = "49"; $high = "70"; $total = (> $low && < $high); $sql="SELECT * FROM $tbl_name WHERE total = '$total'"; $result=mysql_query($sql); // Start looping rows in mysql database. echo "<ul>\n"; while($rows=mysql_fetch_array($result)){ ?> <li><? echo $rows['date']; ?> - <a href="<? echo $rows['url']; ?>" title="<? echo $rows['title']; ?>" target="_blank"><? echo $rows['title']; ?></a></li> <? // close while loop } echo "</ul>"; // close connection mysql_close(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/137899-solved-simple-script-help-with-greater-than-and-less-than-statements-newb/ Share on other sites More sharing options...
blueman378 Posted December 21, 2008 Share Posted December 21, 2008 $sql="SELECT * FROM $tbl_name WHERE total <= '$high' AND total >= '$low'"; cant remember but i think that should work... Quote Link to comment https://forums.phpfreaks.com/topic/137899-solved-simple-script-help-with-greater-than-and-less-than-statements-newb/#findComment-720715 Share on other sites More sharing options...
DeanWhitehouse Posted December 21, 2008 Share Posted December 21, 2008 You can use mathematical operators in sql statments e.g. $sql="SELECT * FROM $tbl_name WHERE total > '$x' AND total < '$y'"; $sql="SELECT * FROM $tbl_name WHERE total <= '$high' AND total >= '$low'"; cant remember but i think that should work... That is greater than or equal to , and less than or equal to. Quote Link to comment https://forums.phpfreaks.com/topic/137899-solved-simple-script-help-with-greater-than-and-less-than-statements-newb/#findComment-720716 Share on other sites More sharing options...
blueman378 Posted December 21, 2008 Share Posted December 21, 2008 oh yeah if your starting out ill tell you now dont use short open tags, and especially not mixing them... 50% because its bad practice 50% because the phpfreaks people wont stop nagging you about it Quote Link to comment https://forums.phpfreaks.com/topic/137899-solved-simple-script-help-with-greater-than-and-less-than-statements-newb/#findComment-720717 Share on other sites More sharing options...
blueman378 Posted December 21, 2008 Share Posted December 21, 2008 opps yeah forgot to mention that, figured hed be able to work it out... Quote Link to comment https://forums.phpfreaks.com/topic/137899-solved-simple-script-help-with-greater-than-and-less-than-statements-newb/#findComment-720718 Share on other sites More sharing options...
DeanWhitehouse Posted December 21, 2008 Share Posted December 21, 2008 http://uk2.php.net/operators.comparison Quote Link to comment https://forums.phpfreaks.com/topic/137899-solved-simple-script-help-with-greater-than-and-less-than-statements-newb/#findComment-720723 Share on other sites More sharing options...
impfut Posted December 21, 2008 Author Share Posted December 21, 2008 AWESOME!!! It's working now, you guys are great! I come from a branding/html/css/photoshop background so PHP is new to me but I'm really enjoying it. I'm still struggling with the fundamentals of how the language "thinks" but once I grasp this I'm sure I'll be fine. Classes, functions etc.. are all very scary at the moment lol. Here's our site if anyone is interested http://www.nodusawards.com official launch should be at the start of Jan. If you do have a look and spot any problems, please let me know. Thanks again!! Dave Quote Link to comment https://forums.phpfreaks.com/topic/137899-solved-simple-script-help-with-greater-than-and-less-than-statements-newb/#findComment-720727 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.