Question

This is my current code

$goalquery = "SELECT goal FROM Goals";

if ($result = $mysqli->query($goalquery))
$goal = $result->fetch_row();

foreach($goal as $value){
   ?> My goal is <?php echo $value;
 }

and it displays enter image description here

But it should return at least 3 values for $goal

It should say...

My goal is to hang my clothing
My goal is to drink less coffee
My goal is to go to the gym everyday
Was it helpful?

Solution

Instead of fetching a row i think you might want to fetch associations

$goal = $result->fetch_assoc();

From documentation

  • Returns an associative array that corresponds to the fetched row or NULL if there are no more rows.

fecth_row() function you used will only return one row

  • Fetches one row of data from the result set and returns it as an enumerated array, where each column is stored in an array offset starting from 0 (zero). Each subsequent call to this function will return the next row within the result set, or NULL if there are no more rows.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top