php - Warning: Illegal string offset -
i new oop , have image displaying when had single array query (requesting image url only) when added sec dimension query array (image id in table) ended getting warning message 'warning: illegal string offset'. have used mysqli_fetch_assoc in database class , running result through foreach loop.
this message getting.
thanks in advance help given.
page code
$user = $_session['user_name']; $query = "select gallery_image, 'gallery_id' gallery user_name = '$user' order gallery_id desc"; $result = $obj_db->get_gallery($query); foreach ($result $image ) { foreach ($image $key => $value) { echo '<div class="gallery_item"><a href="proof.php?image='.$value['gallery_id'].'"><img src="'.$value['gallery_image'].'"></a></div>'; } }
database class code
function get_gallery($sql){ $obj_res = mysqli_query($this->obj_db_conn, $sql); if(mysqli_errno($this->obj_db_conn)){ die ("failed query: $strsql".$this->obj_db_conn->error); } $arresults = array(); while($arrow = mysqli_fetch_assoc($obj_res)){ $arresults[] = $arrow; } homecoming $arresults;
if var_dump
output on $result
give this,
array(2) { [0]=> array(2) { ["gallery_image"]=> "" ["gallery_id"]=> "" } [1]=> array(2) { ["gallery_image"]=> "" ["gallery_id"]=> "" } }
you don't need 2 nested foreach
loops in page code. 1 foreach
loop enough.
$query = "select gallery_image, gallery_id gallery user_name = '$user' order gallery_id desc"; $result = $obj_db->get_gallery($query); foreach ($result $image ) { echo '<div class="gallery_item"><a href="proof.php?image='.$image['gallery_id'].'"><img src="'.$image['gallery_image'].'"></a></div>'; }
php arrays string oop warnings
No comments:
Post a Comment