Jump to content

Archived

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

Mutley

Using multiple ?id=1 methods

Recommended Posts

By placing:

$page = isset($_GET['page']) ? $_GET['page'] : '1';

at the top of the page you garauntee that $page is set, so you can remove the opening if statement.  I.E., [b]if($page)[/b] is not necessary [b]unless[/b] you specifically want nothing to be shown when the url contains [b]page=0[/b].

Share this post


Link to post
Share on other sites
So I've done this:

[code]if($page) {

$sql = "SELECT * FROM pages WHERE page_id=$page LIMIT 1";
$q = mysql_query($sql);
if(mysql_num_rows($q) == 1){
  while($row = mysql_fetch_array($result)){
    $content = $row['content'];
  }
}else{
  $content = "You're trying to find random pages in my website!";
}
echo $content;
}
[/code]

Which still doesn't work but I havn't removed the IF statement, what would it look like as I would need to remove curley brackets to? Could you do a mock up for me please?

Share this post


Link to post
Share on other sites
I'm determined to get this sorted for you...

Forget all the previous stuff, lets go from scratch as it's all very confusing.

[code]
<?php
  // Get the parameters from the URL
  $id = $_GET['id']
  $page = isset($_GET['page']) ? $_GET['page'] : '1'; // if '&page=n' (n is a number) is in the url use it, if not, default to page=1

  // The following assumes that you have a user_id column in your pages table, and the columns are called 'content', 'page_id' and 'user_id'
  $sql = "SELECT content FROM pages WHERE page_id = '$page' AND user_id = '$id'";
  $result = mysql_query($sql);

  // We should only have one row returned, so mysql_fetch_row should be fine here
  $content = mysql_fetch_row($result);

  // Check we found a page with the page_id that was given to us and output accordingly
  if ($content){
      echo $content[0];
  else {
      echo "No record was found for Page ID $page";
  }
?>
[/code]

Now this is assuming quite a lot, but this simple bit of code should work fine and you should be able to build whatever you need around it.

Regards
Rich

Share this post


Link to post
Share on other sites
Hurah! Finally, I've tested it and it works. Brilliant.

I would really like to thank everyone that has got me through this problem. Thanks Rich.  :)

Share this post


Link to post
Share on other sites

×

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.