Reputation: 5177
I want to load the data from mysql
database connection: (database_cnn.php)
Edited:
include 'database_cnn';
$query= "select * from all_songs";
$res= mysql_query($query);
$result= array();
while ($row = mysql_fatch_array($res))
array_push($result , array( 'id' => row[0],
'title' => row[1],
'artist' => row[2] ,
'album' =>row[3],
'lyric' =>row[4]
)
);
echo json_encode(array( "result" => $result));
?>
the error I get:
Parse error: syntax error, unexpected '[', expecting ')' in D:\xampp\htdocs\abc\IPA_3rd\database_out.php on line 13
can anyone tell me why am I getting this error? Is there something wrong with my code?
Upvotes: 0
Views: 108
Reputation: 32820
Change include 'database_cnn';
to include 'database_cnn.php';
// missing extension
It is mysql_fetch_array
NOT mysql_fatch_array
Also use mysql_fetch_assoc
instead of it
You forgot to put '$' for row variable
array_push($result , array( 'id' => row[0],
'title' => row[1],
'artist' => row[2] ,
'album' =>row[3],
'lyric' =>row[4]
)
);
I suggest you to go through the php tutorials first.
Upvotes: 2
Reputation: 1360
If you have time, it would be a good idea to learn to use PDO instead of Mysql who is decrepated.
He is a link to the Doc
Upvotes: 0
Reputation: 917
use $row instead of row
while ($row = mysql_fetch_array($res))
array_push($result , array( 'id' => $row[0],
'title' => $row[1],
'artist' => $row[2] ,
'album' =>$row[3],
'lyric' =>$row[4]
)
);`
Upvotes: 1
Reputation: 1763
array_push($result , array( 'id' => row[0],
'title' => row[1],
'artist' => row[2] ,
'album' =>row[3],
'lyric' =>row[4]
)
should be
array_push($result , array( 'id' => $row[0],
'title' => $row[1],
'artist' => $row[2] ,
'album' => $row[3],
'lyric' => $row[4]
)
and mysql_fatch_array
should be mysql_fetch_array
and
$con = mysqli_connect("localhost", "root", "");
if (mysqli_connect_errno()){
echo "Failed to connect to MySQL: " . mysqli_connect_error();
should be
$con = mysql_connect("localhost", "root", "");
if (mysql_connect_errno()){
echo "Failed to connect to MySQL: " . mysql_connect_error();
Upvotes: 1