MySQL query
Moderator: General Moderators
MySQL query
Dear All,
Bit of a while since I've been using these forums, nice to be back!
Can anyone tell me what query I can use to SELECT the n-th row from a data table (i.e. only dependent on the position of the row in the table, not the row's values).
Many thanks
Mark Seaden (mjseaden@hotmail.com)
Bit of a while since I've been using these forums, nice to be back!
Can anyone tell me what query I can use to SELECT the n-th row from a data table (i.e. only dependent on the position of the row in the table, not the row's values).
Many thanks
Mark Seaden (mjseaden@hotmail.com)
-
malcolmboston
- DevNet Resident
- Posts: 1826
- Joined: Tue Nov 18, 2003 1:09 pm
- Location: Middlesbrough, UK
if you are using an auto-incrementing row ID
dont know if this is what you mean
Code: Select all
$query = "SELECT * FROM mytable WHERE ID ='3'";to select a random row, do this query
Mark
Code: Select all
$sql = "SELECT * FROM mytable ORDER BY rand() LIMIT 1";-
malcolmboston
- DevNet Resident
- Posts: 1826
- Joined: Tue Nov 18, 2003 1:09 pm
- Location: Middlesbrough, UK
ok, i can start it
now you can sort out the print statement
Code: Select all
$query = "SELECT * FROM tablename";
$result = mysql_query($query) or die(mysql_error());
$num_rows = mysql_num_rows($result);
// now create a randomiser
$random_num = rand(1, $numrows);
$fetch_row = mysql_fetch_row($random_num)
print "$fetch_row";to select a certain row in the table if you don't have an id do this
This will return the 5th row. change the 5 to return whatever row you want.
Mark
Code: Select all
$sql = "SELECT * FROM mytable LIMIT 5, 1";Mark
Last edited by JayBird on Tue Apr 20, 2004 10:38 am, edited 1 time in total.
-
malcolmboston
- DevNet Resident
- Posts: 1826
- Joined: Tue Nov 18, 2003 1:09 pm
- Location: Middlesbrough, UK