Rishi Rishi - 6 months ago 37
PHP Question

PHP : get data from database

I am making a web service in php.

I want to have data from database in pagination manner.

eg : I should have 10 records based on event_id which i am passing in url along with page_number i.e 10 records on 1st page , another 10 records on 2nd page, and so on.

I am very new to web service.


if(isset($_REQUEST["Faq_request"]) && trim($_REQUEST["Faq_request"]) != '') {
$faq_details_Request = $_REQUEST["Faq_request"];
// $page_number = 1;
$faqeventdetails_o = json_decode($faq_details_Request);

if( isset($faqeventdetails_o->faq_event_id))
// event_id
$event_id = $faqeventdetails_o->faq_event_id;

die($msgobj->customFailMessage("Please provide Event Id"));

$userQuery="SELECT * FROM `faq` WHERE faq_event_id=$event_id";


/* if($number>0){
$query="DELETE FROM `agendaLikes` WHERE event_id=$event_id and user_id=$user_id
and agenda_id=$agenda_id";
mysql_query("UPDATE agenda SET agendaLikes=agendaLikes-1 where agenda_id=$agenda_id");

mysql_query("INSERT INTO `agendaLikes`(agenda_id,user_id,event_id) VALUES($agenda_id,$user_id,$event_id)");
mysql_query("UPDATE agenda SET agendaLikes=agendaLikes+1 where agenda_id=$agenda_id");


echo json_encode($u);

else {
else {

based on
i should get data.

when i hit in url then nothing is displayed.

where m I lacking?

Thank You.


Use Offset And Limit in your sql query let's say you want 10 records for each page then you need to pass page parameter. so for Example

$page = 2; //parameter pass by get or post method $limit = 10 //our limit to get data per page $offset = $page*$limit; //calculate your offset

Then your sql will look like

$userQuery="SELECT * FROM faq WHERE faq_event_id=$event_id ORDER BY id LIMIT $limit OFFSET $offeset";

Hope this works for you.