1

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);
?>

2 Answers 2

2

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];
}
Sign up to request clarification or add additional context in comments.

Comments

1

Use this:

while($row = mysqli_fetch_array($result))
{
     $Filename[] = $row['Filename'];
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.