I shall do my best to explain here, if im not being clear enough about this please tell me,
I have a database containing information about all of my users, and i would like to add the ability for users to search for each other.
So, i have created a simple form that should allow users to search by sex, location and specify a minimum and maximum age.
The location and sex works fine, its a simple sql query after all.
But im having hair pullingly annoying problems with making the age range search function correctly.
At this moment in time the code that follws simply appears to do nothing... no out put or error messages of any kind whatsoever, which has really got me going bald fast as im sure you can imagine.
Some help is needed i feel.
My database is structured as follows (and yes i know the way i handle dob' is odd) :p
user_name - primary
sex
location
day - (the day of the month they were born on - numerical [dd])
month - (the month they were born in - numerical [mm])
year - (the year they were born in [yyyy])
for now i just want to acheive a situation where i can print out the names of each user who meets the search criteria.
here is my code so far;
<?php
error_reporting(255);
session_start();
include("../secrets.inc");
if ( $_SESSION['logged'] != "true" )
{
header("location: ../login.php");
}
else
{
$connection=mysql_connect($hostname, $username, $password)
or die ("Could not connect !");
$db = mysql_select_db($db, $cnnctn)
or die ("Could not connect to Database");
$sex = $_POST['search_sex'];
$loc = $_POST['search_location'];
$min_age = $_POST['search_age2'];
$max_age = $_POST['search_age1'];
$user_query = "SELECT * FROM members WHERE sex='$sex' AND location='$loc' ORDER BY last_updated DESC";
$result = mysql_query($user_query)
or die ("no can do");
$today = date('d-m-Y');
$a_today = explode('-', $today);
$day_today = $a_today[0];
$month_today = $a_today[1];
$year_today = $a_today[2];
while ( $row = mysql_fetch_array($result))
{
//calculates the age
$day = $row['day'];
$month = $row['month'];
$year = $row['year'];
$birthday = $day."-".$month."-".$year;
$a_birthday = explode('-', $birthday);
$day_birthday = $a_birthday[0];
$month_birthday = $a_birthday[1];
$year_birthday = $a_birthday[2];
$age = $year_today - $year_birthday;
if (($month_today < $month_birthday) || ($month_today == $month_birthday && $day_today < $day_birthday))
{
$age--;
}
if (($age >=$min_age) && ($age <= $max_age)) {
$members [] = $row;
foreach ($members as $key => $value)
print $value['user_name'];
}
}
}
?>
I'm really starting to loose it with this code...... is there anyone out there who can help?
Accura