dsartain Posted February 10, 2007 Share Posted February 10, 2007 Is this the correct syntax?? I've never done one of these before....I'm trying to dynamically display images...work on making it pretty later... $dbconn=mysql_connect($hostname, $user, $password); mysql_select_db($dbname, $dbconn); $sql="SELECT * FROM `thumbnail_table`"; $runquery=mysql_query($sql); $result=mysql_fetch_array($runquery); echo mysql_error(); foreach($result) { '<img src="'.$result['pic_link'].'" /> <br />'; } Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 10, 2007 Share Posted February 10, 2007 http://us2.php.net/foreach The only two valid syntax are listed. foreach($result AS $k=>$v){ '<img src="'.$v['pic_link'].'" /> <br />'; //This line isn't valid code either. } Quote Link to comment Share on other sites More sharing options...
dsartain Posted February 10, 2007 Author Share Posted February 10, 2007 How is it not valid? Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 10, 2007 Share Posted February 10, 2007 It doesn't do anything, it's just a string. You don't put the string in a variable or print it out. Quote Link to comment Share on other sites More sharing options...
dsartain Posted February 10, 2007 Author Share Posted February 10, 2007 Yeah, I saw that just before you mentioned it...I put the echo tag in there....but all I get are red X boxes.... To test it I did: foreach($result as $k=>$v) { echo $v['pic_link']."<br />"; // echo '<img src="'.$v['pic_link'].'" /> '; //This line isn't valid code either. } but the pic_link field in the table gives me a full URL for each one....what am I missing?? The output was... 1 1 1 1 h h Entire code as is now: <?php //vars for $dbconn omitted $dbconn=mysql_connect($hostname, $user, $password); mysql_select_db($dbname, $dbconn); echo mysql_error(); if (!$dbconn) { echo "Could Not Connect to DB!"; } $sql="SELECT * FROM `thumbnail_table`"; $runquery=mysql_query($sql); $result=mysql_fetch_array($runquery); foreach($result as $k=>$v) { echo $v['pic_link']."<br />"; // echo '<img src="'.$v['pic_link'].'" /> '; //This line isn't valid code either. } /* foreach($result as $value) { '<img src="'.$result['pic_link'].'" /> <br />'; } */ ?> Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 10, 2007 Share Posted February 10, 2007 1 is not a full image url. It's a number... Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted February 10, 2007 Share Posted February 10, 2007 What value is stored in the field pic_link? Quote Link to comment Share on other sites More sharing options...
calabiyau Posted February 10, 2007 Share Posted February 10, 2007 Yeah i've never used a foreach before but do you have php myadmin or something to check the values stored in the database? Maybe something went wrong on the input end of things and those values are actually what's stored in the database Quote Link to comment Share on other sites More sharing options...
The_Assistant Posted February 10, 2007 Share Posted February 10, 2007 Try this: for($i=0;$i<mysql_num_rows($runquery);$i++) { echo '<img src="'.mysql_resul($runquery,$i,'pic_link').'" />'; } Quote Link to comment Share on other sites More sharing options...
dsartain Posted February 10, 2007 Author Share Posted February 10, 2007 I wound up using a while loop where while ($result = mysql_fetch_array($runquery) and $result2 = mysql_fetch_array($runquery2)) yes...I added another array... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.