Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialamandeep kaur bhangal
615 Pointscan u help me with my code
class function that is retrieving values from db
public function retrieveFun() { include 'inc/main.php';//connecting to db.
$result = mysqli_query($con,"SELECT * FROM db order by name DESC");
while($row = mysqli_fetch_array($result))
{
$var = array('name' =>$row['name'] ,
'owner'=>$row['owner'],
'date'=>$row['date'] );
// echo $var["name"]."<br/>";
// echo $var["owner"]."<br/>";
// echo $var["date"]."<br/><br/>";
return array($var["name"],$var["owner"],$var["date"]);
}}
and code where i want to display all the rows retrieved in desired format
$obj = new classname(); $id= $obj->retrieveFun();
echo //here i want to display all the rows retrieved in table format. Please help me out as soon as possible
1 Answer
Alex Looper
2,098 PointsI don't know if I understand you question, or if you have even asked one, but try this:
- Make sure you're connected to your database. Then you can do this.
$result = mysqli_query($con,"SELECT * FROM db ORDER BY name DESC");
while($row = mysqli_fetch_array($result)){
$name = $row['name']; //name is a column in your db
$owner = $row['owner']; //owner is a column in your db
$date = $row['date']; //date is a column in your db
}
$printoutput .= "<table width='500' border='0' cellspacing='0' cellpadding='0'>
<tr><td> ". $name . "</td></tr>
<tr><td>$" . $owner . "</td></tr>
<tr><td>". $date . "</td></tr></table>
echo $printoutput;
I'm not sure what this is, $obj = new classname(); $id= $obj->retrieveFun(); Or what you meant by this, but I hope this helps.