Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 08-22-2007, 01:37 AM I am Newbie help me
hitesh123's Avatar
Junior Talker

Posts: 1
Name: hitesh
Trades: 0
I need to add it to forum profiles avatars

We have a forum (Php) for our school cadets and want to know how to make available in search

cadets in age range.
in our forum database Mysql there is no feild of age. but it out puts age of cadet through a code
which calculates cadet's age from db feilds cadet_birthday,
cadet_birthmonth and cadet_birthyear

and in profile it says
cadet
name: lalit
age : 16
gendre : male
class: 8th

can you tell me how to make a mysql search code for searching cadets for a particular range like e.g.

search cadets

gender=emale
age= 10 to 15

php code :
<?php
$max_results = 10;
$from = (($page * $max_results) - $max_results);

$get_results = mysql_query("SELECT * FROM cadetforum_users WHERE cadet_gender='".$_GET['gender']."' AND cadet_class='".$_GET['class']."' AND cadet_rank='".$_GET['rank']."' AND cadet_section='".$_GET['section']."' AND active_status='".$_GET['online']."' AND profile_picture='".$_GET['picture']."' LIMIT $from, $max_results");

?>


Regards,

hitesh

Last edited by hitesh123; 08-22-2007 at 01:48 AM..
hitesh123 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 08-23-2007, 08:28 AM Re: I am Newbie help me
Skilled Talker

Posts: 94
Trades: 0
hitest,

You could use the > < in the MySQL Statement but I like Filtering the results in PHP.

So you could do this

PHP Code:

for ($i 0$row mysql_fetch_assoc($get_results); $i++) {

     if (
$row['age'] < 15 && $row['age'] > 10) {
     
// Do what you want with the information
    
}

Hope that helps
__________________
Sell Templates? Try our
Please login or register to view this content. Registration is FREE
! See a live
Please login or register to view this content. Registration is FREE
ChadR is offline
Reply With Quote
View Public Profile
 
Old 08-23-2007, 09:06 AM Re: I am Newbie help me
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Do that in SQL !
It's designed for that !
PHP Code:
$sql=<<<SQL
SELECT *
FROM cadetforum_users 
WHERE cadet_gender=''
{$_GET['gender']}
AND cadet_class='
{$_GET['class']}
AND cadet_rank='
{$_GET['rank']}'
AND cadet_section='
{$_GET['section']}'
AND active_status='
{$_GET['online']}'
AND profile_picture='
{$_GET['picture']}
AND cadet_age BETWEEN 
{$_GET['ageMin']} AND {$_GET['ageMax']}
LIMIT 
$from$max_results
SQL;
$r=mysql_query($sql); 
Of course, adapt the field name to your db schema...
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 08-23-2007, 04:12 PM Re: I am Newbie help me
Super Talker

Posts: 130
Trades: 0
I would suggest putting the birthdate into one field with a data type of date. Using the proper data type in your schema will make your life a whole lot easier when it come to writing your queries. Read this page on dates and I think it will become very apparent why.
http://dev.mysql.com/doc/refman/5.0/...functions.html
__________________
flann

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
flann is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to I am Newbie help me
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.14042 seconds with 12 queries