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

I made it :)

plz share ur solution ..

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.