Page 2 of 2

Posted: Mon Sep 20, 2004 2:07 am
by sguy
it's work fine when i just use it for displaying result...
got error if i use for searching

Posted: Wed Oct 06, 2004 10:32 pm
by sguy
until now, the problem hvn't fixed..... :cry:

Posted: Thu Oct 07, 2004 2:23 am
by twigletmac
What does your current code look like?

Mac

Posted: Thu Oct 07, 2004 7:17 am
by sguy

Code: Select all

<?PHP
include("config.php");
$search = $HTTP_GET_VARS["search"];
$searchname = $HTTP_POST_VARS["searchname"];
$name = $HTTP_POST_VARS["name"];
$gender = $HTTP_POST_VARS["gender"];
$state = $HTTP_POST_VARS["state"];
$lowage = $HTTP_POST_VARS["lowage"];
$highage = $HTTP_POST_VARS["highage"];
$image = $HTTP_POST_VARS["image"];
$page = $HTTP_POST_VARS["page"];
$lowage = $HTTP_POST_VARS["lowage"]; 
$highage = $HTTP_POST_VARS["highage"];
$nextpage = $HTTP_POST_VARS["nextpage"];
$backpage = $HTTP_POST_VARS["backpage"];
$currentyear = $HTTP_POST_VARS["currentyear"];
?>

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<LINK href="help.css" rel=stylesheet type=text/css>

</head>

<body bgcolor="#FFFFFF" text="#000000">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td>
      <?
$currentyear=strftime("%Y");
?>
    </td>
  </tr>
  <tr> 
    <td> 
      <?php
    mysql_select_db($database, $conn);
    if(!$conn)
    {
       echo "Couldn't make a connection!!!";
       exit;
    }
    $db = mysql_select_db($database,$conn);
    if(!$db)
    {
      echo "The database disapeared!";
      mysql_close($conn);
      exit;
    }
$image="";
if(isset($_POST['image']) && $_POST['image'] == 1) { 
$image .= ' AND image = 1 ';  
}
    $max = 0;
    $bmax = mysql_query("SELECT * from ".$DBprefix."signup WHERE username like '%$searchname%' and fullname like'%$name%' and state like'%$state%' and gender like'$gender%' and userlevel='1' and actnum='0' and $currentyear-dobyear >= $lowage and $currentyear-dobyear <= $highage {$image}") or die('error: '. mysql_error());
    while ($row = mysql_fetch_array($bmax)) 
    { 
     $max++; 
    } 
    ?>
	<font size="2">
      <?php
	  $image="";
if(isset($_POST['image']) && $_POST['image'] == 1) { 
$image .= ' AND image = 1 ';  
} 
echo"<table border=0 cellspacing=0 width=80% align=center>";
    echo "</td><td height="12" align="right" bgcolor="lightcyan" width="100%"><font size=2>";

    echo "<center>Database record returned<font color = blue> $max </font>
          items.</center>";
    echo "</td></tr></form></table><br>";


    $maxresult = 3000;
    $sql_text = ("SELECT * from ".$DBprefix."signup WHERE username like '%$searchname%' and fullname like'%$name%' and state like'%$state%' and gender like'$gender%' and userlevel='1' and actnum='0' and $currentyear-dobyear >= $lowage and $currentyear-dobyear <= $highage{$image}") or die('error: '. mysql_error());

    if (!$page) {
    $page = 1;
    } 
    $backpage = $page - 1;
    $nextpage = $page + 1;
    $query = mysql_query($sql_text);
    $start = ($maxresult * $page) - $maxresult; 
    $num_rows = mysql_num_rows($query); 
    if ($num_rows <= $maxresult) {
    $num_pages = 1; 
    } else if (($num_rows % $maxresult) == 0) {
      $num_pages = ($num_rows / $maxresult);
    } else {
    $num_pages = ($num_rows / $maxresult) + 1;
    } 
    $num_pages = (int) $num_pages;
    if (($page > $num_pages) || ($page < 0)) {
    error("You have specified an invalid page number");
    }
    $sql_text = $sql_text . " LIMIT $start, $maxresult";
    $query = mysql_query($sql_text);
    
    if ($max>$maxresult)
    {
    echo "<center>- ";
    if ($backpage) { 
    echo "<a href="searching.php?search=$search&page=$backpage">Prev</a>";
    } else {
    echo "Prev";
    }
    for ($i = 1; $i <= $num_pages; $i++) {
    if ($i != $page) { 
    echo " <a href="searching.php?search=$search&page=$i">$i</a> ";
    } else { 
    echo " $i "; 
    } 
    }
    if ($page != $num_pages) {
    echo "<a href="searching.php?search=$search&page=$nextpage">Next</a> -";
    } else {
    echo "Next -";
    }
    echo "</center>";
    }
    ?><CENTER>
<table CELLSPACING="2" CELLPADDING="2" BORDER="0" width="70%"> 
<font size=2>
<?php 
$a = $start + 1; 
     print "  <TR bgcolor=slateblue><TD font size=2 align=center height="26"><font font size=2 color=white><b>Nickname</TD><TD align=center><font size=2 color=white><b>Gender</TD><TD align=center><font size=2 color=white><b>Age</TD><TD align=center><font size=2 color=white><b>Location</TD><TD align=center><font size=2 color=white><b>Country</TD><TD align=center><font size=2 color=white><b>Headline</TD></TR>\n"; 

while ($row = mysql_fetch_array($query)) {
?>
<?php
$image="";
if(isset($_POST['image']) && $_POST['image'] == 1) { 
$image .= ' AND image = 1 ';  
}


$res = mysql_query("SELECT * FROM ".$DBprefix."signup WHERE username like '%$searchname%' and fullname like'%$name%' and state like'%$state%' and gender like'$gender%' and userlevel='1' and actnum='0' and $currentyear-dobyear >= $lowage and $currentyear-dobyear <= $highage {$image}") or die('error: '. mysql_error());
if(mysql_num_rows($res) > 0) {  
      echo"<tr>"; 
	  $pic = strtolower(substr($row['gender'], 0, 1)); 
   		$color = ($pic == 'm') ? 'aliceblue' : '#fff0ff';
      echo '<td bgcolor="'.$color.'"><font size=2>&nbsp;&nbsp;<b><a class=hq href="viewuser.php?name='.$row['username'].'" target="_blank">'.$row['username'].'</a>';  
         if($row['image'] == 1) {   
         echo '&nbsp;&nbsp;<img src="members/image/camera.gif" alt="camera" />';  
         }  
          echo '</td>'."\n";  
		  $pic = strtolower(substr($row['gender'], 0, 1)); 
   		$color = ($pic == 'm') ? 'aliceblue' : '#fff0ff';
    		"$row[gender]\n";
	  $currentyear=strftime("%Y");
	  $currentdate=strftime("%d-%m-%Y");
	  $age = $currentyear - $row[dobyear];
		$pic = strtolower(substr($row['gender'], 0, 1)); 
   		$color = ($pic == 'm') ? 'aliceblue' : '#fff0ff';
		echo'<td align=center bgcolor="'.$color.'">';
    		"$row[gender]\n";
		if($row['gender'] == 'male') {
		echo '<img src="members/image/'.substr($row['gender'], 0, 1).'.jpg" alt="'.$row['gender'].'" />';
		}
		else {
		echo '<img src="members/image/'.substr($row['gender'], 0, 1).'.jpg" alt="'.$row['gender'].'" />';
		}
$pic = strtolower(substr($row['gender'], 0, 1)); 
   		$color = ($pic == 'm') ? 'aliceblue' : '#fff0ff';
		echo'<td align=center bgcolor="'.$color.'">';
		echo"<font size=2>$age";
    		"$row[gender]\n";
$pic = strtolower(substr($row['gender'], 0, 1)); 
   		$color = ($pic == 'm') ? 'aliceblue' : '#fff0ff';
		echo'<td align=center bgcolor="'.$color.'">';
		echo"<font size=2>$row[location]";
    		"$row[gender]\n";
$pic = strtolower(substr($row['gender'], 0, 1)); 
   		$color = ($pic == 'm') ? 'aliceblue' : '#fff0ff';
		echo'<td align=center bgcolor="'.$color.'">';
		echo"<font size=2>$row[country]";
    		"$row[gender]\n";			
$pic1 = strtolower(substr($row['gender'], 0, 1)); 
   		$color1 = ($pic1 == 'm') ? 'blue' : 'red';
		echo'<font color="'.$color1.'">';
$pic = strtolower(substr($row['gender'], 0, 1)); 
   		$color = ($pic == 'm') ? 'aliceblue' : '#fff0ff';
		$color1 = ($pic1 == 'm') ? 'blue' : 'red';
		echo'<td bgcolor="'.$color.'"><font color="'.$color1.'">';
		echo"<font size=2>$row[headline]";
    		"$row[gender]\n";	
$a++; 
   }  
else {  
   echo 'No users found';  
} 
?>
</body>
</html>
<?php
    }
    echo "</table>";
    if ($max>$maxresult)
    {
    echo "<br><center>- ";
    if ($backpage) { 
    echo "<a href="searching.php?search=$search&page=$backpage">Prev</a>";
    } else {
    echo "Prev";
    }
    for ($i = 1; $i <= $num_pages; $i++) {
    if ($i != $page) { 
    echo " <a href="searching.php?search=$search&page=$i">$i</a> ";
    } else { 
    echo " $i "; 
    } 
    }
    if ($page != $num_pages) {
    echo "<a href="searching.php?search=$search&page=$nextpage">Next</a> -";
    } else {
    echo "Next -";
    }
    echo "</center>";
    }
?></font>

Posted: Thu Oct 07, 2004 10:59 am
by feyd
okay..

line 57: looks like you are trying to find out how many (total) number of records match your standard query. This can be quickly done useing a [mysql_man]COUNT[/mysql_man]() in the selection.

as for the rest of the code.. is this still the next page link not working problem?

Posted: Thu Oct 07, 2004 10:18 pm
by sguy
all work fine....
its only got error when i press next to the other page, i found this error when i use it on searching.....
after i press search button, then go to this page...
if just used on display result, it don't show any error

Posted: Fri Oct 08, 2004 12:40 am
by feyd
for one, line 11 has $page coming in from POST not GET, maybe that's the problem?

Posted: Fri Oct 08, 2004 12:47 am
by timvw
after a quick look, i wonder where are you storing the values the user submitted on the first search request? right now i think they are lost when he requests the next page.