Jump to content


Photo

Displaying Multiple Rows using class


  • Please log in to reply
2 replies to this topic

#1 massive

massive
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 30 May 2006 - 12:51 PM

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
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;


Displaying page:

Display.php

<?

      //I'm trying to get every information here
     include("include/Zql.php");
 
     $information = $file->getData();




?>


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:


 $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


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

#2 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 30 May 2006 - 02:12 PM

You should use something like this:
$query = mysql_query(SELECT * FROM table") or die(mysql_error());
while ($row = mysql_fetch_row($query)) {
   echo $row['information'];
}

~ D Kuang

#3 massive

massive
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 31 May 2006 - 12:45 AM

[!--quoteo(post=378376:date=May 30 2006, 09:12 AM:name=poirot)--][div class=\'quotetop\']QUOTE(poirot @ May 30 2006, 09:12 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
You should use something like this:
$query = mysql_query(SELECT * FROM table") or die(mysql_error());
while ($row = mysql_fetch_row($query)) {
   echo $row['information'];
}
[/quote]

i think your query is outside the class? i could apply this if i was not using classes :) i think...:(




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users