0

Hey all i have a mind bug with this wile loop , i am a bit of a noob

$sql_advanced_bio = mysql_query("SELECT * FROM bio_details WHERE mem_id='$id'");
while($row = mysql_fetch_assoc($sql_advanced_bio)){


$bio_time_family = $row["bio_time_family"];

}

So this is the php now in my HTML i have this

*php echo $bio_time_family *

Why dose it echo only one value ?

SIMPLE ANSWER so i tried somethingh easier like this $bio_fun_family .= $row["bio_fun_family"].",";

and then this

$bio_fun_family = substr($bio_fun_family,0,-1);

I added the .next to the =

It appends the values

0

3 Answers 3

1

You need to store the values in an array, otherwise you're just overwriting one variable each time, so you'll just end up with the last value.

You also need to use a loop to echo out each value in the array.

$sql_advanced_bio = mysql_query("SELECT * FROM bio_details WHERE mem_id='$id'");
$bio_time_family = array();
while($row = mysql_fetch_assoc($sql_advanced_bio)) {
   $bio_time_family[] = $row["bio_time_family"];
}

And then for the output;

foreach($bio_time_family as $b) {
   echo($b . '<br />');
}
Sign up to request clarification or add additional context in comments.

Comments

0

With each iteration of the while loop, you're assigning to $bio_time_family the newly extracted value. If you'd like to make an array of the, instead, use $bio_time_family[] = $row["bio_time_family"];

1 Comment

zou should use print_r($bio_time_family), not echo, when you want to visualize an array.
0

Because every time you run through the loop you're re-assigning $bio_time_family to the next row's value. Try calling echo directly in your loop or add the row to an array, then loop through that and output the rows

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.