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 trialDimitrios Petropoulos
824 PointsEcho data from mysql to php
Hello,
I am new to programming and i am trying to echo some data from a mysql table to php. Could you please give some guidance?
3 Answers
Michael Fish
7,804 PointsHello Dimitri,
Not sure what the data in the table looks like or what you want to do with it. But here is a general solution:
//Select all(*) records in the YOUR_TABLE table and store them in a variable called $sql.
$sql = "SELECT * FROM YOUR_TABLE";
//Echo the sql data stored inside the variable
echo $sql;
//(Optional) To view the data in your browser you could do this
//Store the results of your query
$results = mysqli_query($sql);
//Dump the data inside the results to the screen
var_dump($results);
Hopefully this is helpful!
Mike
Benjamin Orimoloye
23,328 PointsI think you should go through the Beginner PHP course to really understand. But to answer your question, the steps will be to query the database, store the result in a variable (an array), and echo the one or more of the values in the array. That's the general principle.
Dimitrios Petropoulos
824 PointsThank you both!
Now it seems to fetch the data from the database but what i actually see is this string: object(mysqli_result)#59 (5) { ["current_field"]=> int(0) ["field_count"]=> int(5) ["lengths"]=> NULL ["num_rows"]=> int(1) ["type"]=> int(0) } $result
The fact is that the table inculdes four categories that i would like to echo on the browser, employee_id, gear, startdate and enddate and i am missing the way that i have to follow to do so.
FYI the software is in YII framework.