use part of url as a field in select statement

Dear all,

I have written a script to create new files on my site, populated with a basic template. I have an SQL database that stores the field " $artist " as the same as the file name created, i.e. www.mysite.com/$artist.php.

I was wondering if it is possible to write into the basic template a way of dragging down the main part of the file/URL name to use as the $artist field in the script, whilst also removing the “.php” bit. i.e.

$query="SELECT * FROM table WHERE artist=‘www.mysite.com/ ‘$artist’ .php’ ";

so that the page now viewed only has data about that particular artist and not just the whole of the contents of the $artist column on display.

Perhaps there is another/better way to do this though. I’m not keen on using id’s as there are several entries under the same $artist name, but would be willing to try if you see fit.

Thanks in advance,
Matt

If you create separate file for each new artist, you definitely can extract this artist name from URI, and use it to query database. Here is how you can do this:
[php]<?php
$artist = basename($_SERVER[“PHP_SELF”], “.php”);
$query=“SELECT * FROM table WHERE artist=’”.mysql_real_escape_string($artist)."’";
?>[/php]

But instead of creating new .php file for each artist, you can have one stript, say index.php and pass artist name via query string:

http://www.mysite.com/index.php?artist=xyz

and within index.php have this code:
[php]<?php
$artist = urldecode($_GET[“artist”]);
$query=“SELECT * FROM table WHERE artist=’”.mysql_real_escape_string($artist)."’";
?>[/php]

Thankyou, this has proved incredibly helpful.

Sponsor our Newsletter | Privacy Policy | Terms of Service