roli roli roli roli - 4 months ago 9
PHP Question

Print multiple array values


I have the below code


$student_IT_vitipare = mysql_query("SELECT * from notat where dega='teknologji informacioni' AND viti_lendes='viti pare' ");
$vekt_stud_IT_vitipare = array();
while ($kolo1 = mysql_fetch_array($student_IT_vitipare)) {
$vekt_stud_IT_vitipare[] = $kolo1;
}
$gjatesia_vektorit = count($vekt_stud_IT_vitipare);



EXAMPLE: Array take from database name,last name and it has {john,trevis}{george,trolus} {dionis,karrblus} etc...
I know that if i want to echo out only name the code is :


for($i=0;i<$gjatesia_vektorit;i++){
echo $vekt_stud_IT_vitipare[$i]['name'];
}



i've tryed $vekt_stud_IT_vitipare[$i]['name']['last name']; but it does not work

Answer

you should stop using mysql_* because it's removed on php 7.0 instead use mysqli_* or PDO

your code won't work but instead if you do something like

for($i=0;i<$gjatesia_vektorit;i++){
echo $vekt_stud_IT_vitipare[$i][$i];
 }

it would but you will only one value

instead you need a nested foreach loop

foreach($vekt_stud_IT_vitipare as $key => $value) {
        foreach ($value as $val) {              
       echo $val;
    }
}