0
$query = mysql_query("SELECT hour, team1, team2, goalsteam1, goalsteam2, competition FROM `matches` WHERE `date`='". $daterow['date'] ."'");
while($row = mysql_fetch_array($query)){    

    $hour = substr($row['hour'],0,5);

    $teamemblem = mysql_query("SELECT emblem FROM `teams` WHERE `team`='".$row['team1']."'");
    $teamemblemrow = mysql_fetch_assoc($teamemblem);

    echo '
        <tr class="teamtable">
            <td style="width:60px; font-size:11px;">'.$hour.'</td>
            <td style="width:145px; font-size:11px;"><img width=24px height=24px src='.$teamemblemrow['teamemblem'].'/></td>
            <td style="width:15px; font-size:11px;">'.$row['goalsteam1'].'</td>
            <td style="width:15px; font-size:11px;">'.$row['goalsteam2'].'</td>
            <td style="width:145px; font-size:11px;">'.$row['team2'].'</td>
            <td style="width:120; font-size:11px;">'.$row['competition'].'</td>
        </tr>'; 
}

I tried everything, but the emblem part won't work. It refuses to read from the database. Thing is printing $row['team1'] works, but I don't get why it just won't read..

Any help?

hydravink
  • 63
  • 1
  • 1
  • 11
  • PS The problem is that the emblem `` doesn't display because `$teamemblemrow['teamemblem']` is empty for some reason – hydravink May 18 '14 at 01:36
  • Your select asks for `emblem`, so it probably needs to be `$teamemblemrow['emblem']` not `$teamemblemrow['teamemblem']` – Mark Miller May 18 '14 at 01:37
  • +1 for using in-line style and mysql_* extension in the year 2014 – CodeZombie May 18 '14 at 01:42
  • ZombieHunter idgaf really about what you say about my style lol – hydravink May 18 '14 at 01:55
  • Just a suggestion for the future: if you have a seemingly simple problem, try using the function `var_dump()` or `print_r()` on the problematic variable and see what you come up with. Not that your questions aren't welcome, but it likely would have saved you a good deal of time not having to post a question and wait for replies. You mentioned below that you are still new to PHP, so obviously I'm not faulting you. Just providing a tip for the future. – Noah Heck May 18 '14 at 03:23

1 Answers1

1

In your query you do the select as :

SELECT emblem FROM `teams` WHERE...

But in your code you refer to it after as:

$teamemblemrow['teamemblem']

Which is it? emblem or teamemblem?

When you return an assoc array, you need to make sure that you refer to the elements by the same name. If you want to use a different name, you can modify your query to bring the field back as a different name like this:

SELECT emblem as teamemblem FROM `teams` WHERE...

Which then means you can refer to the assoc array returned via what y ou have in your code at the moment.

Edit: Additionally, you are using old mysql_* functions. You really should have a read of this question and upgrade your code to much better functions.

Community
  • 1
  • 1
Fluffeh
  • 33,228
  • 16
  • 67
  • 80
  • omg! What a noob mistake.. Thanks a lot! This fixed, I had to put emblem not teamemblem. Well not scripting for 1 month does this. Thanks a lot. Going to accept your answer in 8 mins – hydravink May 18 '14 at 01:41
  • @hydravink That's okay, we all miss these things sometime and a fresh set of eyes can sometimes spot them in seconds :) – Fluffeh May 18 '14 at 01:42
  • _“Well not scripting for 1 month does this”_ – no, not having proper error_reporting enabled does this – so __do that now!__ – CBroe May 18 '14 at 02:10