This is my code:
Code: Select all
<?
dbuser();
/* number of profiles per page */
$per_page = 9;
$country = $_GETї'country'];
$city = $_GETї'city'];
$online = $_GETї'online'];
if(isset($country)){
$lookup = "SELECT username, country, city_1, online FROM users WHERE country='".$_GETї'country']."' && profdate!='NULL' order by profdate";
} elseif(isset($city)){
$lookup = "SELECT username, country, city_1, online FROM users WHERE city_1='".$_GETї'city']."' && profdate!='NULL' order by profdate";
} elseif(isset($online)){
$lookup = "SELECT username, country, city_1, online FROM users WHERE online='1' && profdate!='NULL' order by profdate";
} else {
$lookup = "SELECT username, country, city_1, online FROM users WHERE profdate!='NULL' order by profdate";
}
$sql_text = $lookup;
if(!isset($_GETї'page'])) {
$page = 1;
} else {
$page = $_GETї'page'];
}
$prev_page = $page - 1;
$next_page = $page + 1;
$query = @mysql_query($sql_text);
$page_start = ($per_page * $page) - $per_page;
$num_rows = @mysql_num_rows($query);
if($num_rows <= $per_page) {
$num_pages = 1;
} elseif (($num_rows % $per_page) == 0) {
$num_pages = ($num_rows / $per_page);
} else {
$num_pages = ($num_rows / $per_page) + 1;
}
$num_pages = (int) $num_pages;
if ($page > $num_pages || $page < 0) {
echo '
You have specified an invalid page number.
';
}
$sql_text = $sql_text." LIMIT $page_start, $per_page";
$query = mysql_query($sql_text);
/* array is filled here */
$rows = array();
while ($row = mysql_fetch_row($query))
{
$rowsї] = $row;
}
/* page layout starts here */
echo buildTable($rows);
function buildTable($rows)
{
$cols = 3;
$numrows = ceil(count($rows) / $cols);
$counter = 0;
$table = '<table border=0 cellspacing=5>';
for($i = 0; $i < $numrows; $i++) {
$table .= '<tr>';
for($j = 0; $j < $cols; $j++) {
if(!empty($rowsї$counter])) {
if($_SESSIONї'profset'] = '0'){
$link = "<a href="?login" target="_top">";
} else {
$link = "<a href="?id=".$rowsї$counter]ї0]."">";
}
$table .= '<td align="center" class="td'.$rowsї$counter]ї3].'" width="165" height="110">'.$link.'<img src="../emb/b/'.$rowsї$counter]ї0].'_tn.jpg" border="0" class="prof_im"></a></td>';
}
else {
$table .= '<td> </td>';
}
$counter++;
}
$table .= '</tr>';
$counter = $counter - $cols;
$table .= '<tr>';
for($j = 0; $j < $cols; $j++) {
if(!empty($rowsї$counter])) {
if($_SESSIONї'profset'] = '0'){
$link = "<a href="?login" target="_top">";
} else {
$link = "<a href="?id=".$rowsї$counter]ї0]."">";
}
$table .= '<td align="center" class="td2"><strong>'.$link.$rowsї$counter]ї0].'</a></strong><br><a href="?country='.$rowsї$counter]ї1].'">'.$rowsї$counter]ї1].'</a><br><a href="?city='.$rowsї$counter]ї2].'">'.$rowsї$counter]ї2].'</a></td>';
}
else {
$table .= '<td> </td>';
}
$counter++;
}
$table .= '</tr><tr><td><img src="../gfx/spacer.gif" height="5"></td></tr>';
}
$table .= '</table>';
return $table;
}
/* page layout ends here & previous/next links are calculated */
$country = $_GETї'country'];
$city = $_GETї'city'];
$online = $_GETї'online'];
if(isset($country)){
$search = $country;
$go = "country";
} elseif(isset($city)){
$search = $city;
$go = "city";
} elseif(isset($online)){
$search = $online;
$go = "online";
}
echo ("<div align="center">");
/* this displays the "Previous" link */
if ($prev_page != 0) {
echo '<a href="index.php?page='.$prev_page.'&'.$go.'='.$search.'">< Prev</a> |';
}
/* this loops the pages and displays individual links */
for ($i = 1; $i <= $num_pages; $i++) {
if ($i != $page) {
echo ' <a href="index.php?page='.$i.'&'.$go.'='.$search.'">'.$i.'</a> ';
} else {
echo ' '.$i.' ';
}
}
/* this displays the "Next" link */
if ($page != $num_pages) {
echo '| <a href="index.php?page='.$next_page.'&'.$go.'='.$search.'">Next ></a>';
}
echo ("</div>");
?>