Jump to content

[SOLVED] Variables


lostprophetpunk

Recommended Posts

Hello all, I am currently having some trouble with some variables on my page.

 

The problem is that it is supposed to read the 'n' off of the /blog/?n=1 (1 used for example), but it doesn't seem to do this.

 

The code is being used for a pages system.

 

The code I have so far is...

  $pn = mysql_real_escape_string( $_GET['n'] );
  
  $sql40 = "SELECT * FROM `posts` ORDER BY `id`";
  $res40 = mysql_query($sql40) or die(mysql_error());
  $rows = mysql_num_rows($res40);
  
  $limit = 0;
  
  if($pn = 1){
$limit = 4;
  }else if($pn= 2){
$limit = 8;
  }
  
  $perpage = 4;
    
  $sql4 = "SELECT * FROM `posts` ORDER BY `id` desc LIMIT ".$limit.",".$perpage."";
  $res4 = mysql_query($sql4) or die(mysql_error());

 

I thought that would work, changing the query based on the two variables: $limit and $perpage, but it doesn't work. I am trying to make it so that if it was on page 1...it would display the latest 4 rows from the database, then on page 2 it would display the next 4, and so on until it reaches the end.

 

If anyone could help out, that would be awesome. Thanks in advance.

Link to comment
https://forums.phpfreaks.com/topic/170250-solved-variables/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.