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.$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=‘ ‘$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,

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:
$artist = basename($_SERVER[“PHP_SELF”], “.php”);
$query=“SELECT * FROM table WHERE artist=’”.mysql_real_escape_string($artist)."’";

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:

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

Thankyou, this has proved incredibly helpful.

Sponsor our Newsletter | Privacy Policy | Terms of Service