0

Hello! I'm trying to do a query from SQL in PHP table. My code is:

<?php 
$table = mysqli_query($mysqli,"SELECT  song_id, song_name, janr_name,  singers.names FROM `songs` INNER JOIN `singers` ON songs.singer_id = singers.singer_id
    INNER JOIN `janr_songs` WHERE janr_songs.janr_id = songs.janr_id ");
    $row = mysqli_fetch_array($table); 
    {   
        echo "<table border='1' >";  
        echo "<tr><th>№</th><th>Song</th><th>Artist</th><th>Song genre</th><th>Likes</th><th>Dislikes</th><th>LIKED</th><th>DISLIKED</th></tr>";  

     // echo '<pre>' . print_r($row, true) . '</pre>';
    while($row = mysqli_fetch_array($table))
    {
?>
    <tr>
    <th>
    <?php echo $row['song_id']; ?>
    </th>
    <th>
    <?php echo $row['song_name']; ?>
    </th>
    <th>
    <?php echo $row['names']; ?>
    </th>
    <th>
    <?php echo $row['janr_name']; ?>
    </th>
    <th>
    <?php echo $row[($query = mysqli_query($mysqli,"SELECT SUM(`likes`) FROM `voting` WHERE `song_id`='".$_POST['song_id']."'"))]; ?>
    </th>
    <th>

I can't make likes and dislikes from Database to be shown in the table row.
I try with that code, but there is a warning: Warning: Illegal offset type in...

<?php echo $row['janr_name']; ?>
</th>
<th>
<?php echo $row[($query = mysqli_query($mysqli,"SELECT SUM(`likes`) FROM `voting` WHERE `song_id`='".$_POST['song_id']."'"))]; ?>
</th>
<th>

What's wrong in this query? :)

2
Contributors
3
Replies
21
Views
2 Years
Discussion Span
Last Post by iveto89
0

My code is:

<?php
$table = mysqli_query($mysqli,"SELECT  songs.song_id, song_name, janr_name, singers.names, v.likes, v.dislikes FROM `songs` 
    INNER JOIN `singers` ON songs.singer_id = singers.singer_id
    INNER JOIN `janr_songs` ON janr_songs.janr_id = songs.janr_id
    LEFT JOIN (SELECT song_id, SUM(`likes`) AS likes,  SUM(`dislikes`) AS dislikes
            FROM `voting` 
            GROUP BY song_id) AS v
    ON songs.song_id = v.song_id");

    $row = mysqli_fetch_array($table); 
    {   
        echo "<table border='1' >";  
        echo "<tr><th>№</th><th>Song</th><th>Artist</th><th>Song genre</th><th>Likes</th><th>Dislikes</th></tr>";  


    while($row = mysqli_fetch_array($table))
    {
?>
    <tr>
    <th>
    <?php echo $row['song_id']; ?>
    </th>
    <th>
    <?php echo $row['song_name']; ?>
    </th>
    <th>
    <?php echo $row['names']; ?>
    </th>
    <th>
    <?php echo $row['janr_name']; ?>
    </th>
    <th>
    <?php echo $row['likes']; ?>
    </th>
    <th>
    <?php echo $row['dislikes']; ?>
    </th>

But I also have to make 2 more tables (similar to that) in which there should be shown sum likes/dislikes for every song, which definite user (every user when he logs in his profile) has liked/disliked.
So, it should be as that table with that difference that only those songs that are liked have to be seen (with the full count of likes, not only these of that user). That's my problem at the moment.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.