Jump to content

Query in Array


Canman2005

Recommended Posts

Hi all

 

I have an array in my php code

 

$aUsers = array(
"Ädams, Egbert",
"Zaun, Jillie",
);

 

Is there anyway to populate the array with a SQL query such as

 

$sql = "SELECT * FROM `members`";
$show = @mysql_query($sql,$connection) or die(mysql_error());
while ($row = mysql_fetch_array($show))
{
print "name"
}

 

Any help would be smashing

 

Thanks in advance

 

Dave

Link to comment
https://forums.phpfreaks.com/topic/107142-query-in-array/
Share on other sites

If I understand what your wanting, try this:

 

<?php

$aUsers = array(
"Ädams, Egbert",
"Zaun, Jillie",
);

$sql = "SELECT * FROM `members`";
$show = @mysql_query($sql,$connection) or die(mysql_error());

while ($row = mysql_fetch_array($show)){
   $aUsers[] = $row['name'];
}

//new array with names added
echo '<pre>',print_r($aUsers),'</pre>';

?>

Link to comment
https://forums.phpfreaks.com/topic/107142-query-in-array/#findComment-549313
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.