ItsWesYo Posted August 2, 2006 Share Posted August 2, 2006 [b]links.php[/b] (links will be displayed from a mysql database)[code]<?phpinclude ("http://www.evermoreforums.com/wes/header.php");$page = ((isset($_REQUEST['id']))?($_REQUEST['id']):(''));switch($page){case "1": { echo ( "testing" );break; }default: { echo ( "blah, the main page" ); break; }}?>[/code][b]db.php[/b][code]<?mysql_connect("localhost","user","password"); mysql_select_db("my_database"); [/code][b]The question is:[/b]Would I do this to 'links.php'?[code]<?phpinclude ("http://www.evermoreforums.com/wes/header.php");$page = ((isset($_REQUEST['id']))?($_REQUEST['id']):(''));switch($page){case "1": { include ("db.php");$result = mysql_query("select * from news");while($r=mysql_fetch_array($result)){ $title=$r["title"]; $message=$r["message"]; echo "$title <br> $message<br>";}?>" );break; }default: { echo ( "blah, the main page" ); break; }}?>[/code]Sorry if it seems confusing Quote Link to comment Share on other sites More sharing options...
tomfmason Posted August 2, 2006 Share Posted August 2, 2006 ok the way that I use a switch statement is like this[code=php:0]<?phpfunction getpage($page) { switch ($page) { case "whatever":// put your php stuff here break; case "whatever2"://dido break; default://put your default page at the end. There is no need for another break after this }}getpage($_GET['page']);//you need this to execute your code?>[/code]Now you can make a link to it like this [b]yourfile.php?page=whatever[/b]Hope this helps,Tom Quote Link to comment Share on other sites More sharing options...
ItsWesYo Posted August 2, 2006 Author Share Posted August 2, 2006 Well, too bad that code doesn't work :P"Parse error: parse error, unexpected T_VARIABLE, expecting T_STRING in /home/evermore/public_html/wes/beta/index.php on line 2" Quote Link to comment Share on other sites More sharing options...
tomfmason Posted August 2, 2006 Share Posted August 2, 2006 sorry man. Made a small error.change this [code=php:0]function $getpage($page) {[/code]to[code=php:0]function getpage($page) {[/code]Good Luck,TOm Quote Link to comment Share on other sites More sharing options...
ItsWesYo Posted August 2, 2006 Author Share Posted August 2, 2006 It's okay and thanks for helping, man. Quote Link to comment Share on other sites More sharing options...
tomfmason Posted August 2, 2006 Share Posted August 2, 2006 also you should only have to include your database connection file once. Do this before the start of the function. Quote Link to comment Share on other sites More sharing options...
ItsWesYo Posted August 2, 2006 Author Share Posted August 2, 2006 everytime i remove "// put your php stuff here" and the other two, it comes up with an error on a break code. Quote Link to comment Share on other sites More sharing options...
tomfmason Posted August 2, 2006 Share Posted August 2, 2006 post what you have . Quote Link to comment Share on other sites More sharing options...
ItsWesYo Posted August 2, 2006 Author Share Posted August 2, 2006 All I did was replace the // with my own words. Knowing me, I probably did it wrong >_><?phpfunction getpage($page) { switch ($page) { case "whatever":fdfd break; case "whatever2":dfdfdfd break; default://put your default page at the end. There is no need for another break after this }}getpage($_GET['page']);//you need this to execute your code?> Quote Link to comment Share on other sites More sharing options...
tomfmason Posted August 2, 2006 Share Posted August 2, 2006 You will want to omit any [code=php:0]<?php[/code] or [code=php:0]?>[/code] in the cases. I will insert your code above into my code so that you can see a working example.[code=php:0]<?phpinclude("db.php");function getpage($page) { switch ($page) { case "1":$result = mysql_query("select * from news");while($r=mysql_fetch_assoc($result)) { $title=$r['title']; $message=$r['message']; echo "$title <br> $message<br>";}mysql_free_result($result); break; case "whatever2"://dido break; default://put your default page at the end. There is no need for another break after this }}getpage($_GET['page']);//you need this to execute your code?>[/code]And yes in php a coment is ether started with // or /* and ends with */ Quote Link to comment 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.