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
https://forums.phpfreaks.com/topic/16372-is-this-correct/
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
https://forums.phpfreaks.com/topic/16372-is-this-correct/#findComment-68103
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
https://forums.phpfreaks.com/topic/16372-is-this-correct/#findComment-68140
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
https://forums.phpfreaks.com/topic/16372-is-this-correct/#findComment-68145
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.