Results 1 to 2 of 2

Thread: Mysql help

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2006
    Posts
    242

    Mysql help

    Hi first of all i am a beginner in PHP and MYSQL
    I need help on how can i get the list of the emails from user table

    i want the emails to be listed on user_emails.php file

    Can some one help me on how to do this..?
    < advertising link removed by moderator >

  2. #2
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: Mysql help

    first, you would want to connect to MySQL and select the database you'll be using:

    Code:
    mysql_connect(host, username, password);
    mysql_select_db(database);
    then, you should construct an SQL query. they generally have a syntax similar to this:
    Code:
    SELECT field1[, field2[, field3[, ...]]]
    FROM table
    [WHERE expression]
    [ORDER BY field1[, field2[, ...]] [ASC|DESC]]
    anything within square brackets is optional. if you have a field named "email," then we can just select that. if we don't want to filter or sort the results, we can also ignore the WHERE and ORDER BY clauses:
    Code:
    SELECT email FROM table
    you should store this query in a variable -- $sql, maybe. then, we can query the database:
    PHP Code:
    $query mysql_query($sql); 
    then, we can fetch the results in an associative array, one row at a time, in a loop until the query has no results left:
    PHP Code:
    while($row mysql_fetch_assoc($query)){

      echo 
    $row['email'] . "\n";


    note that our SQL query selects one field -- email -- and we can print that email by referencing the "email" key inside of the $row array.

    hope that gives you the general idea.

Posting Permissions

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



Click Here to Expand Forum to Full Width