Retrieving Multiple Data from a Database

Retrieving multiple data from a database running on a local xampp server but not running on a cpanel server. The database is successfully connected. Some work well, the problem is only getting a few data.

$sql_query_slider="SELECT * FROM slider ORDER BY id DESC LIMIT $slide_limit ";
$result_slider=mysqli_query($dbconfig,$sql_query_slider);
<?php foreach ($result_slider as $res) {?>
    <?php echo $res['slider_desc']; ?>
<?php } ?>
+4
source share
2 answers

try

<?php while ($row = mysqli_fetch_assoc($result_slider)) { 
var_dump($row);
 } ?>

You cannot run the result mysqli_querythrough a foreach loop, since it is not an array. What you need to do is process the result using some function mysqli_fetch, in this case mysqli_fetch_assocor mysqli_fetch_array, which returns each row of the query result as an associative array.

+5
source

:

    while($row = mysqli_fetch_array($result_slider)){
     echo $row[1]; //this will print out the first index in the result array.
}
0

Source: https://habr.com/ru/post/1622713/


All Articles