Prashanth Prashanth - 1 year ago 69
SQL Question

How to display multiple array value in PHP?

I am having an trouble in displaying values in PHP.

Value pass through URL


Here is my code

$id = $_GET['mode']; // Id get from URL
//echo $id;
$query = "SELECT `job_title` FROM `job` WHERE `job_id` IN ($id)";
$res = mysqli_query($conn, $query);

foreach(($row = mysqli_fetch_array($res)) as $key1){
$key[] = $key1;

PHP Code:

<?php echo $key;?>

Hence it is in looping so it shows the last looped value. Is it possible to display the all values through loop.

Help me out guys!!

Answer Source

You have multiple options to output an array.

Echo and foreach

You c an loop through your array and echo each $key and $value

foreach ($keys as $key => $value) {
    echo $key." : ".$value."<br />";

print_r and var_dump

This is mostly used in debugging.




You can implode your array to echo the concatted values.

// The first parameter is the devider or separator
echo implode('', $keys);


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download