FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


How i can go to a row when i use mysql_fetch_row?





babarus
For example i use mysql_fetch_row to get first 5 records from my table. After my script do 4: following instruction
Code:
$row=mysql_fetch_row($sql); echo $row[0];
i want to go to the first row and ptint it again. How i can do that?

My english is not so good!so i hope that you will understand what i wanted to say! And i hope that somebody help me!
imagefree
your first row is at $row[0], simply use
Code:
var_dump($row[0]);
Peterssidan
What imagefree writes is not true.


I think you can use mysql_data_seek.
Example to go to first row:
Code:
mysql_data_seek($sql, 0)

After this mysql_fetch_row will start from the beginning.
Fire Boar
Or, if you want to use imagefree's approach, you can read all data into an array. I'd suggest doing something like this however:

Code:
$firstrow;
while ($row = mysql_fetch_row($sql))
{
  if (empty($firstrow))
  {
    $firstrow = $row;
  }
  echo $row[0];
}


After this, $firstrow will contain the first row retrieved.
Related topics
script backup database
Display Country Flags
How To : Improve Your PHP Programming
MySQL DB Backup script - minor problem
Database/PHP/Cron Jobs [Resolved]
Follow the user
simple login script
php if statement confusion
My first PHP + mySQL page - Need feedback
mySQL - Day, date, month, year, time Output/Input
RSS Generator script
Decreasing num. Queries
Get links from a database
Login problem
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.