Jump to content

Is this correct?


ItsWesYo

Recommended Posts

[b]links.php[/b] (links will be displayed from a mysql database)
[code]
<?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; }


}
?>
[/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]
<?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; }


}
?>
[/code]




Sorry if it seems confusing
Link to comment
Share on other sites

ok the way that I use a switch statement is like this
[code=php:0]
<?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
?>[/code]

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

Hope this helps,
Tom
Link to comment
Share on other sites

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
?>
Link to comment
Share on other sites

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]
<?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
?>
[/code]

And yes in php a coment is ether started with // or /* and ends with */
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.