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
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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.