tags:

views:

25

answers:

1

The simple query below is not returning any results. I can't see any errors in it. Any idea why it's not working?

$sqlStr3 = "SELECT loginid, 
                   username, 
                   created    
              FROM login         
          ORDER BY created DESC 
             LIMIT 200";

$result = mysql_query($sqlStr3);
$count = 1;  
$arr = array();
echo "<table class=\"samplesrec1edit\">";
    while ($row = mysql_fetch_array($result)) { 
            $dt = new DateTime($row["created"], $tzFrom); 
            $dt->setTimezone($tzTo);

            echo '<tr>';
            echo '<td class="sitename1edit2a">'.$count++.'.</td>';
            echo '<td class="sitename1edit1"><a href="http://www...com/.../members/index.php?profile='.$row["username"].'"&gt;'.stripslashes($row["username"]).'&lt;/a&gt;&lt;/td&gt;';
            echo '<td class="sitename1edit2">'.$dt->format('F j, Y &\nb\sp &\nb\sp g:i a').'</td>';
            echo '</tr>';
        }

echo "</table>";
+1  A: 

Change your query line from:

$result = mysql_query($sqlStr3);

to

$result = mysql_query($sqlStr3) or die("MySQL error: " . mysql_error());

Even if the query itself looks fine, there's a few bazillion reasons something else can be causing problems.

And if it's not already on, please turn on PHP's display_errors and do error_reporting(E_ALL). Maybe the query portions are fine and something else is blowing up (eg. a invalid value in $tzFrom).

Marc B
Thanks... I had forgotten to define $tzFrom and $tzTo. The last parenthesis in your answer reminded me of that.
John