[advanced search]
 

Go Back   NamePros.com > Discussion > Web Design & Development > Programming

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.


Closed Thread
 
LinkBack Thread Tools
Old 09-14-2005, 01:00 PM   #1 (permalink)
Senior Member
 
Join Date: May 2005
Location: Ontario Canada
Posts: 2,928
1,675.13 NP$ (Donate)

unknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to behold


?f=49

Hey
I have seen this in alot of websites..


How do ppl make Different pages in 1 PHP file

and then link them like this

CURRENTPAGE.PHP?do=something
or
currentpage.php?f=blah

can any1 help me on that

basically i am making a website with Game cheats..and so on and I Need a way of adding ALL THE ALPHATIC pages in 1 FILE

so at the top it says CHEATS: A B C ........... Z

and i dont want to make seprate FILES for each of the alphate but instead i just want it in 1 FILE but when some1 clicks on A ...i only want it to show the content of A in the content box instead of other stuff.... {HINT: NOT BOOKMARK TECHN.}

so if some1 clicks on A it redirects to

cheats.php?f=a

if some1 clicks on C it redirects to

cheats.php?f=c

and a way to add the CONTENT in "f=a" and stuff so it only SHOWS That when some1 clicks on "A"..

I hope u know what i am talking about :P
unknowngiver is offline  
Old 09-14-2005, 01:06 PM   #2 (permalink)
DNOA Member
 
mholt's Avatar
 
Join Date: May 2004
Location: Utah
Posts: 5,041
18.01 NP$ (Donate)

mholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant future

Autism Marrow Donor Program 9/11/01 :: Never Forget Multiple Sclerosis Adoption Alzheimer's Lou Gehrig's Disease (ALS)
Hey unknowngiver,

In the URL, the question mark means that everything after that is recognized as data for scripting languages (not HTML).

So, for example...

page.php?f=12

If that page appeared in a webpage link, it would send the variable "f" with a value of 12 over to page.php.

Multiple variables...

page.php?f=12&a=17

This means it sends "f" and "a" to page.php with the associated values.

As for multiple pages in 1 file, they just write a PHP script that calls include files or header() redirects to another page based on the information in that variable.

See what I mean?
__________________
codeboards

A high-quality community of programmers -- Join today and post! We want new members!
mholt is offline  
Old 09-14-2005, 04:20 PM   #3 (permalink)
Senior Member
 
Join Date: May 2005
Location: Ontario Canada
Posts: 2,928
1,675.13 NP$ (Donate)

unknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to behold


no its not tht



<?php
if($action=="contact_us"){
$img="images/message.gif";
}else{
$img="images/welcome.gif";
}
?>

just an example i could find

Basicaly what i want is tht

When some1 clicks 'A'

everything else from the content box gets hidden and only the stuff for A shows

etc

so it oculd be something like tht?


<?php
if($action=="A"){
$content="Content for A";
}else{
$content="Main content";
}
?>

and then do it for B in the same page etc...
unknowngiver is offline  
Old 09-14-2005, 04:55 PM   #4 (permalink)
NPQ's PA, Slave, and On Call Coder

Technical Services


 
Eric's Avatar
 
Join Date: Mar 2005
Posts: 4,545
0.71 NP$ (Donate)

Eric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond repute

Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Cancer Alzheimer's Protect Our Planet Cancer Survivorship SIDS Child Abuse
Yea something like that I suppose,

PHP Code:
<a href='script.php?action=1'>A</a>
<a href='script.php?action=2'>B</a>
<a href='script.php?action=3'>C</a>
<?php
if($action == 1)
{
echo
"Content for A.";
}
if(
$action == 2)
{
echo
"Content for B.";
}
if(
$action == 3)
{
echo
"Content for C.";
}
?>
Heh,
__________________
Eric is offline  
Old 09-14-2005, 05:03 PM   #5 (permalink)
Senior Member
 
Join Date: May 2005
Location: Ontario Canada
Posts: 2,928
1,675.13 NP$ (Donate)

unknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to behold


Yes but i only want the content to appear in the content box....but i think wid this code.. the nav bar and other stuff on the page will also disapear?
unknowngiver is offline  
Old 09-14-2005, 05:41 PM   #6 (permalink)
tgo
NamePros Regular
 
Join Date: Aug 2005
Posts: 317
103.75 NP$ (Donate)

