Results 1 to 3 of 3

Thread: Change output to variable

  1. #1
    Join Date
    Sep 2006
    Posts
    20
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Change output to variable

    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:

    PHP Code:
    if ($myrow = @mysql_fetch_array($result))
    {echo 
    "<UL>";}
    do
    {
    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:
    PHP 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

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    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:

    PHP Code:
    if ($myrow = @mysql_fetch_array($result)) {
    echo 
    "<script type='text/javascript'>"
    do 

    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.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Sep 2006
    Posts
    20
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Thank you, thank you, thank you!!! I think I have it working now after a couple minor tweaks!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •