After a query how do I display a certain row only?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
3dron
Forum Commoner
Posts: 40
Joined: Sat Feb 01, 2003 10:25 pm

After a query how do I display a certain row only?

Post by 3dron »

I have a query that returns me all 24 records in a database.

Now how can I format different areas of a page to show different rows.

I.E. if I use echo $row_query... it shows me the first record.

How can I for example show the 5th record?

Ron
User avatar
Stoker
Forum Regular
Posts: 782
Joined: Thu Jan 23, 2003 9:45 pm
Location: SWNY
Contact:

Post by Stoker »

Code: Select all

<?php

  $dbc = mysql_connect('user','name','pass');
  mysql_select_db('mydb',$dbc);

  $res = mysql_query ('SELECT col1,col2,col3 FROM mytable',$dbc);

  $mydata = array();
  while ( $row = mysql_fetch_assoc($res) ) $mydata[] = $row;

  echo 'Here is col2 from row 3:' . $mydata[2]['col2'] .'<br>'."\n";

?>
An array index starts at 0, so row 5 would be $mydata[4]['columname']
Post Reply