php - combine two foreach statements( image& text) -


i'm using "foreach" statement fetch images folder print on webpage.

i need give 'links' these images.

links saved in database table called 'advertisement'.

i fetched images , displayed correctly.

but can't make these images links.

i used "foreach" statement fetch 'link' rows table 'advertisement' table.

but how combine these two.

here example of how it:

$files = array('1.jpg','2.jpg'); $stm = $pdo->query('select * advertisement'); $linkinfo = $stm->fetchall(pdo::fetch_assoc); $outputarray = array(); foreach( $linkinfo $row ) {     if( in_array($row['file'], $files) )     {         $outputarray['file'] = $row['link'];     } }  foreach( $outputarray $file => $link ) {     echo "<a href='".$link."'><img src='". $file ."'></a>"; } 

not sure how structure is, have table this:

------------------------------ | file        | link         | ------------------------------ | 1.jpg       | http://...   | + + + 

this should work, adjustment according own structure.


Comments

Popular posts from this blog

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - UML - How would you draw a try catch in a sequence diagram? -

c++ - No viable overloaded operator for references a map -