Jump to content

[SOLVED] Simple script... help with 'greater than' and 'less than' statements (newb)


impfut

Recommended Posts

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();
?>

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.

 

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 :P

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

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.