tgo is on a distinguished road


Ok well since you want it all in one page, usualy this is done with a database.

You see what you see with the

yourpage.php?yourvariable=x

This takes the value of yourvariable (x) and looks in a database to match that with a field to find the row of information that you need for that page with that variable.

Example
http://famousqt.com/profile.asp?celeb=1 - Jessica Alba
http://famousqt.com/profile.asp?celeb=2 - Jennifer Love Hewitt
Its the same code, just pulls different information depending on what the celeb variable is.

This example takes the celeb variable, looks in the database and finds the info for that number, then pulls the information to display it on screen.

My database has this info

CelebId (primary key, unique)
CelebName
CelebBiography
etc.

In the url
http://famousqt.com/profile.asp?celeb=1
I just bring up the database record for the CelebId that matches "1" and I can then read all information in the database for that celebrity, like their name, or biography.

Hope this helps.
tgo is offline  
Old 09-14-2005, 06:36 PM   #7 (permalink)
Senior Member
 
Join Date: May 2005
Location: Ontario Canada
Posts: 2,928
1,675.13 NP$ (Donate)

unknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to behold


Okay since you are getting into databases..can you explain it as i was going to make a website with games cheats..and description of it

So how am i going to do that

Should i have 2 tables for it then?

1 that will display the LINKS to games starting with A B C - Z

and the other one that will have the information {cheat..game name..description}

Can you please explain how am i suppose to do it {i will donate some NP$ if it really helps}

Basically i want it all done in 1 page

So when some1 clicks on "A"
it shows the stuff from the TABLE "A" and then if some1 selects a game starting with "A" lets say "AIRPLANE W.E" then he/she will see a page witth tht games cheats and description..?
unknowngiver is offline  
Old 09-14-2005, 07:49 PM   #8 (permalink)
tgo
NamePros Regular
 
Join Date: Aug 2005
Posts: 317
103.75 NP$ (Donate)

tgo is on a distinguished road


What your asking for will need 1 table and 2 pages.

Table
Games
-Fields
--GameId (primary Key, auto increment)
--GameName
--GameShortDescription
--GameDescription
--GameReview
--GameCheats
--Other unique to the game fields

Page 1 -gamelist.asp
-objective - display all game names, and short description that start with a certain letter with links to them all above.
Look Like
A B C ..... X Y Z
ace - Short Description of the game....
arobatics - Short Description of the game....
astronaught - Short Description of the game....
etc...
--Code Needed--
Read the url, see if it has a variable (perhaps you name it letter)
-your url should look like gameslist.asp?letter=A

If there is no letter variable you can display the "A" record on default
-do this by using SQL and select only the records where the GameName starts with a "A"
-MYSQL code to do this(I didnt test this)
Code:
SELECT GameId, GameName, GameShortDescription FROM games where GameName LIKE 'a%'
Then you loop through all the games that start with A


If there is a letter variable you check what it is and use that in your my SQL instead of the default
So if they press the "H" it will display the ones that start with H.
ASP way, I dont know PHP that well
Code:
mySQL="SELECT GameId, GameName, GameShortDescription FROM games where GameName LIKE  '" & letter & "%'"
Then you loop through all the games that start with the variable letter

** when looping use the gameId field from the database in the url of the links to the games
** All links look like "gamedata.asp?game=<%=objRs("GameId")%>
** this ensures you can find on the next page what game to display the info for.

Page 2 - gamedata.asp
-objective - display the game name, Description, Cheats
Read the url and find what the game variable is.
Take that variable, and do a SQL statement like below
Code:
mySql="SELECT GameId, GameName, GameDescription, GameCheats FROM games where GameId=" & game
Since GameId is unique, it will only return 1 record and you can display that info for that game.

Thats the way I would do it, hope this helps.
tgo is offline  
Old 09-14-2005, 08:20 PM   #9 (permalink)
Senior Member
 
Join Date: May 2005
Location: Ontario Canada
Posts: 2,928
1,675.13 NP$ (Donate)

unknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to behold


sorry can u do it in PHP instead of ASP
unknowngiver is offline  
Old 09-14-2005, 08:26 PM   #10 (permalink)
tgo
NamePros Regular
 
Join Date: Aug 2005
Posts: 317
103.75 NP$ (Donate)

tgo is on a distinguished road


