-1

Hello I am making a highscore webpage with tables. I've gotten two working so far and my last one is giving me trouble. The data is the time played and it is being stored in seconds. This is my query

Stuff I tried

    <?php if( isset($this->attr['totaltime'])) { ?>
        <td><?php echo $row['totaltime']; ?></td>

<?php   } ?>

I've tried a few different variations of this but none has worked for me. I believe it's my lack of knowledge and nothing else. I am 90% i need to add an isset in there to perform a check but I just dont know how the isset works and all the examples I found are extremely complicated.. Like this one.

$o = [];
@$var = ["",0,null,1,2,3,$foo,$o['myIndex']];
array_walk($var, function($v) {
    echo (!isset($v) || $v == false) ? 'true ' : 'false';
    echo ' ' . (empty($v) ? 'true' : 'false');
    echo "\n";
});
REDRUM
  • 9
  • 6
  • please dont edit your question like that, thats not how this site works –  May 05 '19 at 21:50

2 Answers2

3

Your second database column doesn't have a name, it's just the anonymous result of the Floor function.

You should use an alias for the column, e.g.

SELECT utime.playername, FLOOR(utime.totaltime / 3600) as totaltime FROM utime.utime ORDER BY utime.totaltime DESC LIMIT 10

This will then match the index name you're using to refer to it in the PHP

ADyson
  • 57,178
  • 14
  • 51
  • 63
0

There is some debugging that I can suggest. mysqli_fetch_assoc() returns the row as an associative array. And PHP provides a way to loop through an associative array that is the foreach loop. What you can do is inside the body of the while loop, add the foreach loop

while ($row = mysqli_fetch_assoc($utimer)) {
              for ($row as $key -> $value){
                     echo "<br>Key: ". $key . " Value: ". $value
               }
  }

Remove the rest of the body of the while loop and let me know what did you get. The $key will contain the field name i.e. totaltime and playername and $value the data for that row. Let me know what you get. Hope this helps!

Amal K
  • 4,359
  • 2
  • 22
  • 44
  • 1
    This debugging advice, which is helpful in comments, but it's not an actual solution to the problem – ADyson May 06 '19 at 15:51