简体   繁体   中英

How to create a simple PHP array from a result in a MySQL query?

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!

$result = mysql_query(...);
$Description = array();
while ($row = mysql_fetch_array($result)) {
    array_push($Description, $row["columnyouwant"]);
}
$Description = array();
$result = mysql_query(......);
while ($row = mysql_fetch_array($result))
{
    $Description[] = $row;
}
// echo print_r($Description);

hi very simple...

foreach ($Description as $value) {
   echo $value;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM