473,386 Members | 1,790 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Limit rows based on a value?

Hello,

I am trying to filter an array that I am pulling from a mySQL database using PHP.

My question is if there is a way to LIMIT the number of rows that are pulled from the database with a mathematical operation in the SQL statement. I think it would something like:

Expand|Select|Wrap|Line Numbers
  1. $sql = sprintf(SELECT * FROM data WHERE day = CURdate()-INTERVAL 1 day AND statistic_id = %d ORDER BY value DESC LIMIT value > %d, $statistic_id, $selected_value);
  2.  
My objective is to be able to filter the array after a user selects a value from a dropdown option list. The value in the drop down would be stored in the URL and $selected_value would be determined by this value in the URL by the _GET method.

Any help on this would be appreciated!
Thanks!
Sep 28 '10 #1
1 2080
Oralloy
988 Expert 512MB
Yes, but you need to include the mathematical relationship as part of your where clause, like so:

Expand|Select|Wrap|Line Numbers
  1. $sql = sprintf(SELECT * 
  2.                  FROM data
  3.                  WHERE (day = CURdate()-INTERVAL 1 day)
  4.                    AND (statistic_id = %d)
  5.                    AND (value > %d)
  6.                  ORDER BY value DESC,
  7.                $statistic_id,
  8.                $selected_value); 
  9.  
p.s. If I screwed up the PHP code, forgive me, I'm trying to convey the structure of the SQL, and I don't really know PHP that well.
Sep 28 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Mark Sargent | last post by:
Hi All, been away from developing, if you can call what I do that, and am stumped already..lol..see code below. I'm trying to get each row to display, based on the if statements. Hope you can...
1
by: Tamer Higazi | last post by:
Hi! I have problems creating joins between tables and to limit rows for a specified clolumn. I have 2 tables! employees departments I face the problems with the GROUP BY clause and i don't...
1
by: Lurre | last post by:
Hallo! I have small or big problem. I want creat Store Procedurs whit limit rows. For example I need rows from 100 to 200. --Select * from table How I doing best way.
2
by: Steven Blair | last post by:
Hi, I have a DataSet with 30 rows. I pass this DataSet to my reporting module and this needs the first 10 rows. Does C# have a way of filtering the DataSet so I can use only the first 10 rows...
11
by: jimstruckster | last post by:
I have a table with 10 rows, I want all rows except for the first to be hidden when the page first opens up. If the user puts a value in a text box in the first row then I want the second row to...
0
by: josh.23.french | last post by:
Here's the code i have: $db = array(); //main array $db = array(); //table `main` $db = array('id'=>0, 'username'=>'joshfrench','userpass'=>'password','userlevel'=>'admin'); //row $db =...
7
by: tasmontique | last post by:
I have an access table that outputs to excel using a query . However what I am trying to do is under the arrival date column specify a criteria based on the Datepart function that only displays...
22
by: chromis | last post by:
Hi, I'm trying to display a table of highscores, but I don't want to display more than one highscore from the same person aka duplicates in the name column. I tryed this: $sql = "SELECT...
4
by: ravir81 | last post by:
Hi, I am currently working on excel validation using Perl. I am new to Excel validation but not for Perl. I have a question regarding one of the validation. Could anyone please tell me how to get...
3
by: Vinda | last post by:
Hi Bytes, Using a previous question as a base Access 2000 Inserting multiple rows based on a date range. I also wanted to insert multiple rows into a table according to a date range supplied by a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.