Jump to content

Recommended Posts

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!

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.

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

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!

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.

 

:)

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.

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.

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.

 

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.