Jump to content

Pulling from database.. but 1-2 per page ?


nickbunyun

Recommended Posts

ok so just to give you guys a feel of the infos i need to pull out from the db..

this is how much goes in..

 

 $sql="INSERT INTO feedback (date, zipcode, groupadults, groupchildren, findout, findoutother, timesvisit, hoursofop, ryv_likelihood, ryv_info, ryv_helpfull, ryv_cleanliness, ryv_condition, ryv_appeal, ryv_value, comments, suggestionfuture, overall, primaryreason, programtitle, rtp_expect, rtp_interesting, rtp_length, rtp_amount, rtp_conveniece, rtp_value, rtp_ease, programcomments, likebest, attendagain, attendsug, suggestionfutureprograms, email, gehc_member) VALUES ('$dateinsert','$_POST[zipcode]','$_POST[groupadults]','$_POST[groupchildren]','$_POST[findout]','$_POST[findoutother]','$_POST[timesvisit]','$_POST[hoursofop]','$_POST[ryv_likelihood]','$_POST[ryv_info]','$_POST[ryv_helpfull]','$_POST[ryv_cleanliness]','$_POST[ryv_condition]','$_POST[ryv_appeal]','$_POST[ryv_value]','$_POST[comments]','$_POST[suggestionfuture]','$_POST[overall]','$_POST[primaryreason]','$_POST[programtitle]','$_POST[rtp_expect]','$_POST[rtp_interesting]','$_POST[rtp_length]','$_POST[rtp_amount]','$_POST[rtp_conveniece]','$_POST[rtp_value]','$_POST[rtp_ease]','$_POST[programcomments]','$_POST[likebest]','$_POST[attendagain]','$_POST[attendsug]','$_POST[suggestionfutureprograms]','$_POST[email]','$_POST[gehc_member]')"; 

 

 

now i also have to add the QUESTIONS to those.. to see which one goes where..

now im wodering.. how can i do it.. so it only shows 2-3.. maybe 4 per page...  asc by date?

 

Link to comment
Share on other sites

<?php
$page = isset($_GET['page']) && is_numeric($_GET['page']) && $_GET['page'] >= 1 ? $_GET['page'] : 1;

$per_page = 2;// set this

$count_q = mysql_query("SELECT COUNT(id) FROM your table");
$count_r = mysql_fetch_row($count_q);
$count = $count_r[0];

if($page > ceil($count/$per_page)) $page = 1;

$limit_min = ($page-1)*$per_page;


	foreach($res as $x) $w[] = "blah = blah "; // change this
		$w = implode('OR', $w);		

		mysql_select_db(" you databse ") or die(mysql_error());// change this
		$result = mysql_query("SELECT `title`,`type`,`game_picture_url` FROM `game` WHERE $w LIMIT {$limit_min}, {$per_page}")or die(mysql_error()); 
		  while($row = mysql_fetch_assoc($result)){  

		  echo info for each thing

			}
?>

 

it would be something like

 

you document.php?page=5

Link to comment
Share on other sites

 foreach($res as $x) $w[] = "blah = blah "; // change this 

 

i dont exactly know what blah = blah should be

 

first blah = the table field your are search by in the database.

second blah = the criteria. So if your searching for all last names of dork

 

`LastName` = 'dork'

    is the same as

blah = blah (as stated)

Link to comment
Share on other sites

So you want something like:

 

page1.php

//Display the first and last name

 

page2.php

//Display the department and phone number

 

page3.php

//Display the salary and start date

 

OR something like

 

page1.php

//Display First Last Names, department, phone number, salary, and start date of the first 2 records in the database.

 

page2.php

//Display First Last Names, department, phone number, salary, and start date of the NEXT 2 records in the database.

 

page3.php

//Display First Last Names, department, phone number, salary, and start date of the NEXT 2 records in the database.

 

Link to comment
Share on other sites

page1.php

//Display First Last Names, department, phone number, salary, and start date of the first 2 records in the database.

 

page2.php

//Display First Last Names, department, phone number, salary, and start date of the NEXT 2 records in the database.

 

page3.php

//Display First Last Names, department, phone number, salary, and start date of the NEXT 2 records in the database.

 

 

that...

 

 

sorry if i didnt explain it correctly.. kinda hard when u dont know exactly what ur doing..

but yeah..

 

that

Link to comment
Share on other sites

You need to use a technique called pagination. If you google it, you will find many tutorials on how to do it. Basically it involves first querying the database to see how many total records there are, then dividing that by 2 (since you want to show two queries on each page). That will tell you how many pages there are supposed to be. Then you create links to each page. You can see the technique in effect on this any any other forum - where it shows links to page 2, 3, 4 and so on.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.