简体   繁体   中英

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}"; 
?> 

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM