我是php的新手,我知道我想做什么,但我不知道如何执行它们。
mysql表1中有两个表,包含:
ID|Name|AboutMe|Specialisation
Example:
101|Andrew|handsome|drawing
102|Jane|pretty|drawing
103|Daniel|cute|swimming
table 2 contains
ID|Link|Title
101|//image1.jpg|Drawing in the dark
102|//image2.jpg|Drawing in me
103|//image3.jpg|Fish swimming我想显示一些图片,是链接到一个专业,只有在我的网站运行。
我所拥有的一切
// get all the ID with drawing as specialisation // will return 2 rows
select ID FROM table1 WHERE Specialisation = "Drawing";
id = ID2)从匹配的每一行中,取ID从表2中获取链接,如下所示
// get row of the links from the userid
Select * FROM userdatafiles WHERE ID = id
store the links into a variable and send to my jquery to display.因此,基本上获取与绘图匹配的每一行的id,并从表2中获取相同的id并获取链接,并将其发送到jquery。
由于有许多行我必须发送,而且我需要使用数组&循环,所以我不确定我如何能做到这一点。有人能引导我做些什么吗?谢谢!
更新:
jquery:
$.ajax({
type: "POST",
//dataType: "json",
url: "CMS/PHP/displayFeatThumbs.php",
success: function(data) {
alert(data[0]);
}
});PHP:
<?php
include 'dbAuthen.php';
$sql = 'SELECT * FROM userdatafiles JOIN users ON userdatafiles.UserID = users.UserID WHERE Specialisation = "Interactive Art & Technology"';
$result = mysqli_query($con,$sql);
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
echo $links[] = $row["Link"];
}
} else {
echo "0 results";
}
?>不知道如何在jquery上显示数组索引,同时尝试了警告(数据)、警报(data.links);
发布于 2014-11-18 07:49:49
您可以使用自然连接连接2个或更多表。查询应该如下所示:
SELECT * FROM userdatafiles JOIN table1 ON userdatafiles.id = table1.id WHERE Specialisation = "Drawing"结果将是一个新的表,如下例所示:
table1: id _
table2: id :城市/国家
结果: id _ name _
您可以使用这样的数据:
$result = mysql_query("Your Query");
while($row = mysql_fetch_object($result)){
//Access values with $row->ColumnName
}https://stackoverflow.com/questions/26989032
复制相似问题