Jump to content


Photo

Is this correct?


  • Please log in to reply
9 replies to this topic

#1 ItsWesYo

ItsWesYo
  • Members
  • PipPipPip
  • Advanced Member
  • 110 posts

Posted 02 August 2006 - 08:48 PM

links.php (links will be displayed from a mysql database)
<?php
include ("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; }


}
?>


db.php
<?
mysql_connect("localhost","user","password"); 
mysql_select_db("my_database"); 


The question is:
Would I do this to 'links.php'?

<?php
include ("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; }


}
?>




Sorry if it seems confusing

#2 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 02 August 2006 - 09:05 PM

ok the way that I use a switch statement is like this
<?php
function 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
?>

Now you can make a link to it like this yourfile.php?page=whatever

Hope this helps,
Tom

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#3 ItsWesYo

ItsWesYo
  • Members
  • PipPipPip
  • Advanced Member
  • 110 posts

Posted 02 August 2006 - 09:16 PM

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"

#4 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 02 August 2006 - 09:22 PM

sorry man. Made a small error.
change this

function $getpage($page) {

to

function getpage($page) {


Good Luck,
TOm



Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#5 ItsWesYo

ItsWesYo
  • Members
  • PipPipPip
  • Advanced Member
  • 110 posts

Posted 02 August 2006 - 09:23 PM

It's okay and thanks for helping, man.

#6 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 02 August 2006 - 09:27 PM

also you should only have to include your database connection file once. Do this before the start of the function.

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#7 ItsWesYo

ItsWesYo
  • Members
  • PipPipPip
  • Advanced Member
  • 110 posts

Posted 02 August 2006 - 09:36 PM

everytime i remove "// put your php stuff here" and the other two, it comes up with an error on a break code.

#8 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 02 August 2006 - 09:40 PM

post what you have .

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#9 ItsWesYo

ItsWesYo
  • Members
  • PipPipPip
  • Advanced Member
  • 110 posts

Posted 02 August 2006 - 09:46 PM

All I did was replace the // with my own words. Knowing me, I probably did it wrong >_>

<?php
function 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
?>

#10 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 02 August 2006 - 09:52 PM

You will want to omit any
<?php
or
?>
in the cases. I will insert your code above into my code so that you can see a working example.

<?php
include("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
?>

And yes in php a coment is ether started with // or /* and ends with */

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users