Welcome to the IMTalk - Internet Marketing & SEO Forum.
  • Login:
+ Reply to Thread
Results 1 to 6 of 6
  1. #1
    castor's Avatar
    castor is offline IM & SEO Weak Jaw castor will become famous soon enough
    Join Date
    Feb 2012
    Location
    Europe
    Posts
    181
    Thanks Given
    63
    Thanked 49 Times in 42 Posts

    Listing data from 2 tables of one MySQL Database

    Hello,

    I would like to write a PHP code to listing my users on a page and then able to export into CSV format.

    The data are stored in two separate tables in one database.

    The first table named 'users' contains only the email addresses.
    The second one named 'data' contains the first name, last name and other data if any.

    I would like to print on screen the above data like this:
    Email First Name Last Name

    And then I would like to export this table into CSV file.

    Are there anybody can help me to start?

    Thanks

  2. #2
    Mr.Soldoni's Avatar
    Mr.Soldoni is offline IM & SEO Whisperer Mr.Soldoni is on a distinguished road
    Join Date
    Nov 2012
    Posts
    44
    Thanks Given
    4
    Thanked 8 Times in 6 Posts
    you need to put a key in every table to associate an email to name. Example
    Table ONE
    id
    1
    email
    some[at]email

    Table TWO
    id
    1
    First Name
    Will
    Last Name
    Smith

    in this case id is the key.

  3. #3
    castor's Avatar
    castor is offline IM & SEO Weak Jaw castor will become famous soon enough
    Join Date
    Feb 2012
    Location
    Europe
    Posts
    181
    Thanks Given
    63
    Thanked 49 Times in 42 Posts
    Fine, I did it.
    But how can I list them in one php file?
    I connected to db, create the query but I would like to display data on the screen.
    I am stduying UNION at this time but I am not sure I am on the right way.

  4. #4
    Mr.Soldoni's Avatar
    Mr.Soldoni is offline IM & SEO Whisperer Mr.Soldoni is on a distinguished road
    Join Date
    Nov 2012
    Posts
    44
    Thanks Given
    4
    Thanked 8 Times in 6 Posts
    you have created the queries, now you have the values in some variables.
    example
    $resulquery1
    $resulquery2
    to display them just use "echo"
    example
    echo "My name is ".$resulquery2." and my email is ".$resulquery2;

  5. #5
    castor's Avatar
    castor is offline IM & SEO Weak Jaw castor will become famous soon enough
    Join Date
    Feb 2012
    Location
    Europe
    Posts
    181
    Thanks Given
    63
    Thanked 49 Times in 42 Posts
    Yes you're but because these are in separate tables I cannot render the data for the email.

    For example:
    I have the users tabel
    ID email
    1 [email protected]
    2 [email protected]
    etc.
    The second table has:
    UID first_name last_name
    1 Joe Smith
    2 Peter Peterson
    etc.

    Now I need two query to get the data but I would like to display the right name for the email addresses.
    email1@domain com Joe Smith
    [email protected] Peter Peterson
    etc.

    What is the query and the while that I need?

  6. #6
    Mr.Soldoni's Avatar
    Mr.Soldoni is offline IM & SEO Whisperer Mr.Soldoni is on a distinguished road
    Join Date
    Nov 2012
    Posts
    44
    Thanks Given
    4
    Thanked 8 Times in 6 Posts
    the query is
    SELECT 'table1'.'email', 'table2'.'first_name', 'table2'.'last_name' FROM 'table1', 'table2' WHERE 'table1'.'id'=1 AND 'table1'.'id'='table2'.'uid'
    in this case I used the id=1 so the results is email1[at]domain com Joe Smith

  7. The Following User Says Thank You to Mr.Soldoni For This Useful Post:



 

Similar Threads

  1. Searching for a programmer for flatfile database
    By proseocontent in forum Programming, Scripting, Database, Testing, Debugging...
    Replies: 5
    Last Post: 10-10-2023, 03:46 PM
  2. What is the command to create MySQL database using PHP and MySWQ?
    By hirephp in forum Programming, Scripting, Database, Testing, Debugging...
    Replies: 4
    Last Post: 05-14-2012, 05:33 PM
  3. Tables VS DIV
    By bluearrow in forum Website Planning, Design & Development
    Replies: 20
    Last Post: 03-01-2012, 03:59 PM
  4. 750 million email database for sale
    By sonu703 in forum Products
    Replies: 0
    Last Post: 12-02-2011, 08:49 AM
  5. SQL And MySQL
    By amitoops in forum Programming, Scripting, Database, Testing, Debugging...
    Replies: 2
    Last Post: 06-01-2011, 11:08 AM

Tags for this Thread

Posting Permissions

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