Accurax Posted March 13, 2007 Share Posted March 13, 2007 I'm really struggleing to get my head around this, and im getting annoyed at myself for not being able to figure it out. Here is my complete script, it should take 4 values from a form sex, location minimum age and maximum age. It should then access my database and display all my members who satisfy all critera and are between minimum and maximum age's supplied. here is my complete code as it stands .... at the mometn it just loads a blank page, no error codes or output of any kind, and its got me stumped. <?php //connect to database here $sex = $_POST['search_sex']; $loc = $_POST['search_location']; $min_age = $_POST['search_age2']; $max_age = $_POST['search_age1']; $user_query = "SELECT * FROM members m INNER JOIN pictures p ON p.user_name = m.user_name 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']; } } ?> Ive been reading through tutorials on handleing arrays, but nothing seems to make sense with respect to this, so every bit of help is really honestly appreciated here. Link to comment https://forums.phpfreaks.com/topic/42504-im-really-stuck-and-dont-understand/ Share on other sites More sharing options...
billskipton Posted March 13, 2007 Share Posted March 13, 2007 First suggestion - put error_reporting(255) at the start, at least it will give you a clue. Link to comment https://forums.phpfreaks.com/topic/42504-im-really-stuck-and-dont-understand/#findComment-206215 Share on other sites More sharing options...
Accurax Posted March 13, 2007 Author Share Posted March 13, 2007 Still no error message's being thrown out at all code updateed below; <?php error_reporting(255); //connect to database here $sex = $_POST['search_sex']; $loc = $_POST['search_location']; $min_age = $_POST['search_age2']; $max_age = $_POST['search_age1']; $user_query = "SELECT * FROM members m INNER JOIN pictures p ON p.user_name = m.user_name 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']; } } ?> Link to comment https://forums.phpfreaks.com/topic/42504-im-really-stuck-and-dont-understand/#findComment-206220 Share on other sites More sharing options...
boo_lolly Posted March 13, 2007 Share Posted March 13, 2007 i can't tell you where, but your problem, i'm almost certain, involves your sql query. let us see the form. Link to comment https://forums.phpfreaks.com/topic/42504-im-really-stuck-and-dont-understand/#findComment-206227 Share on other sites More sharing options...
Accurax Posted March 13, 2007 Author Share Posted March 13, 2007 the sql query is fine...... i know this because if i remove all the bits about the age and just echo out the details of those users who fit the location and sex criteria it works perfectly. Link to comment https://forums.phpfreaks.com/topic/42504-im-really-stuck-and-dont-understand/#findComment-206232 Share on other sites More sharing options...
boo_lolly Posted March 13, 2007 Share Posted March 13, 2007 try escaping the string like: <?php $user_query = "SELECT * FROM members m INNER JOIN pictures p ON p.user_name = m.user_name WHERE sex = '". $sex ."' AND location = '". $loc ."' ORDER BY last_updated DESC"; ?> Link to comment https://forums.phpfreaks.com/topic/42504-im-really-stuck-and-dont-understand/#findComment-206244 Share on other sites More sharing options...
Accurax Posted March 13, 2007 Author Share Posted March 13, 2007 how would that help you havnt done anything except put it on multiple lines? The problem is not with the sql query.... its with the array and the selection or users that fit the age range, i just dont get it Link to comment https://forums.phpfreaks.com/topic/42504-im-really-stuck-and-dont-understand/#findComment-206254 Share on other sites More sharing options...
billskipton Posted March 13, 2007 Share Posted March 13, 2007 I would suggest you echo the 'today' dates and the 'birthday' dates and see why they aren't matching up. Sometimes odd things can happen when you treat a text string (such as '01') as a number. One thing for certain, theres nothing wrong with PHP, only with the way you are using it (thats what I always tell myself when I have a problem) so you need to pin down the problem by getting as much information as you can - and that means echo, echo, echo. Don't despair - the answer is waiting for you to find it! Link to comment https://forums.phpfreaks.com/topic/42504-im-really-stuck-and-dont-understand/#findComment-206293 Share on other sites More sharing options...
boo_lolly Posted March 13, 2007 Share Posted March 13, 2007 i just escaped the string to make sure the value of the variables was being printed. i only put it on separate lines to help diagnose the query if it returned a mysql_error(). it could be that your table columns are int values and your $_POST variables are strings, and somethings not picking up in between. can you show a short diagram of your two tables? Link to comment https://forums.phpfreaks.com/topic/42504-im-really-stuck-and-dont-understand/#findComment-206318 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.