Jump to content


PHP Help Needed


4 replies to this topic

#1 _*neapra_*

  • Guests

Posted 28 July 2005 - 09:37 AM

Hello

i am making a script that pulls out data from a data base, i have no clue how to limit the results show per page. can someone help me please?!? lol This is doing my head in!

Quote

<?php
$getmembers = mysql_query("SELECT * FROM members ORDER BY id DESC");//query the database for all of the new members

while($r=mysql_fetch_array($getmembers)){//while there are rows in the table
extract($r);//remove the $r so its just $variable

echo("
<table width='550' border='0' cellspacing='0' cellpadding='0'>
  <tr>
    <td width='133' class='textblack'><b>Name:</b></td>
    <td width='147' class='textblack'><b>Email</b></td>
    <td width='270' class='textblack'><b>Telephone:</b></td>
  </tr>
  <tr>
    <td class='textblack'>$namefirst  $namelast </td>
    <td class='textblack'>$email</td>
    <td class='textblack'>$telephone</td>
  </tr>
  <tr>
    <td colspan='3' class='textblack'>&nbsp;</td>
  </tr>
  <tr>
    <td colspan='3' class='textblack'><b>Address:</b></td>
  </tr>
  <tr>
    <td colspan='3' class='textblack'>$address <br> $city <br> $postcode</td>
  </tr>

    <tr>
    <td colspan='3' class='textblack'> <form name='form' action='$php_self' method='post'> <table width='550' border='0' cellspacing='0' cellpadding='0'>   <tr>     <td class='textblack' align='right'><b>Username:</b></td>   </tr>   <tr>     <td align='right'><input name='username' type='text' id='username' class='textblack'></td>   </tr>   <tr>     <td class='textblack' align='right'><b>Password:</b></td> <tr>     <td align='right'><input name='password' type='text' id='password' class='textblack'></td>   </tr>   <tr>     <td align='right'><input name='add' type='submit' id='add' value='Add' class='textblack'></td>   </tr> </table> </form> </td>   </tr>   <tr>     <td colspan='3' class='textblack'><hr width='350' class='textblack' size='1'></td>   </tr>   <tr>     <td colspan='3' class='textblack'><img src='images/spacer.gif' width='550' height='30'></td>   </tr> </table> "); if (isset($_POST["username&'])) {
$namefirst = $_POST["password"];
$namelast = $_POST["email"];

$query = "INSERT INTO users (username, password, email) VALUES('$username','$password','$email')";
mysql_query($query) or die(mysql_error());
echo "<span class='textblack'><p align='center'>The user $username has been added to the members database! <a href='admin.php' class='linkblack'><u>Back</u></a></p></span>";
}
}

?>

Above is the code from my script.

Thanks in advance

Neapra :)

#2 softLearner

    Young Padawan

  • Members
  • Pip
  • 128 posts

Posted 28 July 2005 - 02:01 PM

I beleive you do this:
$getmembers = mysql_query("SELECT * FROM members ORDER BY id DESC");//query the database for all of the new
change above to this:
$getmembers = mysql_query("SELECT * FROM members ORDER BY id DESC LIMIT 0, 50");//query the database for all of the new

Notice: LIMIT 0, 50 this tells mysdl to show the first 50 results, 50 being how many results per page your want shown.

Also you'll want to learn pagnation to make dynamic pages so you can retrieve more reults, That tutorial provided will explain it a bit better.

Edited by softLearner, 28 July 2005 - 02:03 PM.


#3 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 28 July 2005 - 08:03 PM

soft, you're correct in the way you're doing it, but it'd be much easier to lose the 0,
i.e.
mysql_query("SELECT * FROM members ORDER BY id DESC LIMIT 50");


#4 HaloprO

    Requires Armed Escort

  • Members
  • PipPip
  • 310 posts
  • Gender:Male
  • Location:California, USA

Posted 29 July 2005 - 01:00 AM

Doing that won't work, What that will do is grab 50 members, and the same 50 members for other pages, you need it to do + 50 members for each page.

#5 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 29 July 2005 - 01:15 PM

sorry, i missed her comment about "per page"
My mistake





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users