Tuesday, July 1, 2008

Ways to process result set in php mysql

3 ways we can use to run a so-called 'mysql loop' to retrieve data from results in mysql database.

1. mysql_fetch_row()
2. mysql_fetch_assoc()
3. mysql_fetch_object()

Example:
1. mysql_fetch_row()

if (mysql_num_rows($result)>0){
while($row = mysql_fetch_row($result)){
echo $row[0]. "\n";
}

}


2. mysql_fetch_assoc()

if (mysql_num_rows($result)>0){
while($row = mysql_fetch_assoc($result)){
echo $row['item_name']."\n";
}
}


3. mysql_fetch_object()

if (mysql_num_rows($result)>0){
while($row = mysql_fetch_object($result)){
echo $row->itemName."\n";
}
}

0 comments: