GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 16-Sep-2004, 03:42
skyloon skyloon is offline
Junior Member
 
Join Date: Jun 2003
Posts: 53
skyloon is an unknown quantity at this point

next page


this is a searching function
the max result is 30, if more than 30, it has "- Prev 1 2 Next -"
it shows the correct result, but if i press next, it shows these errors:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in c:\phpweb\searching.php on line 61

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in c:\phpweb\searching.php on line 90

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in c:\phpweb\searching.php on line 133


PHP Code:

<?PHP
// $reqlevel sets the accesslevel a user needs to hace
// use 0 (zero) if you want to make it an admin only page.
// and 1 (one)  is default for an new user. 
// this makes the page an member only page.
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"];

?>

<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=$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}");
    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 = 30;
    $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}");

    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}");  
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>
Last edited by JdS : 16-Sep-2004 at 08:08. Reason: Please insert your example PHP codes between [php] and [/php] tags
  #2  
Old 20-Sep-2004, 12:00
OmarEduardo OmarEduardo is offline
New Member
 
Join Date: Sep 2004
Location: Guadalajara, México
Posts: 7
OmarEduardo is on a distinguished road
Its useful to write
or die ("SQL Error: " . mysql_error());
after each mysql_query() to know what part of the sql is wrong.
  #3  
Old 20-Sep-2004, 23:01
skyloon skyloon is offline
Junior Member
 
Join Date: Jun 2003
Posts: 53
skyloon is an unknown quantity at this point
when i put "or die('error: '. mysql_error());", it shows this error message:

error: You have an error in your SQL syntax near 'and '2004'-dobyear <= '' ' at line 1
  #4  
Old 21-Sep-2004, 14:02
OmarEduardo OmarEduardo is offline
New Member
 
Join Date: Sep 2004
Location: Guadalajara, México
Posts: 7
OmarEduardo is on a distinguished road
The empty space between the ' character means that the $highage varirable its empty.
Your are not submiting it or you are submiting it with a wrong name.
  #5  
Old 06-Oct-2004, 21:35
skyloon skyloon is offline
Junior Member
 
Join Date: Jun 2003
Posts: 53
skyloon is an unknown quantity at this point
Unhappy

until now, the problem hvn't fixed..... ??:
  #6  
Old 17-Oct-2004, 12:04
JasonMichael's Avatar
JasonMichael JasonMichael is offline
Awaiting Email Confirmation
 
Join Date: Jul 2004
Posts: 135
JasonMichael has a spectacular aura about
I have never had reliable results only using mysql_select_db to create my MySQL connection. I think if you add the following line somewhere near the top of your script, you'll have better results:

PHP Code:

$conn=mysql_connect('localhost', 'mysql_user', 'mysql_password'); 



Do you happen to have this your config.php file?
 
 

Recent GIDBlogToyota - 2008 July Promotion by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How do you print a web page? rhino1616 Web Design Forum 10 30-Jul-2004 23:25
simple form from generated page zuzupus Web Design Forum 0 17-Sep-2003 09:27
[script] E-mail webmaster error page BobbyDouglas PHP Code Library 0 19-Aug-2003 20:10
Search Engine Positioning 101 and 201 "How To" Tips... 000 Search Engine Optimization Forum 0 29-May-2003 10:34

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 21:58.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.