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
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...:(
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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