0

I have tried everything I can find to try and get time formatted results from my table using mysql_fetch_array while also getting other results.

This is my code:

<?php
    
        $con = new mysqli("mysql.hostinger.co.uk", "user", "password", "database");
        $con->set_charset('utf8mb4');

    //Retrieve all the data from the Update Log Table
        $result = $con->query("SELECT requestID, songTitle, artistName, requester, dedicatedTo, TIME_FORMAT(requestTime, '%r'), dance FROM `table` ORDER BY requestID DESC") or die(mysql_error());

        echo "<form class='formleft'>";
    
        //keeps getting the next row until there are no more to get
        while($row = mysqli_fetch_array($result)){
            //Print out the contents of each row into a table
                echo "<div class='reqgap'></div>";
                echo "<input type='checkbox' id='play";
                echo $row['requestID'];
                echo "' class='play checkbox' autocomplete='off' ";
                if ($row['requestID'] == '0') {
                    echo "style='display:none;' />";
                } else {
                    echo "/>";
                };
            echo "<label class='played' for='play";
                echo $row['requestID'];
                echo "' ";
                if ($row['requestID'] == '0') {
                    echo "hidden >";
                } else {
                    echo ">";
                };
                echo "Played";
            echo "</label>";
            echo "<article class='request songs req";
                echo $row['requestID'];
                if ($row['requestID'] % 2 == 0) {
                    echo " even";
                } else {
                    echo " odd";
                };
                echo "' >";
                echo "<article class='requestleft'>";
                    echo "<article class='requestnum'>";
                        echo "<p class='requestnumt'>";
                            if ($row['requestID'] == '') {
                                echo "RequestID Error";
                            } else {
                                echo $row['requestID'];
                            }
                        echo "</p>";
                    echo"</article>";
                    echo "<article class='requesttime'>";
                        echo "<p class='requesttimet'>";
                            if ($row['requestTime'] == '') {
                                echo "Request Time Error";
                            } else {
                                echo $row['requestTime'];
                            }
                        echo " UTC</p>";
                    echo"</article>";

It just shows my error message "Request Time Error" when it comes to displaying that data. Any assistance will be greatly appreciated

Dharman
  • 30,962
  • 25
  • 85
  • 135
  • 2
    Try `TIME_FORMAT(requestTime, '%r') AS requestTime` – Phil Jul 25 '21 at 03:22
  • 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 Jul 25 '21 at 10:25
  • @Phil Thanks, This time it actually worked. I have tried using something like that before but for some reason it decided to work this time :) – Kiddabob Stamp Jul 26 '21 at 04:07

0 Answers0