Mutley Posted September 5, 2006 Share Posted September 5, 2006 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? Quote Link to comment https://forums.phpfreaks.com/topic/19747-using-multiple-id1-methods/ Share on other sites More sharing options...
brown2005 Posted September 5, 2006 Share Posted September 5, 2006 u can have say index.php?page=1&id=1$page = $_GET['page'];$id = $_GET['id'];hope this helps Quote Link to comment https://forums.phpfreaks.com/topic/19747-using-multiple-id1-methods/#findComment-86246 Share on other sites More sharing options...
HuggieBear Posted September 5, 2006 Share Posted September 5, 2006 [quote]Obviouslly in the URL id?=1?page=2 wouldn't work, if it did how do I call it twice in my PHP?[/quote]Use '&' to pass additional parameters[code]mypage.php?id=1&page=2[/code] Quote Link to comment https://forums.phpfreaks.com/topic/19747-using-multiple-id1-methods/#findComment-86247 Share on other sites More sharing options...
Mutley Posted September 5, 2006 Author Share Posted September 5, 2006 That's great, so what would I do here:[code]$ewid = $_GET['id'];if($ewid) { $sql = "SELECT * "; $sql .= "FROM user "; $sql .= "WHERE id=".$ewid." ";[/code]Would it look like this:[code]$ewid = $_GET['id'];$page = $_GET['page'];if($ewid, $page) { $sql = "SELECT * "; $sql .= "FROM user, page "; $sql .= "WHERE id=".$ewid. && .$page." ";[/code]That's confusing me^^. The user id and page id, are on different tables. Quote Link to comment https://forums.phpfreaks.com/topic/19747-using-multiple-id1-methods/#findComment-86248 Share on other sites More sharing options...
brown2005 Posted September 5, 2006 Share Posted September 5, 2006 explain a bit more of what u are trying to do please.. i dont understand Quote Link to comment https://forums.phpfreaks.com/topic/19747-using-multiple-id1-methods/#findComment-86256 Share on other sites More sharing options...
Mutley Posted September 5, 2006 Author Share Posted September 5, 2006 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=2I 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. Quote Link to comment https://forums.phpfreaks.com/topic/19747-using-multiple-id1-methods/#findComment-86257 Share on other sites More sharing options...
zawadi Posted September 5, 2006 Share Posted September 5, 2006 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 urlI.E.page.php?id=1[quote]$sql = mysql_query("select * from pages where user_id = '$id'");[/quote]also, is the page a file or data from the page table? Quote Link to comment https://forums.phpfreaks.com/topic/19747-using-multiple-id1-methods/#findComment-86263 Share on other sites More sharing options...
Mutley Posted September 5, 2006 Author Share Posted September 5, 2006 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? Quote Link to comment https://forums.phpfreaks.com/topic/19747-using-multiple-id1-methods/#findComment-86280 Share on other sites More sharing options...
Mutley Posted September 5, 2006 Author Share Posted September 5, 2006 [quote author=zawadi link=topic=106927.msg428302#msg428302 date=1157455943]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 urlI.E.page.php?id=1[quote]$sql = mysql_query("select * from pages where user_id = '$id'");[/quote]also, is the page a file or data from the page table?[/quote]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. Quote Link to comment https://forums.phpfreaks.com/topic/19747-using-multiple-id1-methods/#findComment-86319 Share on other sites More sharing options...
ober Posted September 5, 2006 Share Posted September 5, 2006 When you're using more than one $_GET variable, it should always be like this:www.myurl.com?user_id=1&page=xAfter the initial question mark, you have to use ampersands. And if you're coding the links on the page, always use the HTML equivalent & Quote Link to comment https://forums.phpfreaks.com/topic/19747-using-multiple-id1-methods/#findComment-86327 Share on other sites More sharing options...
Mutley Posted September 5, 2006 Author Share Posted September 5, 2006 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:[code]$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);[/code]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"? Quote Link to comment https://forums.phpfreaks.com/topic/19747-using-multiple-id1-methods/#findComment-86333 Share on other sites More sharing options...
ober Posted September 5, 2006 Share Posted September 5, 2006 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? Quote Link to comment https://forums.phpfreaks.com/topic/19747-using-multiple-id1-methods/#findComment-86348 Share on other sites More sharing options...
Mutley Posted September 5, 2006 Author Share Posted September 5, 2006 Yahoo! I have no idea how that works but I've done it, thanks alot. :D Quote Link to comment https://forums.phpfreaks.com/topic/19747-using-multiple-id1-methods/#findComment-86355 Share on other sites More sharing options...
Mutley Posted September 5, 2006 Author Share Posted September 5, 2006 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=1It goes to page 1 but if you put in just ?id=1 it still goes to page 1? Quote Link to comment https://forums.phpfreaks.com/topic/19747-using-multiple-id1-methods/#findComment-86495 Share on other sites More sharing options...
ober Posted September 5, 2006 Share Posted September 5, 2006 You should be using a setup like this:[code]<?phpif(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");?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/19747-using-multiple-id1-methods/#findComment-86496 Share on other sites More sharing options...
Mutley Posted September 6, 2006 Author Share Posted September 6, 2006 Not like that. It's all in the database, heres what I've got:[code]<?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 ^-->[/code]That would work with ?id=1&page=1 but if someone just put ?id=1 I want it to show &page=1 automaticly. Quote Link to comment https://forums.phpfreaks.com/topic/19747-using-multiple-id1-methods/#findComment-86954 Share on other sites More sharing options...
redarrow Posted September 6, 2006 Share Posted September 6, 2006 // if this gets the information from a url .if($page) {do this.if($_GET['page']=="what_ever_condition"){do some think}good luck. Quote Link to comment https://forums.phpfreaks.com/topic/19747-using-multiple-id1-methods/#findComment-87004 Share on other sites More sharing options...
Mutley Posted September 6, 2006 Author Share Posted September 6, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/19747-using-multiple-id1-methods/#findComment-87371 Share on other sites More sharing options...
Mutley Posted September 7, 2006 Author Share Posted September 7, 2006 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:[code]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 ^--><? } } }[/code]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. Quote Link to comment https://forums.phpfreaks.com/topic/19747-using-multiple-id1-methods/#findComment-87707 Share on other sites More sharing options...
Mutley Posted September 7, 2006 Author Share Posted September 7, 2006 Come on you PHP Freaks, what am I doing wrong? ;D Quote Link to comment https://forums.phpfreaks.com/topic/19747-using-multiple-id1-methods/#findComment-87854 Share on other sites More sharing options...
roopurt18 Posted September 7, 2006 Share Posted September 7, 2006 I fail to see why you have <? and ?> all over the place.[code]<?php// What happens if the url contains page=0?// 0 could be a valid page number, but won't pass the test (I think)// I recommend testing: if(isset($_GET['page'])){if($_GET['page']){ // In your query you refer to $page, but nowhere did you give it a value // change $page in your query to $_GET['page'] $sql = "SELECT * "; $sql .= "FROM pages "; //$sql .= "WHERE page_id=".$page." "; $sql .= "WHERE page_id={$_GET['page']}"; // $page changed to use $_GET $result = mysql_query($sql) or die (mysql_error()); if(mysql_num_rows($result) == 1) { $row = mysql_fetch_array($result); $content = $row['content']; $content // This should probably read: echo $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 // should probably say: echo $content_empty; } }}?>[/code]If you have questions about the following line of code:$page = isset($_GET['page']) ? $_GET['page'] : 1;See [b]The Ternary Operator[/b] at [url=http://www.php.net/operators.comparison]http://www.php.net/operators.comparison[/url][code]<?php// Here is a shorter block of code that should do what you want// Set the page, using a default if $_GET['page'] is not set$page = isset($_GET['page']) ? $_GET['page'] : 1;$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] Quote Link to comment https://forums.phpfreaks.com/topic/19747-using-multiple-id1-methods/#findComment-87864 Share on other sites More sharing options...
Mutley Posted September 7, 2006 Author Share Posted September 7, 2006 Thanks but it isn't doing what I mean.If someone went to:www.mysite.com/index.php?id=1It would return a website with no content because all the content is in the "pages" part of the database, so if I went to:www.mysite.com/index.php?id=1&page=2I would see content on Page 2 for the User 1 and if I went to ?id=1&page=1 it would show page 1 of the user 1.Now what I want it to do, is if I goto www.mysite.com/index.php?id=1 for it to show what would be on www.mysite.com/index.php?id=1&page=1See what I mean? Quote Link to comment https://forums.phpfreaks.com/topic/19747-using-multiple-id1-methods/#findComment-87900 Share on other sites More sharing options...
HuggieBear Posted September 7, 2006 Share Posted September 7, 2006 Makes sense now....[code]<?php $page = isset($_GET['page']) ? $_GET['page'] : '1'; // if $_GET['page'] is set then assign it to the variable $page, else assign '1'?>[/code]Try that at the top of your code.Rich Quote Link to comment https://forums.phpfreaks.com/topic/19747-using-multiple-id1-methods/#findComment-87905 Share on other sites More sharing options...
roopurt18 Posted September 7, 2006 Share Posted September 7, 2006 Unless I totally misunderstood you, I'm not sure you even looked at what I wrote. Quote Link to comment https://forums.phpfreaks.com/topic/19747-using-multiple-id1-methods/#findComment-87907 Share on other sites More sharing options...
Mutley Posted September 7, 2006 Author Share Posted September 7, 2006 At the top of my page I have this:[code]$page = isset($_GET['page']) ? $_GET['page'] : '1';[/code]Then further down this:[code]<?phpif($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]It won't work, I feel like I'm doing something obviously wrong, as Roopurt18 suggests. Quote Link to comment https://forums.phpfreaks.com/topic/19747-using-multiple-id1-methods/#findComment-87917 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.