Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Need help with PHP/MySQL
Index -> Programming, PHP -> PHP Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Numbah51




PostPosted: 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
Sponsor
sponsor
wtd




PostPosted: Mon Nov 06, 2006 8:40 am   Post subject: (No subject)

Perhaps:

code:
$5


Is a typo?
rdrake




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




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




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




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




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




PostPosted: Mon Nov 06, 2006 11:44 pm   Post subject: (No subject)

omg thank you that works perfectly! Smile
Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, PHP -> PHP Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 8 Posts ]
Jump to:   


Style:  
Search: