Jump to content

Using multiple ?id=1 methods


Mutley

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].
Link to comment
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?
Link to comment
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
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.