Join the Stack Overflow Community
Stack Overflow is a community of 6.8 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I have a MySQL database that has a column with a bunch of descriptions. I want those in a PHP array imitating this:

$Description[0] = "Here's a description";
$Description[1] = "Here's another description";
$Description[2] = "Wow, many descriptions";
$Description[3] = "Another one";
$Description[4] = "They just keep going";
...etc

I'm struggling with the while loop logic to make this happen though. Help!

share|improve this question
3  
and what have you tried – Satya Aug 30 '15 at 3:43
    
possible duplicate of How do I create this array in PHP? – scottydelta Aug 30 '15 at 4:13
$result = mysql_query(...);
$Description = array();
while ($row = mysql_fetch_array($result)) {
    array_push($Description, $row["columnyouwant"]);
}
share|improve this answer
$Description = array();
$result = mysql_query(......);
while ($row = mysql_fetch_array($result))
{
    $Description[] = $row;
}
// echo print_r($Description);
share|improve this answer

hi very simple...

foreach ($Description as $value) {
   echo $value;
}
share|improve this answer
    
Sorry, I guess I should've specified. I just want to pull the information from my MySQL database and store the values into the $Description array, not echo them out. I don't have the values in the array yet, that's what I need help with. A While loop to pull those from my database and plop them in there. – Cherries0nTopGaming Aug 30 '15 at 3:54

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.