Posted: Mon Nov 06, 2006 12:04 am Post subject: Need help with PHP/MySQL
I have a list of things in my database, numbered under the column 'Number'. What i'm trying to do is to display 5. I want it to work so that the page will be like whatever.php?start=0 and it will display videos 56-60 (if there is 60 videos in the database) and if start=1 then it will display videos 51-55. The query i attemped and failed at using was:
code:
<?PHP
$x=$_GET['start'];
include "_.db/config.php";
include "_.db/opendb.php";
$query="SELECT * FROM 'Videos' WHERE 'Number' BETWEEN ((MAX(Number)-5)-(5*$x)) AND (MAX(Number)-($5*x))";
$result = mysql_query($query);
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
//All the stuff i want it to do etc
echo $row['Number'];
echo "<BR>";
}
include "_.db/closedb.php";
?>
Any help would be VERY GREATLY appreciated
Sponsor Sponsor
wtd
Posted: Mon Nov 06, 2006 8:40 am Post subject: (No subject)
Perhaps:
code:
$5
Is a typo?
rdrake
Posted: Mon Nov 06, 2006 8:43 am Post subject: (No subject)
Just a few nitpicks...
$x is not a very meaningful variable name. Also, the value of $x should be sanitized. Remember not to trust anything that comes from outside sources.
How exactly is this failing? Can you give is an example? Let's say you set start=10.
Numbah51
Posted: Mon Nov 06, 2006 9:46 am Post subject: (No subject)
wtd wrote:
Perhaps:
code:
$5
Is a typo?
i just typed it wrong when i typed it here. It should be
code:
5*$x
And it doesn't work like it gives a SQL error. Even when i just put $x=0 it doesn't work.
rdrake
Posted: Mon Nov 06, 2006 9:55 am Post subject: (No subject)
Numbah51 wrote:
wtd wrote:
Perhaps:
code:
$5
Is a typo?
i just typed it wrong when i typed it here. It should be
code:
5*$x
And it doesn't work like it gives a SQL error. Even when i just put $x=0 it doesn't work.
What is the exact error?
Numbah51
Posted: Mon Nov 06, 2006 10:01 am Post subject: (No subject)
Unfortunately I'm at school right now, i'll post it when i get home. Thanks for your time so far btw.
octopi
Posted: Mon Nov 06, 2006 1:09 pm Post subject: (No subject)
code:
$query="SELECT * FROM 'Videos' WHERE 'Number' BETWEEN ((MAX(Number)-5)-(5*$x)) AND (MAX(Number)-($5*x))";
I haven't looked at your code to determine if thers typos or not, but a more common way to do this is as follows:
code:
$query="SELECT * FROM `Videos` order by `Number` ASC limit $x,5
you can change ASC to DESC to switch between ascending, and descending results.
Numbah51
Posted: Mon Nov 06, 2006 11:44 pm Post subject: (No subject)