First of all, thankyou so much for the help with my previous question,i have with your guidance managed to make the search script work correctly.
However, :eek: ..... I have another problem with it.
Im paginating my results to only display 5 rows per page, this appears to be a problem when using the $_POST method, but i cant think of a better way around it.
I have tried :
if ( $pageNum == 1 ) {
$sex = $_POST['search_sex'];
$loc = $_POST['search_location'];
$min_age = $_POST['search_age2'];
$max_age = $_POST['search_age1'];
$_SESSION['sex'] = "$sex";
$_SESSION['loc'] = "$loc";
$_SESSION['min_age'] = "$min_age";
$_SESSION['max_age'] = "$max_age";
}
else {
$sex = $_SESSION['sex'];
$loc = $_SESSION['loc'];
$min_age = $_SESSION['min_age'];
$max_age = $_SESSION['max_age'];
}
but the above just displays the same on every page (which is odd) but it wont let you return to page 1 without errors.
the error i am recieving is as follows:
Notice: Undefined index: search_sex in C:\wamp\www\test.php on line 28
I get 4 of those erros.... one for each $_POST['']; variable.
Is there a way around this without rewriting my entire script?
here is my code so far:
<?php
error_reporting(255);
session_start();
include("../secret.inc");
if ( $_SESSION['login'] != "true" )
{
header("location: ../login.php");
}
else
{
$connection=mysql_connect($h, $u, $p)
or die ("Could not connect !");
$db = mysql_select_db($d, $c)
or die ("Could not connect to Database");
$rowsPerPage = 5;
$pageNum = 1;
// if $_GET['page'] defined, use it as page number
if(isset($_GET['page']))
{
$pageNum = $_GET['page'];
}
$offset = ($pageNum - 1) * $rowsPerPage;
$sex = $_POST['search_sex'];
$loc = $_POST['search_location'];
$min_age = $_POST['search_age2'];
$max_age = $_POST['search_age1'];
$min_date = date('Y-m-d', strtotime('-' . $min_age . 'years'));
$max_date = date('Y-m-d', strtotime('-' . $max_age . 'years'));
$user_query = "SELECT * FROM members m INNER JOIN pictures p ON p.user_name = m.user_name
WHERE sex='$sex' AND location='$loc' AND age BETWEEN '$min_date' AND '$max_date'
ORDER BY last_updated DESC";
$result = mysql_query($user_query)
or die ("no can do");
while ( $row = mysql_fetch_array($result))
{
echo "<table>";
echo "<tr>";
echo "<td>";
echo "<ul id='search_thumbs'><li><a href='view_profile.php?user_name=".$row['user_name']."'><img src='../".$row['thmb_1']. "'></a></li></ul>";
echo "</td>";
echo "<td>";
echo '<a href="view_profile.php?user_name='.$row['user_name'].'">'; echo $row['user_name']; echo "</a>";
//calculates the age
$day = $row['day'];
$month = $row['month'];
$year = $row['year'];
$birthday = $day."-".$month."-".$year;
$today = date('d-m-Y');
$a_birthday = explode('-', $birthday);
$a_today = explode('-', $today);
$day_birthday = $a_birthday[0];
$month_birthday = $a_birthday[1];
$year_birthday = $a_birthday[2];
$day_today = $a_today[0];
$month_today = $a_today[1];
$year_today = $a_today[2];
$age = $year_today - $year_birthday;
if (($month_today < $month_birthday) || ($month_today == $month_birthday && $day_today < $day_birthday))
{
$age--;
}
echo "<strong> - Age: </strong>";
echo ' ';
echo $age;
//end of age calc
//loctaion
$location = $row['location'];
echo "<strong> From: </strong>";
echo $location;
//end of location call
echo "<br />";
echo $row['introduction'];
echo "</td>";
echo "</tr>";
echo "</table>";
}
// how many rows we have in database
$query = "SELECT COUNT(user_name) AS numrows FROM members";
$result = mysql_query($query) or die('Error, query failed line 95');
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$numrows = $row['numrows'];
// how many pages we have when using paging?
$maxPage = ceil($numrows/$rowsPerPage);
// print the link to access each page
$self = $_SERVER['PHP_SELF'];
$nav = '';
for($page = 1; $page <= $maxPage; $page++)
{
if ($page == $pageNum)
{
$nav .= " $page "; // no need to create a link to current page
}
else
{
$nav .= " <a href=\"$self?page=$page\">$page</a> ";
}
}
// creating previous and next link
// plus the link to go straight to
// the first and last page
if ($pageNum > 1)
{
$page = $pageNum - 1;
$prev = " <a href=\"$self?page=$page\">[Prev]</a> ";
$first = " <a href=\"$self?page=1\">[First Page]</a> ";
}
else
{
$prev = ' '; // we're on page one, don't print previous link
$first = ' '; // nor the first page link
}
if ($pageNum < $maxPage)
{
$page = $pageNum + 1;
$next = " <a href=\"$self?page=$page\">[Next]</a> ";
$last = " <a href=\"$self?page=$maxPage\">[Last Page]</a> ";
}
else
{
$next = ' '; // we're on the last page, don't print next link
$last = ' '; // nor the last page link
}
// print the navigation link
echo "<br />";
echo "<br />";
echo "More profiles";
echo "<br />";
echo $first . $prev . $nav . $next . $last;
// and close the database connection
//include '../library/closedb.php';
}
?>
I was trying to use require_once but i couldnt get that to work, and for all i know it cant apply to variables anyway.
Im sorry to ask so much of you guys, but this is right on the edge of my abilities right now, and seems to be too specific for google to help much.