0

我试图在存储在不同文件夹中的 div 3 缩略图中显示。
在我的 bd 中确定(值为“1”)哪个记录有图片。所以这是我的数据库:

+------+----------------+---------+--------+--------+
| ID   | BRAND          |   PHP   |  RUBY  |  JAVA  |
+------+----------------+---------+--------+--------+
| 1    | ford           |    1    |    0   |    0   |
+------+----------------+---------+--------+--------+
| 2    | seat           |    1    |    1   |    1   |
+------+----------------+---------+--------+--------+
| 3    | fiat           |    1    |    1   |    0   |
+------+----------------+---------+--------+--------+
| 4    | toyota         |    1    |    0   |    0   |
+------+----------------+---------+--------+--------+
| 5    | vw             |    1    |    0   |    1   |
+------+----------------+---------+--------+--------+

选择记录:

$result = mysqli_query($connecDB,"SELECT * FROM brands WHERE php = '1' OR ruby = '1' OR java = '1' ORDER BY id ASC");


while($row = mysqli_fetch_assoc($result)){
    $new_array[] = $row;
}

但我的问题是:我如何选择值“1”以及如何知道哪个是哪个?
也许我可以使用:$row['php'] $row['java'] $row['ruby']但是如何过滤值“0”?

4

2 回答 2

1

看起来您想将数组分解为 php、java 和 ruby​​。下面没有测试,只是给你一个想法。

$resultsArray = array();
while($row = mysqli_fetch_assoc($result)){
    if($row['php'] == 1) {
        $resultsArray['php'][] = $row['id'];
    }
    if($row['java'] == 1) {
        $resultsArray['java'][] = $row['id'];
    }
    if($row['ruby'] == 1) {
        $resultsArray['ruby'][] = $row['id'];
    }
}

然后遍历该二维数组,从 resultsArray 中的键中获取名称。

foreach($resultsArray as $language => $array) {
    foreach($array as $id) {
        echo "url/".$language."/".$id;
        echo "<br>";
    }
}
于 2013-08-19T19:51:34.247 回答
0
foreach($resultsArray as $language => $array){
    foreach(array_slice(glob('work/'.$language.'/'.$rowtest['id'].'/*.jpg'),0,1) as $image){    
        echo $image . "<br />";
    }
}
于 2013-08-20T18:28:53.537 回答