Forum Moderators: coopster
I want to develop a comments page for my site where you have a text area and each time someone types something as a comment, it gets stored as the next row in my table. And when I open the page, the counter should go from 1, incrementing my one and printing the corresponding row content. When it encounters a NULL (that is the end of the file), it displays a text area and exits the loop.
I would like to know how to do this. One problem I face is I can get the row content stored in a variable, but do not know how to display it. Print, echo commands seem to be not fit for this function. I am very new to PHP,so can somebody please tell me what commands to use for this.
for($i = 1;;$i++)
{
$content = mysql_query("SELECT content FROM table1 WHERE sno = '$i'");if($content="")
{
?><input type = "text">....
<?php
break;
else
echo $content;
?>
<br>
<?php
}
?>
Basically what I am trying to do is check if the content is not null, that is that row of the table contains a comment, then display the 'content' field corresponding to each 'sno'(serial number) field.
And when the content field is found to be null, then display a text box instead and break away. I have not included the html part of including the text area here.
So, can someone tell me if I am going wrong somewhere?
<?php
$content = mysql_query("SELECT content FROM table1 WHERE sno = '$i'");
while (rows = mysql_fetch_array($content)) {
// print out the existing data
}
?>
<!-- Now back into HTML and show the textarea: -->
<textarea ... >
However, as you noted, the variable name itself is deceiving when you are reading the code. I just used what the anand84 first laid down to try and avoid any confusion, and in the process it seems we have created more. Sorry I confused you. This should clear things up a bit:
<?php
$rows = mysql_query("SELECT content FROM table1 WHERE sno = '$i'");
while (row = mysql_fetch_array($content)) {
// print out the existing data
}
?>
<!-- Now back into HTML and show the textarea: -->
<textarea ... >