SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Thread: filter results

  1. #1
    SitePoint Member
    Join Date
    Aug 2004
    Location
    here & there
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    filter results

    Hi!

    i have a script that search the 'signup' table in my DB.
    the user is entering a zipcode, & the script is giving an output of emails of members that live under that zipcode:
    Code:
    <?php 
    //i opened a connection to the DB
    $link = mysql_connect('localhost', 'MY-USER') or die ('Could not connect to MySQL');
    mysql_select_db('MY-DB' , $link) or die('Could not open db');
    
    //basic search
     if ($_POST['SendButton'] == 'Search'){  
        if (ereg('[0-9]{1,20}', $_POST['zipcode'])){  
            $selection = mysql_query("SELECT email FROM signup WHERE zipcode=" . addslashes(trim($_POST['zipcode']))) or die ('Queryproblem');  
            if (mysql_num_rows($selection)>= 1){  
               echo '<ul>';  
               while ($row = mysql_fetch_assoc($selection) ) {  
                   echo '<li>' . $row['email'] . '</li>';  
               }  
               echo '</ul>'; 
            }else{  
               echo 'No emails for this zipcode.';  
            }  
        }else{  
           echo 'Invalid value. Zipcode needs to be between 1 and 20 digits.';  
        }  
    }else{  
        echo 'Invalid pagerequest.';  
    }  
    mysql_close();
    ?>
    the rows at the 'signup' tables are:
    uname fname lname email country zipcode

    now i have another table called 'authuser', inside that table there is a row called uname some other rows... & a row called status. in that row you have values of inactive or active [for users that confirmed the registration email or not], what i need is to filter inactive users from what the above script has found...
    thanks

  2. #2
    SitePoint Wizard Lats's Avatar
    Join Date
    Jun 2003
    Location
    Melbourne, AU
    Posts
    1,142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Untested, but something like this...
    PHP Code:
    $selection mysql_query("
        SELECT 
            signup.email, 
            signup.uname 
        FROM 
            signup 
        LEFT JOIN 
            authuser 
        ON
            signup.uname = authuser.uname
        WHERE 
            zipcode=" 
    addslashes(trim($_POST['zipcode'])) ."
        AND
            authuser.status = 'active'"
    ) or die ('Queryproblem'); 
    Lats...

  3. #3
    SitePoint Member
    Join Date
    Aug 2004
    Location
    here & there
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    how to integrate it to the existing code? where should it go?
    thanks

  4. #4
    SitePoint Wizard Lats's Avatar
    Join Date
    Jun 2003
    Location
    Melbourne, AU
    Posts
    1,142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Replace your current $selection= line.
    Lats...

  5. #5
    SitePoint Member
    Join Date
    Aug 2004
    Location
    here & there
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    cool!
    it worked!


    i have another small 'interesting' issue,
    there are users from several countries, that uses their own languages when registering & filling the registration form. the problem is that their details somehow tranlated into some html code/ascii code or whatever [i attached a screenshot from the country row for example] & when a user enter a country name into the search box [to find users under that country], nothing is found... [you have to enter this code if you want to find it...]
    Attached Images Attached Images

  6. #6
    SitePoint Member
    Join Date
    Aug 2004
    Location
    here & there
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    where is the attachment? hmmm,i'll try again
    Attached Images Attached Images


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
  •