spacepoet Posted January 18, 2011 Share Posted January 18, 2011 Hi everyone: Can someone show me an example of the proper way to request an id, and then use "If Then Else" statements to display data depending on the id selected. I am use to doing this with ASP, but never with PHP. I have found so many different examples on GOOGLE, but would like some input from this forum. That always helps me. I have a page roster.php: <html> ... <a href="players.php?PlayerID=1">Player 1</a><br /> <a href="players.php?PlayerID=2">Player 1</a><br /> <a href="players.php?PlayerID=3">Player 1</a><br /> <a href="players.php?PlayerID=4">Player 1</a><br /> ... </html> Then it goes to players.php: <?php $myvar = $_REQUEST['PlayerID']; echo $myvar; ?> IS THE ABOVE THE PROPER WAY TO REQUEST AN ID? <html> ... <% If PlayerID=1 Then %> PLAYER 1 PHOTO AND BIO <% ElseIf PlayerID=2 Then %> PLAYER 2 PHOTO AND BIO <% ElseIf PlayerID=3 Then %> PLAYER 3 PHOTO AND BIO <% Else %> PLAYER 4 PHOTO AND BIO <% End If %> ... </html> I would write it somewhat like that with ASP. How do I do this with PHP? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/224799-proper-way-to-request-id-and-do-if-then-else-with-php/ Share on other sites More sharing options...
Pikachu2000 Posted January 18, 2011 Share Posted January 18, 2011 When the var is a part of the URL query string, you cna use $_GET rather than $_REQUEST. Beyond that, it's hard to help with the rest of your question without knowing how the bios and photos are actually stored etc. Quote Link to comment https://forums.phpfreaks.com/topic/224799-proper-way-to-request-id-and-do-if-then-else-with-php/#findComment-1161177 Share on other sites More sharing options...
crabfinger Posted January 18, 2011 Share Posted January 18, 2011 <?php $strThisPage = 'hello.php'; // Change this to your page name $players['1'] = 'player 1'; $players['2'] = 'player 2'; $players['3'] = 'player 3'; $players['4'] = 'player 4'; $players['5'] = 'player 5'; if( isset( $_GET['player'] ) && !empty( $_GET['player'] ) ) { if( isset( $players[$_GET['player']] ) ) { print $players[$_GET['player']] . '<br /><br />'; } } foreach($players as $key => $value) { print '<a href="' . $strThisPage . '?player=' . $key . '">' . $value . '</a><br />'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/224799-proper-way-to-request-id-and-do-if-then-else-with-php/#findComment-1161178 Share on other sites More sharing options...
spacepoet Posted January 18, 2011 Author Share Posted January 18, 2011 Thanks I will look at this. One thing: This is a site I just took over, and the site is mostly in HTML. There is no database pulling out the data (not in the budget to build it, either). I just don't want to have to make a new page for every player; I'm trying to use just one page, and decide what photo/bio to show depending on what ID is clicked. Does that make sense? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/224799-proper-way-to-request-id-and-do-if-then-else-with-php/#findComment-1161184 Share on other sites More sharing options...
crabfinger Posted January 18, 2011 Share Posted January 18, 2011 If you have access to the server mysql is very easy and free to install. I would recommend looking into it. otherwise what I posted will do exactly what you're asking for, just modify the code to show what you want it to. Quote Link to comment https://forums.phpfreaks.com/topic/224799-proper-way-to-request-id-and-do-if-then-else-with-php/#findComment-1161189 Share on other sites More sharing options...
spacepoet Posted January 18, 2011 Author Share Posted January 18, 2011 OK, thanks for clarifying. I will play around with it tomorrow. Might have some questions, but it's a good start! The site probably has mySQL (I know it has PHP) but it's not the type of project budgeted for a database development, admin panel, etc. Quote Link to comment https://forums.phpfreaks.com/topic/224799-proper-way-to-request-id-and-do-if-then-else-with-php/#findComment-1161192 Share on other sites More sharing options...
crabfinger Posted January 18, 2011 Share Posted January 18, 2011 really budget has nothing to do with databases, learn how to use phpmyadmin (free) or an ssh terminal and the mysql command to build databases and tables, even build the databases using php code. there are a world of possibilities which cost nothing if you already have the server. Quote Link to comment https://forums.phpfreaks.com/topic/224799-proper-way-to-request-id-and-do-if-then-else-with-php/#findComment-1161194 Share on other sites More sharing options...
trq Posted January 18, 2011 Share Posted January 18, 2011 The site probably has mySQL (I know it has PHP) but it's not the type of project budgeted for a database development, admin panel, etc. If this project is being done on a clients budget you really shouldn't be doing it at all should you? You don't even understand a simple if elseif statement, I think it's pretty unfair to be getting paid. Anyway, if statements (like everything else) are covered in the manual. See if. Quote Link to comment https://forums.phpfreaks.com/topic/224799-proper-way-to-request-id-and-do-if-then-else-with-php/#findComment-1161205 Share on other sites More sharing options...
spacepoet Posted January 18, 2011 Author Share Posted January 18, 2011 This is a small part of a bigger project, mostly involving graphics, Flash, layout, CSS (and I understand each very well) so of course I should get paid. I understand "If Then Else" very well but am use to ASP syntax. I'm just looking for tips on the best syntax to use when doing PHP, which I have very little experience using. That's why I come to this forum, seeking advice. I will look at the link you posted. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/224799-proper-way-to-request-id-and-do-if-then-else-with-php/#findComment-1161505 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.