mysql - PHP How to filter array values -
i'm trying show in div 3 thumbnails stored in different folders.
in bd determined (with value "1") record has pictures. db:
+------+----------------+---------+--------+--------+ | 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 | +------+----------------+---------+--------+--------+
selecting records:
$result = mysqli_query($connecdb,"select * brands php = '1' or ruby = '1' or java = '1' order id asc"); while($row = mysqli_fetch_assoc($result)){ $new_array[] = $row; }
but problem is: how can select values "1" , how know which?
maybe use: $row['php'] $row['java'] $row['ruby']
how filter values "0"?
it looks want break array php, java, , ruby. below not tested, give idea.
$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']; } }
then loop through 2d array, grabbing name key in resultsarray.
foreach($resultsarray $language => $array) { foreach($array $id) { echo "url/".$language."/".$id; echo "<br>"; } }
Comments
Post a Comment