ofmyst Posted August 6, 2008 Share Posted August 6, 2008 I have a mysql database called paintings with a table called pieces consisting of data (Title, Medium, Size). I have a PHP file (tinker2.php) that creates a table consisting of the information pulled from the mySQL database. My question: How can I have the table show up in my html file? Or am I going about this improperly? I am completely new to PHP and MySQL. Thanks so much, Sharon Link to comment https://forums.phpfreaks.com/topic/118511-solved-using-php-to-pull-data-from-mysql-and-put-into-html-novice/ Share on other sites More sharing options...
realjumper Posted August 6, 2008 Share Posted August 6, 2008 So what are you saying.....you want the results of your query to be displayed in an html table? Link to comment https://forums.phpfreaks.com/topic/118511-solved-using-php-to-pull-data-from-mysql-and-put-into-html-novice/#findComment-610126 Share on other sites More sharing options...
lemmin Posted August 6, 2008 Share Posted August 6, 2008 You can write HTML in a php file. Just put your html outside of the php tags to position the table where you want it. <html> <body> content <?php //code that draws the table ?> content </body> </html> Link to comment https://forums.phpfreaks.com/topic/118511-solved-using-php-to-pull-data-from-mysql-and-put-into-html-novice/#findComment-610130 Share on other sites More sharing options...
ofmyst Posted August 6, 2008 Author Share Posted August 6, 2008 The PHP file creates a HTML table, so if I go to tinker2.php the result is an HTML table filled in from mysql. My problem is that I want that table to show up in a different HTML file that has other information in it. The data table will be just part of the full page. I hope that is more clear. Unfortunately, I do not know the proper language for what I am trying to do. Link to comment https://forums.phpfreaks.com/topic/118511-solved-using-php-to-pull-data-from-mysql-and-put-into-html-novice/#findComment-610132 Share on other sites More sharing options...
realjumper Posted August 6, 2008 Share Posted August 6, 2008 Ok, I'm not quite sure what it is you want, but the following code will display the results of a query in an html table. Of course you'll have to change the query etc to suit your needs..... // Get all the data from the "example" table $result = mysql_query("SELECT * FROM example") or die(mysql_error()); echo "<table border='1'>"; echo "<tr> <th>Name</th> <th>Age</th> </tr>"; // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table echo "<tr><td>"; echo $row['name']; echo "</td><td>"; echo $row['age']; echo "</td></tr>"; } echo "</table>"; Link to comment https://forums.phpfreaks.com/topic/118511-solved-using-php-to-pull-data-from-mysql-and-put-into-html-novice/#findComment-610133 Share on other sites More sharing options...
ofmyst Posted August 6, 2008 Author Share Posted August 6, 2008 Thank you! It looks like that helped. Link to comment https://forums.phpfreaks.com/topic/118511-solved-using-php-to-pull-data-from-mysql-and-put-into-html-novice/#findComment-610138 Share on other sites More sharing options...
ofmyst Posted August 6, 2008 Author Share Posted August 6, 2008 Thank you, that worked. My next related question is, using your example: If rather than the table looking like this: Name Age Name Age Name Age I wanted it to look like this: Name Name Name Age Age Age How would I write the code? Link to comment https://forums.phpfreaks.com/topic/118511-solved-using-php-to-pull-data-from-mysql-and-put-into-html-novice/#findComment-610158 Share on other sites More sharing options...
ofmyst Posted August 7, 2008 Author Share Posted August 7, 2008 I figured that part out. Thanks for all of your help! Link to comment https://forums.phpfreaks.com/topic/118511-solved-using-php-to-pull-data-from-mysql-and-put-into-html-novice/#findComment-610335 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.