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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.