mysql - PHP show values of associative array when one of the values equals a specified value -


i have mysql recordset have put associative array can reuse on , over.

i used function put values array:

while(($comments[] = mysql_fetch_assoc($rscomments)) || array_pop($comments)); 

here print_r($comments) displays

array ( [0] => array ( [commentid] => 10 [comment] => ouch [commentauthor] => randy krohn [commentdate] => 2010-10-06 17:19:49 [id] => 1231 [categoryid] => 42 ) [1] => array ( [commentid] => 12 [comment] => dirty duck [commentauthor] => john lemoine [commentdate] => 2010-10-06 17:22:43 [id] => 1411 [categoryid] => 42 ) [2] => array ( [commentid] => 13 [comment] => talk deja vu! [commentauthor] => dber [commentdate] => 2010-10-06 17:24:48 [id] => 1473 [categoryid] => 42 ) ) 

i looping through list of images, , want display comments associated images specified imageid (for example 1473).

i need display ones id equal specified value?

this must easy, reason, flying on head.

thanks help!

simplest way loop through 'comments' associative array (aka dictionary) foreach , check value of 'id' key, if matches desired value, print value of 'comment' key:

$imageid = 1473; foreach($comments $comment) {     if($comment['id'] == $imageid) {         echo $comment['comment'];     } } 

Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -