Jump to content

multiple table confusion


ksb24930

Recommended Posts

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

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
$sql3

Same for $result and $str then give it a run. Just make sure you update your variable names in each section accordingly.

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.