Jump to content


Photo

pagination


  • Please log in to reply
4 replies to this topic

#1 rc69

rc69

    PHP Master PD

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

Posted 10 October 2004 - 12:16 PM

ive got a slight problem... im trying to develop a site similar to P2L but different all the same... and ive got this search script that i would like to add pagination to, but the main problem is all the the tutorials ive seen for pagination don't seem to work

could anybody help me work it out?
site: http://graphic-designz.uni.cc
<?
include ('config.php');

$search = $_POST["search"];
$topic = $_POST["topic"];

if (!$search || $search == "Search"){
	die ('Please enter a query.');
	}
if (!$topic){
	die('Please choose a method to search by.');
}

if ($topic == 'title' || $topic == 'author' || $topic == 'description'){
$sql = "SELECT * FROM search WHERE $topic LIKE '%$search%' ORDER BY program, id DESC";
}else{
$sql = "SELECT * FROM search WHERE (title LIKE '%$search%') AND (program = '$topic') ORDER BY program, id DESC";
}
echo "<table align=\"center\">
   <tr>
   <td align=\"center\"><u>Search Info</u>:<br>
   <font size=\"-2\">:REMOVED FOR LENGTH:</font>
   </td></tr></table>";

$result = mysql_query("$sql");
	if(mysql_num_rows($result) == 0){
   echo "No Results to Display.";
	}else{

$bg = "#2C323B";
echo "<table cellspacing=\"0\">";
while($r=mysql_fetch_array($result))
{   
	if($bg == "#38404B"){
  $bg = "#2C323B";
	}else{
  $bg = "#38404B";
	}
	if($r['program'] == 'photoshop'){
  $program = "Photoshop";
	}elseif($r['program'] == "image ready"){
  :list of program name edits, nothing special:
	}
	
   echo "<tr bgcolor=\"$bg\"><td></td>
   <td width=\"400\"><a href=\"http://graphic-designz.uni.cc/tut.php?link=$r[link]\" target=\"_blank\"><b>$r[title]</b></a> ::by:: <a href=\"http://graphic-designz.uni.cc/tut.php?link=$r[site]\">$r[author]</a>
   </td><td>
   Info-</td></tr>
   <tr bgcolor=\"$bg\">
   <td width=\"60\"><img src=\"$r[img]\" width=\"50\" height=\"50\">
   </td>
   <td><br>
         $r[description]<hr></td>
   <td width=\"200\" valign=\"top\">
   <font size=\"-2\"><b>Type:</b> $r[program]<br>
   <b>Date Entered:</b> $r[date]<br>
   <b>Views:</b> $r[count]</font></td></tr>";
}
echo "</table>";
}
?>

it's a 100% working script (go to my site and test it your self), anything surrounded by :: is edited so that i dont have a mile long post, but i would really appreciate some help of any sort

#2 shao

shao

    Original P2L Programmer

  • Members
  • Pip
  • 49 posts
  • Gender:Male
  • Location:Canada

Posted 11 October 2004 - 01:01 AM

Use: Limit Offset, Records to get your pages. So if you plan to display 30 records for page 2 (start with 31st record)

your sql statement would be: "Select * from TABLE ... LIMIT 31, 30".

31 can be a variable that you can manipulate from the post or get or URL method and the 30 can be a constant variable. There's more to manipulation, but the above should be a good start for you. Good luck, eh!

#3 rc69

rc69

    PHP Master PD

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

Posted 11 October 2004 - 04:29 PM

thanks, but wouldn't having every single tutorial (for multiple programs), on the same database cause problems with that?

like repeating of the same results multiple times since one tutorial could be on row 35, then starting from 31 would show 35 again?

(not exactly sure how to get a variable to start at the last row selected)

#4 Dabu

Dabu

    Young Padawan

  • Members
  • Pip
  • 148 posts
  • Location:Greensboro, North Carolina

Posted 11 October 2004 - 05:57 PM

there is a tutorial on spoono that can help you. It is filled with errors (as in php writeing errors) but I am sure you can fix those <3.

#5 rc69

rc69

    PHP Master PD

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

Posted 12 October 2004 - 07:28 PM

limit $rowstart,5");

your sql statement would be: "Select * from TABLE ... LIMIT 31, 30".

...repeating of the same results multiple times since one tutorial could be on row 35, then starting from 31 would show 35 again?


tried that tutorial already... thats basicaly what shao suggested, and what i asked was, is there a way to get the exact row number of the last row selected, not the total rows selected




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users