Jump to content

Recommended Posts

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()

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 :)

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.

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.

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.

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.

 

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.

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:]

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.