Quote:
Originally Posted by unknowngiver
sorry can u do it in PHP instead of ASP
Nope but its the same concept.
tgo is offline  
Old 09-15-2005, 01:48 AM   #11 (permalink)
NamePros Regular
 
dkin69's Avatar
 
Join Date: May 2005
Posts: 358
15.75 NP$ (Donate)

dkin69 has a spectacular aura aboutdkin69 has a spectacular aura about


I created my site this way using files and switchs like so

function page1()
{
code
}

switch ("$page")
{
case "abc":
page1();
break;

}

then your url would be .php?page=abc
dkin69 is offline  
Old 09-15-2005, 05:46 AM   #12 (permalink)
SQLdumpster.com
 
miseria's Avatar
 
Join Date: Jun 2005
Location: West Sussex, UK
Posts: 545
205.50 NP$ (Donate)

miseria will become famous soon enoughmiseria will become famous soon enough


Please show some gratitude, these people are trying to help you out. I think SecondVersion's post may be of use to you. If you are worried that your navbar and head will not be displayed, code them into different php files and "include" them like so:

PHP Code:
if($action == 1)
{
include (
"head.php");
include (
"nav.php");

echo
"Content for A.";

include (
"foot.php");
}
__________________
!!!!!!! see something you like? Accepting offers for great affiliate websites !!!!!!!
Free Databases for your Website | All Things Playstation 3
Website Design Books | Music While You Work? | Computer Gadgets
miseria is offline  
Old 09-15-2005, 08:47 AM   #13 (permalink)
Senior Member
 
Join Date: May 2005
Location: Ontario Canada
Posts: 2,928
1,675.13 NP$ (Donate)

unknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to behold


Yea but again it will display the nav and header in tht order right?

I have included the Nav bar and so on in different places...and i only want to change the CONTENT area for A-Z
unknowngiver is offline  
Old 09-15-2005, 09:20 AM   #14 (permalink)
NamePros Regular
 
Join Date: Aug 2005
Posts: 214
170.00 NP$ (Donate)

slantednet is on a distinguished road


You keep saying "change the content area" but your taking big steps. You're looking at developing this site, break it down into baby steps.

The baby steps your looking at isn't just "change the content area", you're actually going to call back the same page and pass it some variables. With those variables in the page, your going to requery the information you need from the table, "rebuild" the page, and display it to the user.

In the user's mind, you're only "changing the content area" but from a development point of view you've got a few more steps to go through to accomplish this.

I recommend googling for a couple of PHP tutorials, get yourself a PHP IDE (not necessary, but helpful, and there are many free ones out there (PHP Designer 2005 is looking real nice)) and start giving it a shot. What your looking to do is rather simple, and a great introduction project to developing dynamic sites with PHP.

When you get stuck on a part, come back here and post in the programming forum. There are many talented people here that are willing to offer a helping hand to those that help themselves, or cough up some duckies for the assistance.

But here, to get you started, just design your page in HTML, you don't have to start with generating the whole thing in PHP. Lay it out exactly how you want it, and where your navbar is with the "A B C D E" make the links link back to the page. So if your working on listing.php, put all html in there, and for link A, use the url "listing.php?list=a", for B use "listing.php?list=b", etc.

Then, down where you want the content area for your page, do this (this is pseudo code, it won't work as typed, you want to learn, do some research)

PHP Code:
if $list is not set {
    
// generate whatever you want to display for when they come without
    // specifying a letter
} else {
   if
$list is not numeric and length of $list is equal to 1 {
//only one letter in list
        // setup your query
        
$query = "select blah blah blah from blahtable where title like '$list%'"
        
// execute the query
        
$res = do_query($query);
        
// set a var to hold your display
        
$pageinfo = ""
        
// then loop through the resulting rows
        
while($row = fetch_result_array($res)) {
              
// display content for each resulting row from the database
              
$pageinfo .= "<tr><td>" . $row['title'] . "</td></tr>";
        }
   }
}

// kick the resulting "content area" back to the user
echo $pageinfo;

// then continue on with the rest of your html
Really, it's that simple. Of course, there are grander ways to do this, but this will get you started with the basics.

Good luck,
Mike
__________________
OnlineGames.net

Last edited by slantednet; 09-15-2005 at 09:32 AM.
slantednet is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Site Sponsors
Advertise your business at NamePros

All times are GMT -7. The time now is 06:04 AM.


Powered by: vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0
Template-Modifications by TMS
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85