Ninemonths - Home

Baby Names

Search our Baby Names and choose a special name for your child.

[insert_php]
// a few variables
$search_url = ”;
$female_status = ‘unchecked’;
$male_status = ‘unchecked’;
$option = ”;
$gender = ”;

// get the current page or set a default
if (isset($_GET[“currentpage”]) && is_numeric($_GET[“currentpage”])) {
// cast var as int
$currentpage = (int) $_GET[“currentpage”];

}
else {
// default page num
$currentpage = 1;
} // end if

// find out what we are searching for
if (isset($_GET[‘search’])){

$search = $_GET[‘search’];
$search_url .= ‘&search=’ . $search;

}

// if gender has been selected…
if (isset($_GET[‘gender’])){

$gender = $_GET[‘gender’];
if($gender != ”){
$option .= ” AND namebank_sex='” . $gender . “‘”;
$search_url .= ‘&gender=’ . $gender;
}
if ($gender == ‘F’) {
$female_status = ‘checked’;

}
else if ($gender == ‘M’){
$male_status = ‘checked’;

}
}

if (isset($_GET[‘origin’]) && !empty($_GET[‘origin’])) {
$origin = $_GET[‘origin’];
$option .= ” AND namebank_orgin LIKE ‘%” . $origin . “%'”;
$search_url .= ‘&origin=’ . $origin;
}

// query to count number of results to then work out pages
$query = mysql_query(“SELECT namebank_sex, namebank_name, namebank_orgin, namebank_meaning FROM name_bank WHERE namebank_name LIKE ‘” . $search . “%'” . $option . “”);

$numrows=mysql_num_rows($query);
$testing = “

number of results: ” . $numrows . “; query is ” . $search . “; current page is: ” . $currentpage . ” origin is: ” . $origin;

// number of rows to show per page
$rowsperpage = 20;

// find out total pages
$totalpages = ceil($numrows / $rowsperpage);

// if current page is greater than total pages…
if ($currentpage > $totalpages) {
// set current page to last page
$currentpage = $totalpages;
} // end if
// if current page is less than first page…
if ($currentpage < 1) { // set current page to first page $currentpage = 1; } // end if // the offset of the list, based on current page if (isset($_GET["currentpage"])){ $offset = ($_GET["currentpage"] - 1) * $rowsperpage; } else{ $offset = 0; } $testing .= "; offset:" . $offset . "

“;

//normal query and print results
$query = mysql_query(“SELECT namebank_sex, namebank_name, namebank_orgin, namebank_meaning FROM name_bank WHERE namebank_name LIKE ‘” . $search . “%'” . $option . ” ORDER BY namebank_name ASC LIMIT $offset, $rowsperpage”);
if(isset($_GET[‘search’])){

$alert = “search results for: ” . $search;

if ($numrows == 0){
$alert = “unfortunately, we could not find ‘” . $search . “‘ in our name database.”;
}

}

?>

“;
if(isset($_GET[‘search’])){
echo “

” . $alert . “

“;
}
echo “

“;

while ($row = mysql_fetch_array($query, MYSQL_ASSOC)) {
echo “

‘;
}

echo “

Gender Name Meaning Origin
“;
printf($row[“namebank_sex”]);
echo “
“;
printf($row[“namebank_name”]);
echo “
“;
printf($row[“namebank_meaning”]);
echo “
“;
printf($row[“namebank_orgin”]);
echo ‘

‘;
/****** end build pagination links ******/

[/insert_php]


© Copyright Ninemonths.com.au - All rights reserved