skimsurf4 Posted June 16, 2009 Share Posted June 16, 2009 hi, i have a php page called select.php that connects and retrieves data from a database. now, how do i write that result to a html page called output.html? Quote Link to comment https://forums.phpfreaks.com/topic/162483-retrieving-data-using-php-and-writing-result-to-html/ Share on other sites More sharing options...
Alex Posted June 17, 2009 Share Posted June 17, 2009 Are you sure you want to write it to a file? If you write it to a file then it will only be up-to-date every time you run that file again. Instead you can just run the query and echo out the results every time the page is run. That way everything that displays is always up-to-date. If you still want to write it to a file, you can look into fopen() and fwrite() Quote Link to comment https://forums.phpfreaks.com/topic/162483-retrieving-data-using-php-and-writing-result-to-html/#findComment-857603 Share on other sites More sharing options...
EchoFool Posted June 17, 2009 Share Posted June 17, 2009 hi, i have a php page called select.php that connects and retrieves data from a database. now, how do i write that result to a html page called output.html? Not sure the reason of your method nor do i know your level of knowledge with php but do you know html can be used in php so you don't need to write to a html file... (im assuming here your new ?) If not then AlexWD hit the nail on the head Quote Link to comment https://forums.phpfreaks.com/topic/162483-retrieving-data-using-php-and-writing-result-to-html/#findComment-857607 Share on other sites More sharing options...
skimsurf4 Posted June 17, 2009 Author Share Posted June 17, 2009 html page is the template page where the php page connects to the database and runs the sql statement to retrieve the data to display to the html(template) page. yes, the html page will always display the same information. it will only change when there is an update to the database. i like to know the syntax how to write this bit of code. Quote Link to comment https://forums.phpfreaks.com/topic/162483-retrieving-data-using-php-and-writing-result-to-html/#findComment-857619 Share on other sites More sharing options...
Alex Posted June 17, 2009 Share Posted June 17, 2009 Are updates so infrequent to the database that every time they're made it won't be annoying to rerun the file that will be creating the html file? If not.. $fp = fopen("somefile.html","w"); if(!$fp) { echo 'File could not be opened.'; exit; } fwrite("Stuff that's being written to the file"); fclose($fp); That's a basic example on how to write to a file. Quote Link to comment https://forums.phpfreaks.com/topic/162483-retrieving-data-using-php-and-writing-result-to-html/#findComment-857624 Share on other sites More sharing options...
skimsurf4 Posted June 17, 2009 Author Share Posted June 17, 2009 updates to the database is very minor and quickly published to the live server after making changes on the fly. Quote Link to comment https://forums.phpfreaks.com/topic/162483-retrieving-data-using-php-and-writing-result-to-html/#findComment-857644 Share on other sites More sharing options...
skimsurf4 Posted June 17, 2009 Author Share Posted June 17, 2009 Not sure the reason of your method nor do i know your level of knowledge with php but do you know html can be used in php so you don't need to write to a html file... (im assuming here your new ?) If not then AlexWD hit the nail on the head Yes, I do know that I can embed the html in the php page. But I'm trying to keep the html template (Frontpage-WYSIWYG) design page separate from the php page. The main reason behind this is so that I can still be able to use the Frontpage WYSIWYG design template. If i combine the html into the php page and save it as php file, the html design page is no longer available. Quote Link to comment https://forums.phpfreaks.com/topic/162483-retrieving-data-using-php-and-writing-result-to-html/#findComment-857649 Share on other sites More sharing options...
skimsurf4 Posted June 17, 2009 Author Share Posted June 17, 2009 Let's say from the php page, I have a sql that selects from the members table in the database: mem_name, mem_phone, and mem_address. How do I write the php code to display the 3 fields to a html web page? Let's called the php page, select.php and html page output.html. Quote Link to comment https://forums.phpfreaks.com/topic/162483-retrieving-data-using-php-and-writing-result-to-html/#findComment-857655 Share on other sites More sharing options...
htzone Posted June 17, 2009 Share Posted June 17, 2009 You could set up some <div> or <span> tags with id values in your template (so that they're unique), and then have your PHP script load the entire contents of that template, and then search through it and fill in the relevant <div> or <span> tags with the retrieved data. Then save all of this to a new file, as suggested earlier. No matter how you do this though, it's going to be messy. Quote Link to comment https://forums.phpfreaks.com/topic/162483-retrieving-data-using-php-and-writing-result-to-html/#findComment-857698 Share on other sites More sharing options...
skimsurf4 Posted June 17, 2009 Author Share Posted June 17, 2009 You could set up some <div> or <span> tags with id values in your template (so that they're unique), and then have your PHP script load the entire contents of that template, and then search through it and fill in the relevant <div> or <span> tags with the retrieved data. Then save all of this to a new file, as suggested earlier. No matter how you do this though, it's going to be messy. this is the answer i was looking for. can you expand on it a little more? like what is the php code to load the entire contents of the html template? i could assign the id values in my template like this... [:memberName:] [:memberPhone:] [:memberAddress:] Quote Link to comment https://forums.phpfreaks.com/topic/162483-retrieving-data-using-php-and-writing-result-to-html/#findComment-858136 Share on other sites More sharing options...
skimsurf4 Posted June 17, 2009 Author Share Posted June 17, 2009 the members table in the database has currently 18 members. the php/sql will supposedly, if the coding works, write every members name, phone#, and address to the html template that will be displayed on a webpage. until i update the members table in the database (add or delete), it will only display the current 18 members on the website. Quote Link to comment https://forums.phpfreaks.com/topic/162483-retrieving-data-using-php-and-writing-result-to-html/#findComment-858142 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.