Saturday, 8 July 2017

PHP array is not getting the data from mysqli query but the query works in PHPmyadmin




I am trying to show the result of my query but I am not getting any output from the php. I have tried several different loops but I cannot get anything to show on the page. The query works in PHPmyadmin and there are no errors showing when the webpage loads. This is the code. Let me know if you need any more information. I did print_r($data) and got this result :



mysqli_result Object ( [current_field] => 0 [field_count] => 8 [lengths] => [num_rows] => 2 [type] => 0 ) 2



$select = "SELECT u.`info_id`, u.`info`, u.`removed`, m.`date_added`, m.`title`, m.`summary`, m.`poster`, m.`imdb`, m.`cv` ".
"FROM `user_movies` AS u ".
"INNER JOIN `movies` AS m ".
"USING (`movie_id`) ".
"WHERE u.`user_id` = '{$_SESSION['user_id']}' ".

"AND u.`info` = '0' AND u.`removed` = '0' ".
"ORDER BY m.`date_added` DESC, m.`movie_id` ASC";
$data = mysqli_query($connect, $select) or die ('error getting user movies');
$movies = array();
while ($movie = mysqli_fetch_array($data));
{
array_push($movies, $movie);
}

foreach ($movies as $movie)

{
$id = str_replace(' ', '', $movie['title']);
$poster = $movie['poster'];
$title = $movie['title'];
$summary = $movie['summary'];
$imdb = $movie['imdb'];

echo "
$title" .
"

$title
$summary
" .
"More info at IMDb

";

}

Answer



The while loop had a semi colon at the end of it stopping the array_push from doing its job



while ($movie = mysqli_fetch_array($data));


should just be




while ($movie = mysqli_fetch_array($data))

No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...