Jump to content

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. 

Edited by davefootball123

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">';


}
}
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.