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

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.