I am currently running a MySQL query to return song titles from a database. Each song title returned displays on a different line when I echo
the results. I would like to return the song titles as an array and then echo
that array.
Example output: songTitle1 songTitle2 songTitle3
What I am looking for: Array ([1] => songTitle1 [2] => songTitle2) and so on
Thanks.
Here is my PHP script:
<?php
$varusername = $_POST['username'];
//connection string
$connection=mysqli_connect(<server_details>);
//check connection
if(!$connection)
{die("Failed to connect to MySql:".mysqli_connect_error());}
else
$query = "SELECT Title FROM songs WHERE Uusername='$varusername'";
$result = $connection->query($query);
if ($result->num_rows > 0){
while($row = $result->fetch_assoc()){
echo $row["Title"]. "<br>";
}
}
else
{die('SQL Error:'.mysqli_error($connection));}
mysqli_close($connection);
?>