Jump to content

Get All MYSQLI results


davefootball123

Recommended Posts

I have a script seen below that queries a MYSQL database. It works fine for getting the first result however I need to get all the results. Can someone help me with this?

 

Thanks very much, Dave.

 

$sql ="SELECT map FROM onwarn WHERE type='SPECIAL WEATHER STATEMENT'";
$results = mysqli_query($connect,$sql);


$location = mysqli_fetch_($results);

foreach($location as $subregion) {

echo '<img style="position:absolute;left:50%;; margin-top:15px" src="/WWAMAP/SpecialWeatherStatements/'.$subregion.'.png" border="0">';


}



mysqli_close($connect);

 

 

Link to comment
https://forums.phpfreaks.com/topic/276358-get-all-mysqli-results/
Share on other sites

turn error reporting on, look at the error messages produced.

Thanks for the response Barand...there is no error. It does display the image...however it doesn't get each result. From what I know mysqli_fetch_row only gets the first result...unless im wrong. 

I tried some code...I get "Call to undefined method mysqli_result::fetch_all() in /home/sowx/public_html/dbget.php on line 15"

$connect = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname) or die ("Couldn't connect to warning server");
$sql ="SELECT map FROM onwarn WHERE type='SPECIAL WEATHER STATEMENT'";

$result_db = $connect->query($sql) or die ("Error!");
$all_result = $result_db->fetch_all();

foreach($all_result as $subregion) {

echo '<img style="position:absolute;left:50%;; margin-top:15px" src="/WWAMAP/SpecialWeatherStatements/'.$subregion.'.png" border="0">';


}



mysqli_close($connect);

Fixed...simple fix. Thanks for your support. 

 

$connect = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname) or die ("Couldn't connect to warning server");
$sql ="SELECT map FROM onwarn WHERE type='SPECIAL WEATHER STATEMENT'";

$result_db = $connect->query($sql) or die ("Error!");
while ($row = $result_db->fetch_assoc()) {

foreach ($row as $subregion) {

echo '<img style="position:absolute;left:50%;; margin-top:15px" src="/WWAMAP/SpecialWeatherStatements/'.$subregion.'.png" border="0">';


}
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.