Quote:
Originally Posted by FRANK(WGH)
Could you show me a sample of the connection configuration you would use. I specified localhost as my server and then 127.0.0.1 and neither worked.
Also, What does the database structure look like. I created a database with a table called picture. what columns do I need to have for your script to work.
|
OK, so the connection configuration.
First of all, PHP has a bunch of built in functions that allow for many things to happen with MySQL. You can see all of those
here scroll towards the botton for all of the function or search for "Innehållsförteckning".
The way I setup the MySQL connect in the script above is this.
PHP Code:
$server = "[insert here]"; //url for the mysql server
$DBuser = "[insert here]"; //database username
$DBpass = "[insert here]"; //database password
$conn = mysql_connect($server,$DBuser,$DBpass); //connect to server
That part is pretty straightforward. For the sake of simplicity, I will show you how to setup the database structure as well.
First, create a MySQL database and call is 'FRC_0048_gallery' (I used FRC_0048 because you need a unique name since you are most likely on a shared server)
Then within the database 'FRC_0048_gallery' create a column with the name of 'PICTURES'
Then create 2 rows called 'PICTURE_URL' and 'PICTURE_DATE'
Then using all of that, it comes together to make a PHP script that looks like this
PHP Code:
<table>
<tr>
<?php
//config section
$column_limit = 5; //change to howver many columns you want
//MySQL information
$server = "[insert here]"; //url for the mysql server
$DBuser = "[insert here]"; //database username
$DBpass = "[insert here]"; //database password
$DB = "FRC_0048_gallery"; //actual database name
//column counter
$column_counter = 0;
$conn = mysql_connect($server,$DBuser,$DBpass); //connect to server
mysql_select_db($DB); //select database
$query = "SELECT * FROM PICTURES"; //select items from column PICTURES
$results = mysql_query($query);
while($row = mysql_fetch_assoc($results))
{
if($column_counter == $column_limit)
{
echo '</tr><tr>'; //End current row, and start a new row
$column_counter = 0; //reset the column counter
}
else {
echo '<td><a href="' .$row[PICTURE_URL]. '" ><img src="' .$row[PICTURE_URL]. '" /></a><br>'; //Echo a link to the image, and display the image as well
echo 'Added to gallery:' .$row[PICTURE_DATE]. '</td>'; //display the dat it was added
$column_counter++; //Add one to the counter
}
}
?>
</tr>
</table>