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

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

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

java - Cannot secure connection using TLS -