So this code should call a the name of a photo out of a database. then put it into an array then open the photos with the names in the array. the problem is that it only calls the first row twice. any ideas on how to fix this cause i'm stumped. the code is function display_photos () { $valid_user = $_SESSION['valid_user']; mysql_connect("-------","-------","----"); mysql_select_db("-----") or die("Unable to select database"); $conn = db_connect(); $result = mysql_query("select photo from photo where email='".$valid_user."' "); $a = mysql_fetch_array($result) or die("No photos holmes"); ?> <table> <?php foreach($a as $b) { echo "$b"; ?> <tr><td> <img src="images/<?php echo $b; ?>" alt="<?php echo $b; ?>" /> </td></tr> <?php } ?> </table> <?php } ?> anyway, any help would well... help. tanks
well i looked over the search engine problem and it actually just returns double of all values in a database.
Use this: <?php function display_photos () { $valid_user = mysql_escape_string($_SESSION['valid_user']); mysql_connect("-------","-------","----"); mysql_select_db("-----") or die("Unable to select database"); $conn = db_connect(); $result = mysql_query("select photo from photo where email='".$valid_user."' "); ?> <table> <?php while($row = mysql_fetch_row($result)) { ?> <tr><td> <img src="images/<?php echo $row[0]; ?>" alt="<?php echo $row[0]; ?>" /> </td></tr> <?php } ?> </table> } ?> PHP:
that did it. Thanks man. did the mysql escape string fix that or the while? i was thinking that could patch up my search problem.
The problem was something to do with the for each part I think, might have not been returning the values as you expected. I always keep my php like that, just seems simple to me. I added the escape for security