Page 1 of 1

mysql return

Posted: Wed Mar 29, 2006 8:52 pm
by joerosenthal
for a script I am making, I am unable to echo. is there any possible way to rewrite the following code without echo or print and still maintain the same functionality?

Code: Select all

<?php
       mysql_connect("localhost", "user","pass") or die(mysql_error());
       mysql_select_db("main") or die(mysql_error());

       $query="SELECT * FROM chat";
       $result=mysql_query($query);

       $num=mysql_numrows($result);

       mysql_close();

       $i=0;
       while ($i < $num) {

       $postby=mysql_result($result,$i,"postby");
       $msg=mysql_result($result,$i,"msg");
       $date=mysql_result($result,$i,"date");
       $ip=mysql_result($result,$i,"ip");
       $time=mysql_result($time,$i,"time");

echo "$postby&nbsp;";

$i++;
}

?>

Posted: Wed Mar 29, 2006 9:01 pm
by feyd
what are you trying to do with this?

Posted: Wed Mar 29, 2006 9:04 pm
by joerosenthal
this page is being included in an ajax page to make a "shoutbox" type thing. there's an issue with echo/print commands so im trying to see if theres a substitution, previously I had been using a text file as my database and was able to just return the top twenty lines of the file.

Re: mysql return

Posted: Fri Mar 31, 2006 7:21 am
by jrd

Code: Select all

echo $postby."&nbsp;";

?>
Try that.

Posted: Fri Mar 31, 2006 9:15 am
by joerosenthal
problem has been solved by using

Code: Select all

while($row = mysql_fetch_assoc($result)) {
$output .= $row['postby'] . " ";
}
return $output;