Here is my problem. I need more than one row from the database, and i need the first row for certain task and then go through all the list again to create a record set.
$query = "SELECT * FROM mytable";
$result = mysql_query($query);
$firstrow = //extract first row from database
//add display some field from it
while($row = mysql_fetch_assoc($result)) {
//display all of them
}
Now, how to extract just the first row?
SUBSTRING() function in MySQL function in MySQL is used to derive substring from any given string . It extracts a string with a specified length, starting from a given location in an input string. The purpose of substring is to return a specific portion of the string.
you can use Object oriented style :
$query = "SELECT * FROM mytable";
$result = mysql_query($query);
if ( $row = $result->fetch_assoc()){
$firstRow = $row;
mysql_data_seek($result, 0);
while( $row = $result->fetch_assoc()) {
//display all of them
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With