2012-11-08 117 views
2

我有两个表,imagevideo。我想在一个表格中显示来自图像和视频的所有数据。我知道如何显示来自视频的所有数据,但是如何在同一张表中显示来自图像的所有数据。有一张桌子可以显示来自视频的所有数据,但是有人可以告诉我如何在显示来自视频的数据完成时显示来自同一个表格中图像的所有数据。如何在一个表中显示来自两个数据表的数据

<table width="879" border="2" cellpadding="3" cellspacing="1"> 
    <tr> 
    <td colspan="11" align="center" ><strong>All uploaded videos</strong> 
    </td> 
    </tr> 
    <tr> 
    <td width="51" align="center" bgcolor="#000000" class="yellow"><strong>Id</strong></td> 
    <td width="95" align="center" bgcolor="#000000" class="yellow"><strong>Video</strong></td> 
    <td width="83" align="center" bgcolor="#000000" class="yellow"><strong>Name</strong></td> 
    <td width="130" align="center" bgcolor="#000000" class="yellow"><strong>Date</strong></td> 
    <td width="177" align="center" bgcolor="#000000" class="yellow"><strong>Description</strong></td> 
    <td width="101" align="center" bgcolor="#000000" class="yellow"><strong>Price</strong></td> 
    <td width="174" align="center" bgcolor="#000000" class="yellow"><strong>Added by</strong></td> 
    </tr> 

    <?php $path= "videoFile/"; 
    while($rows=mysql_fetch_array($result1)){ 
    ?> 

    <tr> 
    <td> 
     <?php if (current_user_can('manage_options')) { echo $rows['vid'];}else { echo "For admins only!"; } ?> 
    </td> 
    <td><a href="<?php echo $path.$rows['filename'] ?>">View video</a></td> 
    <td><?php echo $rows['alttext']; ?></td> 
    <td><?php echo $rows['imagedate']; ?></td> 
    <td><?php echo $rows['description']; ?></td> 
    <td><?php echo "$".$rows['price']; ?></td> 
    <td><?php echo $rows['user_nicename']; ?></td>  
    </tr> 

    <?php 
    } 
    ?>  
</table> 
+0

向我们展示您的mysql查询。 –

+0

$ sql1 =“选择*从视频连接wp_users on video.userID = wp_users.id order by imagedate”; $ sql2 =“选择*从图像加入wp_users在images.userID = wp_users.id秩序由imagedate”; –

回答

0
SELECT * 
FROM video 
JOIN wp_users ON wp_users.id = video.userID 
JOIN images ON images.userID = wp_users.id 
ORDER BY imagedate 

检查已接纳的答案here

相关问题