View Full Version : selecting all tables. vers. 2

08-03-2010, 05:25 PM
Hi, i have a very basic knowledge of PHP and currently have the following code on my website (in signature)

$con = mysql_connect("localhost","username","password");
if (!$con)
die('Could not connect: ' . mysql_error());

mysql_select_db("portfolio", $con);

$result = mysql_query("SHOW TABLES")or die(mysql_error());

<script type="text/javascript">alert("Cannot connect to Database.");</script>
<?php ;

while($fetch = mysql_fetch_array($result)){
$result2 = mysql_query("SELECT * FROM ". $fetch[0]. " ORDER BY timestamp DESC LIMIT 6")or die('Error:'. mysql_error());

while($row = mysql_fetch_array($result2)){
$image_src = $row['image_src'];
$thumbnail_src = $row['thumbnail_src'];
$image_width = $row['image_width'];
$image_height = $row['image_height'];
$name = $row['name'];

echo "<a href=\"$image_src\" rel=shadowbox;width=$image_width;height=$image_hei ght; title=\"$name\" >
<div id=\"polaroid\">
<div id=\"polaroidInner\" style=\"background-image:url($thumbnail_src)\">
<div id=\"polaroidShadow\"></div>


apart from it not working as it loads more than the 6 fields i want - i think it is loading 6 from each table - it also seems very complicated.

My question is this, I have read about the JOIN feature on w3schools and in forums, the only problem is i dont think this will work for me, so how do i query all tables called 'flash', 'photoshop' and 'web_design' then load those fields into variables - like above?

thanks in advance i realise what a big question this is :D


08-03-2010, 08:09 PM
You need to join them

You need a relationship in each table to do this


08-03-2010, 08:13 PM
each table has different information in though, or is it still possible to do, they have the same fields though. am i misunderstanding the point of the JOIN?

08-04-2010, 01:18 AM
yes you join on matching fields in each table