Jump to content

Displaying Multiple Rows using class


massive

Recommended Posts

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>
</html


of 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
Link to comment
https://forums.phpfreaks.com/topic/10771-displaying-multiple-rows-using-class/
Share on other sites

[!--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...:(

Archived

This topic is now archived and is closed to further replies.

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