ksb24930 Posted November 11, 2006 Share Posted November 11, 2006 I am trying to display the results of three different tables. the three tables differ only by name, the colums names are the same. So, if i try to recall infomation about the tables on the same page, the results overlap. see code below: how do i get a query to only recall the column information of the specific table!?$sql = "SELECT * FROM imagea ORDER BY image_date desc"; $result = mysql_query ($sql, $conn); if (mysql_num_rows($result)>0) { while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $i++; $str .= $i.". "; $str .= "<a href=\"index.php?iid=".$row["image_id"]."\">".$row["image_name"]."</a> "; $str .= "[".$row["image_date"]."] "; $str .= "[".$row["image_size"]."] "; $str .= "[".$row["image_discription"]."] "; $str .= "[<a href=\"index.php?act=rem&iid=".$row["image_id"]."\">Remove</a>]<br>"; } print $str; }mysql_free_result ($result); echo "<br><br><hr><br>"; $sql = "SELECT * FROM imageb ORDER BY image_date desc"; $result = mysql_query ($sql, $conn); if (mysql_num_rows($result)>0) { while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $i++; $str .= $i.". "; $str .= "<a href=\"index.php?iid=".$row["image_id"]."\">".$row["image_name"]."</a> "; $str .= "[".$row["image_date"]."] "; $str .= "[".$row["image_size"]."] "; $str .= "[".$row["image_discription"]."] "; $str .= "[<a href=\"index.php?act=rem&iid=".$row["image_id"]."\">Remove</a>]<br>"; } print $str; } mysql_free_result ($result); echo "<br><br><hr><br>"; $sql = "SELECT * FROM imagec ORDER BY image_date desc"; $result = mysql_query ($sql, $conn); if (mysql_num_rows($result)>0) { while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $i++; $str .= $i.". "; $str .= "<a href=\"index.php?iid=".$row["image_id"]."\">".$row["image_name"]."</a> "; $str .= "[".$row["image_date"]."] "; $str .= "[".$row["image_size"]."] "; $str .= "[".$row["image_discription"]."] "; $str .= "[<a href=\"index.php?act=rem&iid=".$row["image_id"]."\">Remove</a>]<br>"; } print $str; } mysql_free_result ($result); ?></body> Link to comment https://forums.phpfreaks.com/topic/26925-multiple-table-confusion/ Share on other sites More sharing options...
ksb24930 Posted November 11, 2006 Author Share Posted November 11, 2006 All i need to know is how to stop calling columns with the same name from different tables. Is it something to do with "while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {..." Link to comment https://forums.phpfreaks.com/topic/26925-multiple-table-confusion/#findComment-123150 Share on other sites More sharing options...
freakus_maximus Posted November 11, 2006 Share Posted November 11, 2006 What is happening is that each step is occuring, but the last step is the only thing you are getting. This is becuase your variables are all named the same and essentially just overwrite each other.Try incrementing your variable names such as:$sql1$sql2$sql3Same for $result and $str then give it a run. Just make sure you update your variable names in each section accordingly. Link to comment https://forums.phpfreaks.com/topic/26925-multiple-table-confusion/#findComment-123158 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.