Current location: Hot Scripts Forums » Programming Languages » PHP » filter results


filter results

Reply
  #1 (permalink)  
Old 08-24-04, 10:42 AM
cooc cooc is offline
Newbie Coder
 
Join Date: Aug 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
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

Last edited by cooc; 08-24-04 at 10:44 AM.
Reply With Quote
  #2 (permalink)  
Old 08-25-04, 05:44 AM
blaw's Avatar
blaw blaw is offline
Junior Code Guru
 
Join Date: Dec 2003
Location: Vancouver, BC, Canada
Posts: 550
Thanks: 0
Thanked 0 Times in 0 Posts
Hello,

You can JOIN two tables and act on it as if they were one table. This way, you can use something like WHERE authuser.status = 'inactive' or something. Good place to learn how to JOIN tables is here: http://www.w3schools.com/sql/sql_join.asp . This is the beauty of RDBMS, so I strongly suggest that you master this. Good luck!

Another tip from me is that you can change authuser.status to something like isActive tinyint(1). If the value of this column is 1, or true, then that means the user is active, and if 0, or false, inactive (sort of Yes/No data type in Access or the likes). This way you are saving storage space and possibly it makes easier for you to code your PHP script.

My 22 cents.
__________________
Blavv =|
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP/MySQL - Sports results database Neil_Allen PHP 4 11-29-08 02:59 PM
PHP, MySQL Beginner... Help Needed Displaying Results db3db3 PHP 1 05-12-04 01:24 AM
posting of results script Sir-ihlatrebon Script Requests 0 02-17-04 11:46 AM
results page to display prev/next php-learner PHP 11 01-12-04 09:40 AM
Database storage of the results of a cardclub Xirtam Script Requests 0 12-15-03 11:16 AM


All times are GMT -5. The time now is 04:23 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.