massive Posted May 30, 2006 Share Posted May 30, 2006 Hi :) , i have trouble displaying my datas in my html pages...i could but i can only display one data...i've made a class script named zql.php:so[code]Class Zql{ function Zql() { some task... } now here we go lets concentrate here: function getData() { $query = "SELECT * FROM meals"; $result = mysql_query($query, $this->connection); $data = mysql_fetch_array($result); return $data; }} $file = new Zql;[/code]Displaying page:Display.php[code]<? //I'm trying to get every information here include("include/Zql.php"); $information = $file->getData();?>[/code]lets say we had some html codes here:<html>blah blah blah....so when i display it... like lets say:<table> <tr> <td><? echo $information['FoodName']?></td> </tr> </table></htmlof course it will only display one data...i tried doing while conditions and for conditions but its seems im not doing it right its easy to (while conditon) if it was outside the class i would have done it like this:[code] $q = "select * from meals"; $r = mysql_query($q) or die (mysql_error());<table>while($row = mysql_fetch_object($r)) //i used object instead of arrays{ <tr> <td><? echo $information->FoodName?></td> </tr>}</table></html[/code]but i need to display multiple datas using the class:is it:while($information){ echo "$information";}or foreach($information as $key){ echo "$key";}im confuse...tnx Quote Link to comment https://forums.phpfreaks.com/topic/10771-displaying-multiple-rows-using-class/ Share on other sites More sharing options...
poirot Posted May 30, 2006 Share Posted May 30, 2006 You should use something like this:[code]$query = mysql_query(SELECT * FROM table") or die(mysql_error());while ($row = mysql_fetch_row($query)) { echo $row['information'];}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/10771-displaying-multiple-rows-using-class/#findComment-40241 Share on other sites More sharing options...
massive Posted May 31, 2006 Author Share Posted May 31, 2006 [!--quoteo(post=378376:date=May 30 2006, 09:12 AM:name=poirot)--][div class=\'quotetop\']QUOTE(poirot @ May 30 2006, 09:12 AM) [snapback]378376[/snapback][/div][div class=\'quotemain\'][!--quotec--]You should use something like this:[code]$query = mysql_query(SELECT * FROM table") or die(mysql_error());while ($row = mysql_fetch_row($query)) { echo $row['information'];}[/code][/quote]i think your query is outside the class? i could apply this if i was not using classes :) i think...:( Quote Link to comment https://forums.phpfreaks.com/topic/10771-displaying-multiple-rows-using-class/#findComment-40411 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.