SitePoint Sponsor |
|
User Tag List
Results 1 to 6 of 6
-
Jan 4, 2005, 22:33 #1
Displaying only part of a mysql result set..?
If I have a mysql result set in $thisVar that contains say 100 rows...and what I want to do is to display the rows as fields of a table...but only for rows that are greater than x and less than y.
When mysql results are gathered, does each row get an "id" number or something that could be used to tell if it's the 20th row or the 25th row that was returned?
Thanks,
Cranjled
-
Jan 4, 2005, 22:42 #2
- Join Date
- Oct 2004
- Location
- New Jersey
- Posts
- 235
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
PHP Code:$startRow = 20;
$endRow = 30;
$i = 0;
$sel = mysql_query ("SELECT fieldname FROM table");
while (mysql_fetch_array($sel)) {
if ($i > $startRow && $i <= $endRow) {
echo $fet['fieldname'] . '<br />';
}
$i++;
}
- Trog
-
Jan 4, 2005, 23:32 #3
Thanks, that worked nicely.
-
Jan 4, 2005, 23:45 #4
- Join Date
- Oct 2004
- Location
- New Jersey
- Posts
- 235
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Excellent! No prob.
-
Jan 5, 2005, 04:48 #5
How about this
PHP Code:$start_row = 19;
$num_rows = 10;
$sql = 'SELECT fieldname FROM table LIMIT ' . $start_row . ',' . $num_rows;
$result = mysql_query($sql);
while ($row = mysql_fetch_assoc($result))
{
echo $row['fieldname'] . '<br />';
}
For more info, look at http://dev.mysql.com/doc/mysql/en/SELECT.html
-
Jan 5, 2005, 11:22 #6
Thanks to you too swdev.
Bookmarks