Reputation: 31
I am trying to print the all of the contents in column1 (Filename)
in mysql
database, however, only the first row is being printed. I believe this is solved by using while loop
in order to print the whole contents in that column. However I cannot get it to work.
I have tried:
while($row = mysql_fetch_array($result))
but it didn't work
This is the script that works but only prints the top row:
<?php
$servername = "localhost";
$user = "xxxx";
$password = "xxxx";
$dbname = "123";
// Create connection
$conn = mysqli_connect($servername, $user, $password, $dbname);
if (!$conn)
{
die("Connection failed: " . mysqli_connect_error());
}
$query = "SELECT Filename FROM Test";
$result = mysqli_query($conn, $query);
$row = mysqli_fetch_array($result);
$Filename[] = $row['Filename'];
echo $row['Filename'];
mysqli_close($conn);
?>
Upvotes: 1
Views: 196
Reputation: 552
Use this:
while($row = mysqli_fetch_array($result))
{
$Filename[] = $row['Filename'];
}
Upvotes: 1
Reputation: 2447
you were not using while loop in proper way try this & use the data wherever you want
while($row = mysqli_fetch_array($result))
{
//$Filename[] = $row['Filename'];
//echo $row['Filename']."<br/>";
echo $row[0];
}
Upvotes: 2