Jump to content

How to select from two tablse from the database


bokivaol

Recommended Posts

What is command to connect two tables from the database. I would like to select from table "newsletter" all emails which are different AND  to select from the table "user_registration" all users with newsletter=1, but if there any user in those two tables with the same email, I would not like to display it twice.

When I put in the code

$s = dbQuery("select * from `newsletter` where `email`<>'' order by `email`");

- it display all different emails from the table "newsletter"

When I put in the code

$s = dbQuery("select * from `user_registration` where `newsletter`='1' order by `email`");

- it display all emails from the table "user_registration" with newsletter=1.

I would like to connect these two equations, but I don't know how, I don't know what is command? Can you help me about this? I used JOIN command, but I didn't do anything.

 

<?php
        $s = dbQuery("select * from `user_registration` where `newsletter`='1' order by `email`");........1        
        /* $s = dbQuery("select * from `newsletter` where `email`<>'' order by `email`");........................2*/
        $count = dbNumRows($s);
        if($count>0){
        ?>
        <select size="6" multiple="multiple" id="multi" name="multi[]" style="width:200px;">
        <?php        
            while($t = dbFetchArray($s,MYSQL_BOTH))
            {    
        ?>
            <option value="<?php echo $t["id"]; ?>"><?php echo $t["email"]; ?></option>
        <?php
            }        
        ?>
        <?php
            }        
        ?>   
        </select>
        <input type="checkbox" onClick="selectAll(this);"/> Select All<br />
        <input type="submit" onclick="return checkdel();" name="DelUser" value="Delete Those Subscribers" />
        <?php
        }
        else
        {
        ?>
        No Records!
        <?php
        }        
        ?>

 

Can anyone help me to write a code, I am not so good in mysql and php, but I know what I want.

 

[attachment deleted by admin]

Link to comment
Share on other sites

Maybe it is easy for you, but for me it is very hard. I tried with

SELECT newsletter.email, user_registration.email FROM user_registration LEFT JOIN newsletter ON newsletter.email <> user_registration.email

, but I need function IF and THEN. IF they are = THEN display just ONE of them, all other different emails should be displayed.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.