gentlebreeze gentlebreeze - 7 months ago 16
PHP Question

Display all rows from Mysql table

I have a database "media" with table "video"

CREATE TABLE IF NOT EXISTS `video` (
`id` int(12) NOT NULL AUTO_INCREMENT,
`title` varchar(25) NOT NULL,
`link` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;


table video contains 3 fields:
id,
title,
link
(contains iframe and link to video).

I want to display all of the videos in the mysql table, but only the first video s being displayed.

<?php
$con=mysqli_connect("localhost","user","password","database");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$result = mysqli_query($con,"SELECT * FROM video");

while($row = mysqli_fetch_array($result))
{
$id = $row["id"];
$videoiframe = $row["link"];
}
echo "{$videoiframe}";
?>

Answer

Loop override the value of id and videoiframe. You need to define an array and store value in it as

$array=array();// define array

    while( $row = mysqli_fetch_array($result)){
        $array[] = $row; // Inside while loop
    }
print_r($array);// get all value

Updated

while($row = mysqli_fetch_array($result))
  {
  $user.=$row['link']."</br>";
  }
echo $user;