Jump to content

How do URLs in PHP work in relation to the database?


shizknight

Recommended Posts

Ok i'm completely new to PHP and MySQL, and I'm making a site with a friend just as a fun project to learn something new. In my mysql database, there is a db called "cat", for categories, and tables named "movies", "shows", "cartoons" and so on - at this point you may have deducted it was a streaming media site.

 

Anyway on to the question - I don't understand how in php I can get it to display what I wish based on the url.

In the link, site.com/index.php?cat=movies - how can I get it to display the list of movies in the movies table?

 

Thanks in advance, and sorry if this is in the wrong forum.

Ok i'm completely new to PHP and MySQL, and I'm making a site with a friend just as a fun project to learn something new. In my mysql database, there is a db called "cat", for categories, and tables named "movies", "shows", "cartoons" and so on - at this point you may have deducted it was a streaming media site.

 

Anyway on to the question - I don't understand how in php I can get it to display what I wish based on the url.

In the link, site.com/index.php?cat=movies - how can I get it to display the list of movies in the movies table?

 

Thanks in advance, and sorry if this is in the wrong forum.

 

lol, I'm also working on a project like that one... but i hardly get any time to do stuff with it... http://www.media2c.com/ (my bro's for random stuff on it atm)

 

erm, btw, to show everything in the table, you've got to loop it...

Here's an example in it's most basic form.  Of course you will need to change 'movie_name' to whatever you named your column.

 

<?php
if(isset($_GET['cat'])){
$cat=mysql_real_escape_string($_GET['cat']);
$movies=mysql_query("SELECT * FROM $cat");
while($row=mysql_fetch_array($movies)){
	echo $row['movie_name'].'<br />';
}
} else{
echo 'no category selected';
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.