Page 1 of 1

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

Posted: Sun Feb 16, 2003 9:57 pm
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

Posted: Sun Feb 16, 2003 10:09 pm
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']