$selectra_result = mysql_query("SELECT * FROM `my_selectra` WHERE user_id='$user_id'") or die(mysql_error());
while($row = mysql_fetch_array( $selectra_result )) {
$product_id = $row['product_id'];
$namep[] = $product_name= $row['product_name'];
$linkp[] = $product_permalink = $row['product_permalink'];
$imgpp[] = $product_image_path = $row['product_image_path'];
}
foreach($namep as $pname => $prodname){
foreach($linkp as $plink => $prodlink) {
foreach($imgpp as $ppath => $prodpath) {
$res1 = "<a href='$prodlink'><p>$prodname</p></a>";
$res2 = "<a href='$prodlink'><img src='$prodpath'/>";
}
}
}
echo $res2.''.$res1;
}
I want to display data from my_selectra table using foreach, unfortunately it appears only one data when echo.
Your code is pretty convoluted… You don’t need 3 arrays to grab the data you want, nor do you need a triple-nested foreach loop structure. Try something like this: