Jump to content

Table name = variable


damju87
 Share

Recommended Posts

At the top of my page, I have:

<?php//connect to dbinclude "MyConnect.php";// $artist = $_GET['Mia'];?>

Inside the "MyConnect" is:

//get all of the photos$photoList = "";$artist = $_POST['artist'];$sql = mysql_query("SELECT * FROM $artist ORDER BY photoID DESC LIMIT 6");//check for photos$photoCount = mysql_num_rows($sql); if ($photoCount > 0){	while($row = mysql_fetch_array($sql)){			$photoID = $row["photoID"];			$photoName = $row["photoName"]; 			$photoList .= '<li class="thumb">				 <a href="#"><img src="../images/mia/' . $photoName . '.jpg" alt="' . $photoName . '" width="100" height="100" /></a>			  </li>';	}}else{	$dynamicList = "There are no photos at this time!";}

What I'm trying to do is, set $artist to equal Mia which will make FROM $artist into FROM Mia. I want to repeat this on more pages.

Link to comment
Share on other sites

Code different scripts for different pages and adapt MyConnect.php to the page you need to create. That's the answer to the question that I think you're asking.

Link to comment
Share on other sites

Wait... don't you already have the artist at the $artist variable? Why not simply name your data folder (pictures, etc.) in the same way you name the DB tables? That way, you can do what you want by simply changing:

                        $photoList .= '<li class="thumb">                                 <a href="#"><img src="../images/mia/' . $photoName . '.jpg" alt="' . $photoName . '" width="100" height="100" /></a>                          </li>';

into

                        $photoList .= '<li class="thumb">                                 <a href="#"><img src="../images/' . $artist .'/' . $photoName . '.jpg" alt="' . $photoName . '" width="100" height="100" /></a>                          </li>';

BTW, you have at least one security issue (two, if you implement my proposal above "as is"), but we can fix that once the basics are working the way you want them to.

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...