Jump to content

Echo is not working


mycro

Recommended Posts

For some reason, the following code will not retreive the row data

[code]$query2 = "SELECT * FROM topics WHERE timestamp='$timestamp'";
$result1 = mysql_query($query2, $conn);
while($row=mysql_fetch_array($result1)) {

echo $row[topicid];
}[/code]

This same thing works if I simply change $row[topicid] to a different field, such as row[username]. There IS data in all of the topicid rows, btw. If it helps, "topicid" is the primary index in my database, and auto incriments. Thank you!
Link to comment
https://forums.phpfreaks.com/topic/20338-echo-is-not-working/
Share on other sites

Put some debugging statements in your code to see what is going wrong:
[code]<?php
$query2 = "SELECT * FROM topics WHERE timestamp='$timestamp'";
echo "The query we are using is: $query2<br>";
$result1 = mysql_query($query2, $conn) or die("There was a problem with the query: $query2<br>" . mysql_error());
echo 'Number of rows retrieved: ' . mysql_num_rows($result1) . '<br>';
while($row=mysql_fetch_assoc($result1)) {
      echo '<pre>' . print_r($row,true) . '</pre>';  // this is the crucial debugging line. It will show you exactly what has been retrieved.
//      echo $row['topicid'];  remove this line for now (put it back after you figure out what is wrong)
}?>[/code]

Ken
Link to comment
https://forums.phpfreaks.com/topic/20338-echo-is-not-working/#findComment-89623
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.