Jump to content

[SOLVED] Content management with PHP


woolyg

Recommended Posts

Hi,

 

I have almost 1000 entries on a table in a MySQL DB. What I want to do is to display items from a row, depending on the URL.

 

For Example, I want this url:

http://localhost/players.php?lookup=23

 

to display certain attributes set into the table (ID,Firstname,Lastname), etc.

 

 

I'm using the following code for http://localhost/players.php?lookup=23 and it's not working:

 

 

<?php include("maincore.php"); //maincore is connecting to the mySQL DB.

global $lookup;

$result = mysql_query("SELECT * FROM player_stats WHERE player_statsid='$lookup'");

$row = mysql_fetch_row($result);

echo "Name: $row[1]<br>";

 

?>

 

 

 

 

 

 

When I use this code for http://localhost/players.php and it functions fine:

<?php include("maincore.php");

 

$result = mysql_query("SELECT * FROM player_stats WHERE player_statsid='1'");

$row = mysql_fetch_row($result);

echo "Name: $row[1]<br>";

 

?>

 

 

 

Can anyone tell me how I can define the content of a page depending on the lookup value in the URL?

Cheers

Woolyg

 

 

 

Link to comment
Share on other sites

I'm not sure entirely sure of what you need, but $_GET[''] might work?

 

Example:

<?php
if ($_GET['lookup'] == 23)
{
//conect to database
//Set your variables for ?lookup=23
//...
}
elseif ($_GET['lookup'] == 62)
{
//conect to database
//Set your variables for ?lookup=23
//...
}
?>

Link to comment
Share on other sites

Thanks bobleny, I'll put that into practise and see how I get on.

 

I'm mainly looking to short-circuit having to manually enter variable details. I have a single mySQL table with 12 columns and 950 rows, sorted by ID.

 

What I'd like to do is display this:

User enters URL http://localhost/players.php?lookup=23

 

Page Displays the following:

- player name (column 2 of row 23)

- player age (column 3 of row 23)

- etc

 

 

...I shall continue! If you have any pointers, let me know.

Woolyg

Link to comment
Share on other sites

I'm trying to use the following:

 

<?php

 

$no = array (1,2,3,4,5,6,7,8,9);

if ($_GET['lookup'] == $no)

{

//conect to database

$result = mysql_query("SELECT * FROM table_1 WHERE id='$no"');

$row = mysql_fetch_row($result);

echo "ID: $row[0]<br>";

echo "ID: $row[1]<br>";

}

?>

 

.. but it's not displaying when a user goes to http://localhost/players.php?lookup=2

 

Is it possible to specify an array variable in this manner (where I've specified $no and used it to look up the id of the table)..?

Link to comment
Share on other sites

<?php

$lookup = intval($_GET['lookup']);

//conect to database
$result = mysql_query("SELECT * FROM table_1 WHERE id = $lookup');

$row = mysql_fetch_row($result);

if($row){
echo "ID: ".$row[0]."<br />";
echo "ID: ".$row[1]."<br />";
} else {
"No match in database!";
}
?>

Link to comment
Share on other sites

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.