0

I am trying to combine 2 tables of data. However, all of my results were getting stuck in one set of results. I need the results to go across multiple. Someone posted a reply to that post with a code snippet and said some stuff that I didn't quite understand. I have now managed to figure out one of the errors that his code had (he used a different variable for the SQL connection) and I am now stuck with this error: Here is what Is happening: What is Happening

<?php
$con = new mysqli("-", "-", "-", "-");            
$con->set_charset('utf8mb4');
    
//Retrieve all the data from the Update Log Table
$result = $con->query("SELECT StreamDayID, WeekColor, DayName, StreamTitle, StreamGame, TIME_FORMAT(StartTime, '%r') AS StartTime, DATE_FORMAT(StreamDate, '%D %b') AS StreamDate FROM `WeekData` WHERE WeekColor='Blue'") or die(mysql_error());

//Retrieve all the data from the Update Log Table
//$joinresult = $con->query("SELECT JoinID, JoinedBy, StreamID FROM `JoinedBy` INNER JOIN `WeekData` ON StreamID = StreamDayID") or die(mysql_error());

echo "<div id='blue' class='day'>";
echo "<h1 class='row'>Blue:</h1>";
    
//keeps getting the next row until there are no more to get
while($row = mysqli_fetch_array($result)){
    $joinresult = $con->stmt_init();

    $joinresult->prepare("SELECT JoinID, JoinedBy, StreamID FROM `JoinedBy` WHERE StreamID = ?");
    // if `StreamDayID` is an integer, change "s" -> "i"
    $joinresult->bind_param("s", $row['StreamDayID']);

    $exec = $joinresult->execute();
    if(!$exec){
    // error
    die(mysql_error());
    }

    //Print out the contents of each row into a table
        echo "<div id='blue";
        echo $row['StreamDayID'];
        echo "' class='les'>";
            echo "<div class='title'>";
                echo "<h2>";
                echo $row['StreamTitle'];
                echo "</h2>";
            echo "</div>";
            echo "<div class='detail'>";
                echo "<h4>Day: ";
                echo $row['DayName'];
                echo "</h4>";
                echo "<h4>Game: ";
                echo $row['StreamGame'];
                echo "</h4>";
                echo "<h4 class='joiners'>Joined By:";
                while($join = mysqli_fetch_array($joinresult)){
                    echo "<a class='delink' href='https://twitch.tv/";
                    echo $join['JoinedBy'];
                    echo "'>";
                    echo $join['JoinedBy'];
                    echo "</a>";
                };
                echo "</h4>";
                echo "<h4>Start Time: ";
                echo $row['StartTime'];
                echo "</h4>";
                echo "<h4>Stream Date: ";
                echo $row['StreamDate'];
                echo "</h4>";
            echo "</div>";
        echo "</div>";
};

?>

Here is What I want to happen: What I want it to do

  • [Mysqli tutorial (how to use it properly)](https://phpdelusions.net/mysqli) – Your Common Sense Aug 14 '22 at 08:12
  • @YourCommonSense FYI - I am getting very very slow to actual timeouts on the link provided in your comment. I think the hamsters need feeding. – TimBrownlaw Aug 14 '22 at 10:27
  • You have an error. [`mysql_error()`](https://www.php.net/manual/en/function.mysql-error.php) worked only for the old API. Please consider switching error mode on instead. [How to get the error message in MySQLi?](https://stackoverflow.com/a/22662582/1839439) – Dharman Aug 14 '22 at 11:03

0 Answers0