View Full Version : Change output to variable

09-15-2006, 08:33 PM
Hi, I hope I am putting this question in the right place, I am not entirely sure where it needs to be... I am working on a project, where I want to pull various emails from the database, display them on a page, then be able to click something to email all of them. I have two parts working, but I need to connect them. I have the database and I am able to query it and output what I need. It is currently outputting as email links, using this:

if ($myrow = @mysql_fetch_array($result))
{echo "<UL>";}
echo "<LI>";
echo "<A HREF=mailto:\"",$myrow["email"],"\">",$myrow["Name"];
echo "</A>"; "<BR>";
} while ($myrow = @mysql_fetch_array($result));

What I really need is for that information to instead end up like this, inside the javascript code:

//Set name and email for each employee:
var employee=[];
employee[0]=['Name 1', 'email1'];
employee[1]=['Name 2', 'email2'];
employee[2]=['Name 3', 'email3'];

Is this possible? I am a complete moron at this stuff, I can't believe I've even gotten it to work this far. Thanks :)

09-15-2006, 09:24 PM
This really belongs in the PHP forum but you might get some help here. In any case, you are almost home, you just need to write out a script and an array before the script that will use the array. My PHP is not good, something like:

if ($myrow = @mysql_fetch_array($result)) {
echo "<script type='text/javascript'>";
echo "var employee=[];";
echo "employee[employee.length]=['",$myrow["Name"],"', '",$myrow["email"],"']";
} while ($myrow = @mysql_fetch_array($result));
echo "</script>";

But, the PHP forum folks would be better at the correct syntax.

09-15-2006, 09:57 PM
Thank you, thank you, thank you!!! I think I have it working now after a couple minor tweaks!