woolyg Posted April 17, 2007 Share Posted April 17, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/47385-solved-content-management-with-php/ Share on other sites More sharing options...
bobleny Posted April 17, 2007 Share Posted April 17, 2007 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 //... } ?> Quote Link to comment https://forums.phpfreaks.com/topic/47385-solved-content-management-with-php/#findComment-231164 Share on other sites More sharing options...
woolyg Posted April 17, 2007 Author Share Posted April 17, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/47385-solved-content-management-with-php/#findComment-231619 Share on other sites More sharing options...
woolyg Posted April 18, 2007 Author Share Posted April 18, 2007 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)..? Quote Link to comment https://forums.phpfreaks.com/topic/47385-solved-content-management-with-php/#findComment-231849 Share on other sites More sharing options...
HeyRay2 Posted April 18, 2007 Share Posted April 18, 2007 <?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!"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/47385-solved-content-management-with-php/#findComment-231859 Share on other sites More sharing options...
woolyg Posted April 18, 2007 Author Share Posted April 18, 2007 Beautiful. Thanks a million HeyRay2! Quote Link to comment https://forums.phpfreaks.com/topic/47385-solved-content-management-with-php/#findComment-231881 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.