mysql return

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
joerosenthal
Forum Newbie
Posts: 7
Joined: Tue Mar 28, 2006 8:27 pm

mysql return

Post 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++;
}

?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

what are you trying to do with this?
joerosenthal
Forum Newbie
Posts: 7
Joined: Tue Mar 28, 2006 8:27 pm

Post 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.
jrd
Forum Commoner
Posts: 53
Joined: Tue Mar 14, 2006 1:30 am

Re: mysql return

Post by jrd »

Code: Select all

echo $postby."&nbsp;";

?>
Try that.
joerosenthal
Forum Newbie
Posts: 7
Joined: Tue Mar 28, 2006 8:27 pm

Post by joerosenthal »

problem has been solved by using

Code: Select all

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