SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Wizard creole's Avatar
    Join Date
    Oct 2000
    Location
    Nashvegas Baby!
    Posts
    7,845
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey all, I got the script working that I was having problems with (see http://sitepointforums.com/showthrea...readid=10657).

    The script grabs the user list from my database and prints out name and email in a series of mailto: links. Now I want to be able to add one big long mailto: with all of the users emails like this:

    <a onmouseover="showStatus('email everyone'); return true;" href="mailto:emails go here">email everyone</a>

    My questions are:
    1) After the PHP script parses the $result variable in the last while loop, does $result still contain data?

    2) If it does not, then would I have to run another query?

    3) or is there a better way of doing that?

    <?php
    //start editing here
    $dbhost = "localhost"; //db host name
    $dbuser = "user"; //db username
    $dbpass = "pass"; //db password
    $dbname = "dreaming_smallgroup"; //db name
    $dbtable_users = "osg_user"; //table on dbname with data in it
    $dbtable_email = "osg_email"; //table on dbname with data in it
    //stop editing here

    $conn = mysql_connect($dbhost, $dbuser, $dbpass);
    if (!$conn) {
    echo "<P>Unable to connect to the database server at this time.</P>";
    exit();
    }
    if (! @mysql_select_db($dbname) ) {
    echo( "<P>Unable to locate the database at this time.</P>" );
    exit();
    }

    $result = mysql_query("SELECT CONCAT(first_name,' ',last_name) AS name,email FROM osg_user, osg_email WHERE id=osg_user.uid");
    if (!$result) {
    echo "<P>Error performing query on database";
    exit();
    }

    while ($row = mysql_fetch_array($result)){
    echo "<a href=mailto:".$row["email"].">".$row["name"]."</a><br>";
    }

    ?>

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you want to resue data like that I would suggest putting it into an array then you can use over and over without having to make another query to the db.
    Like so:
    $result = mysql_query("SELECT CONCAT(first_name,' ',last_name) AS name,email FROM osg_user, osg_email WHERE id=osg_user.uid");
    if (!$result) {
    echo "<P>Error performing query on database";
    exit();
    }

    while ($row = mysql_fetch_array($result)){
    $users[] = array("name" => $row["name"],
    "email" => $row["email"]
    );
    }

    //Now $users holds all your data so to make your emails
    //We now loop through the $users array and get the values using the list() function
    while(list($key,$val) = each($users)) {
    printf('<a href="mailto:%s">%s</a><br>', $users[$key]["email"], $users[$key]["name"]);
    }
    //Now simply reset the array
    reset($users);
    while(list($key,$val) = each($users)) {
    $email .= sprintf('%s, ', $users[$key]["email"]);
    }
    //NOw $email will hold all the emails separated by a comma but we need to take the last comma off so we use substr()
    $email = substr($email, 0, -2);
    printf('<a href="mailto:%s">email everyone</a>', $email);

    Hope that helps
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    SitePoint Wizard creole's Avatar
    Join Date
    Oct 2000
    Location
    Nashvegas Baby!
    Posts
    7,845
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ummmm...ok....

    you're a slavedriver...poor Freddy must have coded his little paws off to come up with that one.

    hehe

    Thanks, I'll give it a try. I have most of what I wanted working. Now it is just a matter of refining the scripts and paring them down to the very basics.

  4. #4
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah it is probably more complicated than what you need but belive me learning how to use arrays for thsi prupose will save you a lot of processing time, if there is any part of that which you don't understand just let me know.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  5. #5
    SitePoint Wizard creole's Avatar
    Join Date
    Oct 2000
    Location
    Nashvegas Baby!
    Posts
    7,845
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Freddy, I am getting a good handle on it, but since you volunteered, here are two more questions.

    Please take a look at http://www.oursmallgroup.com/pr.php3, specifically the header containing the date and the "most recent" sidebar.

    question one
    I am calling for date in one query to get the date for the header, then I am calling for pid (prayer request id),uid (user id) and main_text in the other query.

    What I want is to have one page per "day" of prayer requests with a header printed with that date on each page. Right now it works just fine, but the main problem is when I added a date other than 10-18 it printed both dates in the header bar. I need to figure out how to:

    ****a) use one query for both.

    ****b) be able to print out the date and prayer requests per date entered.
    I will be trying out your suggestion of the array so if that post answered either of these questions dont worry about answering.


    $result_date = mysql_query("SELECT date FROM osg_prayer_request GROUP BY date");
    if (!$result_date) {
    echo "<P>Error performing query on database";
    exit();
    }

    $result_requests = mysql_query("SELECT pid,uid, main_text FROM osg_prayer_request");
    if (!$result_requests) {
    echo "<P>Error performing query on database";
    exit();
    }

    question two

    I am gonna try Kevin's lesson on how to do this, but I wanted to post because I want help on it also. In the most recent sidebar I have a query that gets date,pid,uid,title and first_name. I print out the "title" of the prayer request but I want to make a link to the "main_text" of the prayer request using the pid. How do I do that? This is part that will truly make any PHP driven website I do great instead of good.

  6. #6
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In response to your first question about the dates and more than one showing up, unfortunately I think you will have to run two queries. How will you ne deciding whcih date to use for your query. Will you hard-code it in or will it be passed from some form or link? I tried to stick with the code you had and this would ONLY be a simple fix to show just one dat at the top of the page. Give me a better idea about how this will all work, and I can give you some better feedback. But here is a quick fix

    $result_date = mysql_query("SELECT date FROM osg_prayer_request GROUP BY date LIMIT 1");
    if (!$result_date) {
    echo "<P>Error performing query on database";
    exit();
    }
    $daterow = mysql_fetch_array($result_date);
    $date = $daterow["date"];
    $result_requests = mysql_query("SELECT pid,uid, main_text FROM osg_prayer_request WHERE date = '$date'");
    if (!$result_requests) {
    echo "<P>Error performing query on database";
    exit();
    }


    [Edited by freddydoesphp on 10-27-2000 at 11:02 AM]
    Please don't PM me with questions.
    Use the forums, that is what they are here for.


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
  •