Jump to content


Photo

Using multiple ?id=1 methods


  • Please log in to reply
31 replies to this topic

#1 Mutley

Mutley
  • Members
  • PipPipPip
  • Advanced Member
  • 765 posts

Posted 05 September 2006 - 10:11 AM

I'm wanting to have id?=1 for a page but also one for a user, so a user with the id?=1 wants to view page number 2.

Obviouslly in the URL id?=1?page=2 wouldn't work, if it did how do I call it twice in my PHP?
~ Mutley.

#2 brown2005

brown2005
  • Members
  • PipPipPip
  • Advanced Member
  • 943 posts

Posted 05 September 2006 - 10:42 AM

u can have say index.php?page=1&id=1

$page = $_GET['page'];
$id = $_GET['id'];

hope this helps

#3 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 05 September 2006 - 10:42 AM

Obviouslly in the URL id?=1?page=2 wouldn't work, if it did how do I call it twice in my PHP?


Use '&' to pass additional parameters

mypage.php?id=1&page=2

Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#4 Mutley

Mutley
  • Members
  • PipPipPip
  • Advanced Member
  • 765 posts

Posted 05 September 2006 - 10:46 AM

That's great, so what would I do here:

$ewid = $_GET['id'];

if($ewid) {

	$sql  = "SELECT * ";
	$sql .= "FROM user ";
	$sql .= "WHERE id=".$ewid." ";

Would it look like this:
$ewid = $_GET['id'];
$page = $_GET['page'];
if($ewid, $page) {

	$sql  = "SELECT * ";
	$sql .= "FROM user, page ";
	$sql .= "WHERE id=".$ewid. && .$page." ";

That's confusing me^^. The user id and page id, are on different tables.


~ Mutley.

#5 brown2005

brown2005
  • Members
  • PipPipPip
  • Advanced Member
  • 943 posts

Posted 05 September 2006 - 11:11 AM

explain a bit more of what u are trying to do please.. i dont understand

#6 Mutley

Mutley
  • Members
  • PipPipPip
  • Advanced Member
  • 765 posts

Posted 05 September 2006 - 11:16 AM

Theres 2 tables in the database, 1 to store the users and 1 to store the pages for that user.

The first ?ID=1 will be the user, then to get the page it will be ?PAGE=2 (for page 2 for example), so ?ID=1&?PAGE=2

I want 1 php file so when you goto the ?ID=1&?PAGE=2 it finds the user and their page, then displays them. So there can be multiple users with their own pages.
~ Mutley.

#7 zawadi

zawadi
  • Members
  • PipPip
  • Member
  • 25 posts
  • LocationChippenham UK

Posted 05 September 2006 - 11:32 AM

so what you need to do is, pass the page the user ID and in the page table have a user_id colum and query data database for the page ID where the user_id = the ID in the url

I.E.

page.php?id=1

$sql = mysql_query("select * from pages where user_id = '$id'");


also, is the page a file or data from the page table?
That's the beauty of asymmetric warfare. You don't need a lot of money, or an army of people. You can do it from the comfort of your living room, with a beer in your hand.

#8 Mutley

Mutley
  • Members
  • PipPipPip
  • Advanced Member
  • 765 posts

Posted 05 September 2006 - 12:06 PM

Can you explain in more detail? That's confused me alot.

The database will have data in.

So will I have to include the pages.php file or something?
~ Mutley.

#9 Mutley

Mutley
  • Members
  • PipPipPip
  • Advanced Member
  • 765 posts

Posted 05 September 2006 - 12:47 PM

so what you need to do is, pass the page the user ID and in the page table have a user_id colum and query data database for the page ID where the user_id = the ID in the url

I.E.

page.php?id=1

$sql = mysql_query("select * from pages where user_id = '$id'");


also, is the page a file or data from the page table?


The problem with that, if the user id=1 it would only show page 1, I want it so users can have lots of pages.
~ Mutley.

#10 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 05 September 2006 - 12:59 PM

When you're using more than one $_GET variable, it should always be like this:

www.myurl.com?user_id=1&page=x

After the initial question mark, you have to use ampersands.  And if you're coding the links on the page, always use the HTML equivalent &

Info: PHP Manual


#11 Mutley

Mutley
  • Members
  • PipPipPip
  • Advanced Member
  • 765 posts

Posted 05 September 2006 - 01:03 PM

I understand that, thank-you Ober but my problem is how to code it into the page?

I know how to find the user, like this:
$ewid = $_GET['id'];
if($id) {

	$sql  = "SELECT * ";
	$sql .= "FROM users ";
	$sql .= "WHERE id=".$ewid." ";

	$result = mysql_query($sql) or die (mysql_error());
	
	if(mysql_num_rows($result) == 1) {
	
		$row = mysql_fetch_array($result);

But then how do I also do it, so it loads a page from the database with the URL? So ?id=1 would bring up that user but how would I make it so ?id=1&page=2 bring up page 2 data from the database table named "pages"?
~ Mutley.

#12 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 05 September 2006 - 01:29 PM

You would have to run the same sort of SQL query for the page contents.  Your actual content display function can be kind of generic, but you just plug the ID from the URL into the SQL statement to get the different content.  Now, where it can get somewhat tricky is if the content is actually specific to one user.  In that case, you just store the userid AND the page id in the contents table and use an AND in your WHERE clause to grab the right data.

Does that make sense?

Info: PHP Manual


#13 Mutley

Mutley
  • Members
  • PipPipPip
  • Advanced Member
  • 765 posts

Posted 05 September 2006 - 01:35 PM

Yahoo! I have no idea how that works but I've done it, thanks alot.  :D
~ Mutley.

#14 Mutley

Mutley
  • Members
  • PipPipPip
  • Advanced Member
  • 765 posts

Posted 05 September 2006 - 04:20 PM

How do I make it so if no &page=1 etc was put in, it would display it the first page anyway?

For example you put in ?id=1&page=1

It goes to page 1 but if you put in just ?id=1 it still goes to page 1?
~ Mutley.

#15 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 05 September 2006 - 04:25 PM

You should be using a setup like this:
<?php
if(isset($_GET['page']))
{
  switch($_GET['page'])
  {
      case "1":
         require("somepage.php");
      break;
      case "2":
         require("someotherpage.php")
      break;
      default:
         require("index.php");
  }
}
else
    require("index.php");
?>

Info: PHP Manual


#16 Mutley

Mutley
  • Members
  • PipPipPip
  • Advanced Member
  • 765 posts

Posted 06 September 2006 - 08:59 AM

Not like that. It's all in the database, heres what I've got:

<?
if($page) {

	$sql  = "SELECT * ";
	$sql .= "FROM pages ";
	$sql .= "WHERE page_id=".$page." ";

	$result = mysql_query($sql) or die (mysql_error());
	
	if(mysql_num_rows($result) == 1) {
	
		$row = mysql_fetch_array($result);
	
		$content = $row['content'];
?>
<?=$content?>
<?
} else {
echo "No Page selected"
	}
	}
?>
<!--^ Content of the page ^-->

That would work with ?id=1&page=1 but if someone just put ?id=1    I want it to show &page=1 automaticly.
~ Mutley.

#17 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 06 September 2006 - 11:10 AM


// if this gets the information from a url .
if($page) {

do this.

if($_GET['page']=="what_ever_condition"){

do some think

}

good luck.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#18 Mutley

Mutley
  • Members
  • PipPipPip
  • Advanced Member
  • 765 posts

Posted 06 September 2006 - 08:06 PM

Sorry, could you explain what to do with that and how it works? Would that make it so if I put ?id=1 it would goto ?id=1&page=1 automaticly.
~ Mutley.

#19 Mutley

Mutley
  • Members
  • PipPipPip
  • Advanced Member
  • 765 posts

Posted 07 September 2006 - 12:56 PM

Tried so many ways, I just can't get it so if it is

?id=1 it displays page 1 and if I then put ?id=1&page=2 it comes up blank, I can only get one of the other to work. I've tried this:

if($_GET['page']) {

	$sql  = "SELECT * ";
	$sql .= "FROM pages ";
	$sql .= "WHERE page_id=".$page." ";

	$result = mysql_query($sql) or die (mysql_error());
	
	if(mysql_num_rows($result) == 1) {
	
		$row = mysql_fetch_array($result);
	
		$content = $row['content'];
?>
<?=$content?>
<?
} else {
	$sql  = "SELECT * ";
	$sql .= "FROM pages ";
	$sql .= "WHERE page_id=1 ";

	$result = mysql_query($sql) or die (mysql_error());
	
	if(mysql_num_rows($result) == 1) {
	
		$row = mysql_fetch_array($result);
	
		$content_empty = $row['content'];
?>
<?=$content_empty?>
<!--^ Content of the page ^-->
<?
	}
	}
	}

Also tried:

if(!empty($page)) {

and:

if($page == "")) {

...but they all make ?id=1 find page 1 but if I then did ?id=1&page=2 it just comes up blank.
~ Mutley.

#20 Mutley

Mutley
  • Members
  • PipPipPip
  • Advanced Member
  • 765 posts

Posted 07 September 2006 - 05:34 PM

Come on you PHP Freaks, what am I doing wrong?  ;D
~ Mutley.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users