Answer the question
In order to leave comments, you need to log in
How to output multiple variables from the database if it is greater than 1 (in one code)?
Didn't know how to ask the question. The bottom line is this:
There are several cells in the database: art_1, art_2, art_3. The folder contains pictures with the corresponding names (art_1, etc.).
It is necessary to display a picture if the value is greater than 1, if 0 do not display. Well, this is easy to do, what is the best way to do it so as not to write code for each picture?
Tried like this:
$db->Query("SELECT * FROM db_users_art WHERE id = '$usid' LIMIT 1");
$art = $db->FetchArray();
$art_name = $art_name + 1;
$art1 = $art["art_".$art_name];
if ($art1 >= 1) {
echo '<img src="/img/art/art_'.$art_name.'.gif">';
}else echo 'Пусто';
Answer the question
In order to leave comments, you need to log in
I decided like this, completely forgot about the cycles :)
$db->Query("SELECT * FROM db_users_art WHERE id = '$usid' LIMIT 1");
$art = $db->FetchArray();
for ($i = 1; $i <= 3; $i++) {
if ($art["art_".$i] >= 1) {
echo '<img src="/img/art/art_'.$i.'.gif">';
}
}
You need to do a loop and go through the pictures in the loop. Then you check each element of the picture for a value, whether it is greater than zero or not, if the value is 0, then we do a break; if the value is not equal to 0, then we display the picture.
$set = 0;
while ($art = mysqli_fetch_array() {
foreach ($art as $image) {
if ($set == 0){
break;
}
else {
echo'<img src ="/img/art/art_' . $image . 'gif>';
}
}
}
Вот как то так.
It's not clear, you have a lot of pictures and need to display them? - Cycle.
Well, you can also shorten the condition like this ;)
if ($art1) echo '<img src="/img/art/art_',$art_name,'.gif">'; else echo 'Пусто';
echo $art ? '<img src="/img/art/art_',$art_name,'.gif">' : 'Пусто';
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question