hey,
i have problem with paging,i need to use two tables to fetch data.
i am submitting my developed code. i hope some body will help me.

mysql_connect("localhost", "root", "") or die(mysql_error()); 
mysql_select_db("dummy1") or die(mysql_error());



$START=$_GET['start'];
if(!$START)
{
    $START=0;
}

$data = mysql_query("SELECT * FROM scrapmsg ORDER BY date DESC") or die(mysql_error());
$total = mysql_num_rows($data);
$LIMIT = 4;
$NEXT=$START+$LIMIT;
$PREV=$START-$LIMIT;
//This is your query again, the same one... the only difference is we add $max into it
$data_p = mysql_query("SELECT scrapmsg.ucode,scrapmsg.myomsg, acountseting.usercode, acountseting.fnm, acountseting.imgpath ". "FROM scrapmsg, acountseting "."WHERE scrapmsg.rcode = acountseting.usercode ORDER BY scrapmsg.rcode DESC  LIMIT $START,$LIMIT") or die(mysql_error());

//$query = "SELECT scrapmsg.ucode,scrapmsg.myomsg, acountseting.usercode, acountseting.fnm, acountseting.imgpath ". "FROM scrapmsg, acountseting "."WHERE scrapmsg.rcode = acountseting.usercode ORDER BY scrapmsg.rcode DESC";
while($info = mysql_fetch_array( $data_p ))
{
  
  if($info['usercode'] == $current_img)
  {
  	print $info['ucode'] . " to " . $info['rcode'];
  	print $info['myomsg'];
  	print "<br>";
  }
}
Member Avatar for diafol

so what's the problem?

hey ardav,

this script is not printing data on the page.
this is the problem.
i don't know why is not working i had check this script for fetching data in simple form.data is coming on the page but in paging it's not coming.

So please help me if you have any solution for this problem.

Thanks

Member Avatar for diafol

is this all the code? there seems to be some weird vars: $total, $current_img.

well it's my mistake, i forgot to declare all variables.
when i was posting this problem.
$total is a variable to count no. of data stored in "scrapmsg" table and $current_img is containing the value of usercode that used for if condition.
if "scrapmsg's usercode" equals with $current_img them it goes in the if condition and print required data.

Thanks

Member Avatar for diafol
$START=$_GET['start'];
if(!$START)
{
    $START=0;
}

to

$LIMIT = 4;
//get total num recs as $TOTAL...
$PAGES = ceil($TOTAL/$LIMIT);
if(isset($_GET['start']){
    $START=intval($_GET['start');
    if($START > $PAGES)$START = $PAGES;
    if($START < 0)$START = 0;
}else{
    $START = 0;
}
$OFFSET = $START * $LIMIT;

//then in your sql ... LIMIT $OFFSET,$LIMIT...

Off top of my head - sorry can't test at the moment.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.