4
I need to generate a variable with arbitrary name. I have the following code, which does not work:
$vv = mysql_query("SELECT * FROM $tabela ORDER BY rand() LIMIT 3");
$i=1;
while($v = mysql_fetch_array($vv)){
$vertical.$i=$v['arquivo'];
$i++;
}
echo'
<img src="img/fotos/'.$vertical1.'"> <br>
<img src="img/fotos/'.$vertical2.'"> <br>
<img src="img/fotos/'.$vertical3.'">
';
I would like the query to return me 3 variables: $vertical1
, $vertical2
and $vertical3
Note: In the database the field 'file' has the 'format' included. Ex.: photo.jpg
Note 2: I believe the problem is in the concatenation $vertical.$i
...
It would be better to move echo inside the WHILE and use the variable that is already passed, what do you think?
– RFL
The code I posted is a short version of the page. In the real case it would not be ideal due to the position of the <img>, which are in various places. Then I would have to do several "query", besides running the risk of listing 2 times the same img.
– Leonel Junior