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 Link to comment https://forums.phpfreaks.com/topic/16372-is-this-correct/ 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 Link to comment https://forums.phpfreaks.com/topic/16372-is-this-correct/#findComment-68103 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" Link to comment https://forums.phpfreaks.com/topic/16372-is-this-correct/#findComment-68110 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 Link to comment https://forums.phpfreaks.com/topic/16372-is-this-correct/#findComment-68118 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. Link to comment https://forums.phpfreaks.com/topic/16372-is-this-correct/#findComment-68120 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. Link to comment https://forums.phpfreaks.com/topic/16372-is-this-correct/#findComment-68123 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. Link to comment https://forums.phpfreaks.com/topic/16372-is-this-correct/#findComment-68132 Share on other sites More sharing options...
tomfmason Posted August 2, 2006 Share Posted August 2, 2006 post what you have . Link to comment https://forums.phpfreaks.com/topic/16372-is-this-correct/#findComment-68135 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?> Link to comment https://forums.phpfreaks.com/topic/16372-is-this-correct/#findComment-68140 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 */ Link to comment https://forums.phpfreaks.com/topic/16372-is-this-correct/#findComment-68145 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.