Hi all.......what is ?

naoshad's picture

He has: 23 posts

Joined: Feb 2005

Hi guys,
I am learning PHP. I see some code in some webpage like:

http://www.webmaster-forums.net/member.php?u=10145
or
http://www.webmaster-forums.net/misc.php?do=bbcode

if anybody tell me that what is " ?u=10145 " and how it is used.

Thanks,
Naoshad.

Thanks,
Naoshad
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Try not to become a man of success, but rather try to become a man of value.
Albert Einstein

pitbull82's picture

He has: 18 posts

Joined: Apr 2005

It's a variable and its value which helps you to manage your site.

Simple example. Save it as example.php:

<?php
<html>
   <
head>
   </
head>
   <
body>
  
   <!--
  
Here we have content of the site
  
-->
  
   if (isset(
$_GET['where']))
          
$where=$_GET['where'];
   else
         
$where='';
   switch (
$where)
   {
           case
'first':
                   echo \
"Here's the content of the first article. (You could use include funcion here)\";
                   break;
           case 'second':
                   echo \"Here's the content of the second article. (You could use include funcion here)\";
                   break;               
           case 'third':
                   echo \"Here's the content of the third article. (You could use include funcion here)\";
                   break;                               
           default:
                   echo \"Here's the main page (or there was bad value of where). (You could use include funcion here)\";
   }
  
  
  
   <ul>
   <li>
           <a href=\"example.php?where=first\">First link</a>
   </li>
   <li>
           <a href=\"example.php?where=second\">Second link</a>
   </li>
   <li>
           <a href=\"example.php?where=third\">Third link</a>
   </li>
  </ul>
   </body>
    </html>
?>

Hope that's useful for you Smiling

naoshad's picture

He has: 23 posts

Joined: Feb 2005

it will be very helpful if you ilaborate the code. i mean if you make comments in every line where necessary.

Naoshad

naoshad's picture

He has: 23 posts

Joined: Feb 2005

thanks a lot for your reply.

pitbull82's picture

He has: 18 posts

Joined: Apr 2005

Well, there's nothing to comment in here. Only switch instruction, $_GET - that's the array which store your variables given via GET method ( example.php?where=first - this is GET method - where will be stored in $_GET['where']), isset - checks if variable exists or not.

That's all. If u don't understand it - sorry, start learning PHP...

He has: 77 posts

Joined: Apr 2005

This might help you out. This is the source code of the homepage of my website. You can see it in action at http://assassin.cjb.cc

Assassin Band
<?PHP
/* here I'm simply including a CSS file. it's got nothing to do with your question */
include("http://assassin.cjb.cc/assassin.css");

/* Here's where it starts to get interesting. This if then thing tells my page that if there is nothing in the "Query string" which is the ?u=10145 in your question that my variable $Pagename should be set to home */
if($_SERVER['QUERY_STRING']==NULL){
$Pagename=home;
}
// This gets the query string if there is one
else{
/* My URL always comes as http://assassin.cjb.cc?$Pagename=whatever. All I want is the whatever, so first I make an array that contains 2 pieces: 1)http://assassin.cjb.cc?$Pagename= and 2) whatever */
$Query = explode("=", $_SERVER['QUERY_STRING']);
// this sets my variable $Pagename to the whatever that I got before
$Pagename=$Query[1];
} ?>

 

  • <?PHP if($Pagename=="home"){ print("

  • "); } else{ print("
  • "); } ?>
  • Home

    <?PHP if($Pagename=="bios"){ print("

  • "); } else{ print("
  • "); } ?>Bios
  • <?PHP if($Pagename=="book"){ print("

  • "); } else{ print("
  • "); } ?>Book Us
  • <?PHP if($Pagename=="originals"){ print("

  • "); } else{ print("
  • "); } ?>Original
    Songs
  • <?PHP if($Pagename=="covers"){ print("

  • "); } else{ print("
  • "); } ?>Song Arsenal
  • <?PHP if($Pagename=="past"){ print("

  • "); } else{ print("
  • "); } ?>Past Shows
  • <?PHP if($Pagename=="shows"){ print("

  • "); } else{ print("
  • "); } ?>Future Shows

<?PHP
/* This sets my page. all of the code above just sets my tabs and my header. this is where the real action is. I have all of my pages set up so that they can be linked to in this matter. */
include("http://www.cjb.cc/members/assassin/" . $Pagename . ".html"); ?>

I really hope this helped. The code can be a little overwhelming at first, but I think you should be able to get it.

naoshad's picture

He has: 23 posts

Joined: Feb 2005

thank you all. Smiling

They have: 26 posts

Joined: Apr 2005

Hiya,

I have just answered a question very similar to this in the thread 'Ready to move from html - php site...how?'. Please take a look at that for a VERY simple explanation.

Thanks,

Andy - http://www.heartsaffection.com

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.