Jump to content

Mysql select all tables then post each table name in a different query


jamesyrawr

Recommended Posts

I have a photo album style gallery to build

and

i'm finding it dificult to list all the table names (these are names of photo albums) and then enter the data into a seperate query for each album name (these will change often so i cant keep updating the file as normal. this will then post all the data to the xml file and show the set of photos in the individual albums in a flash file.

can anyone help me where im going wrong at all?

 

 

 

<?php
$dbname = 'cablard';

if (!mysql_connect('localhost', 'cablard', '')) {
    echo 'Could not connect to mysql';
    exit;
}

$sql = "SHOW TABLES FROM $dbname";
$result = mysql_query($sql);

if (!$result) {
    echo "DB Error, could not list tables\n";
    echo 'MySQL Error: ' . mysql_error();
    exit;
}

while ($row = mysql_fetch_row($result)) {
    echo "Table: {$row[0]}\n";
}

mysql_free_result($result);



$query = "SELECT * FROM photo ORDER BY id DESC"; 
$result2 = mysql_query ($query)  or die ("Error in query: $query. ".mysql_error());

   
   while ($row = mysql_fetch_array($result2))  
   {                                       
         echo  "
	<image>
		<date>".$row['date']."</date>
		<title>".$row['title']."</title>
		<desc>".$row['description']."</desc>
		<thumb>".$row['thumb']."</thumb>
		<img>".$row['image']."</img>
	</image>

";


   }                      
?>

 

Thanks

James

i would not use a different table for each album. as you've seen, that makes things more difficult and less efficient. just use one table, with a unique identifier linking to a second table containing information for each album.

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.