Jump to content

php in html


DeFActo

Recommended Posts

Hello, i have php file a.php with code

<?php
$link = mysql_connect('', '', '');
mysql_select_db('');
$sql = "SELECT * FROM table1 WHERE id='caspa'";
$sql1= "SELECT * FROM table2 WHERE id='caspa'";
$sql2="SELECT * FROM table3 WHERE id='caspa'";
$query = mysql_query($sql);
$query1 = mysql_query($sql1);
$query2 = mysql_query($sql2);
$result=mysql_fetch_assoc($query);
$result1=mysql_fetch_assoc($query1);
$result2=mysql_fetch_assoc($query2);
if ($result && $result1 && $result2)
   {
   $a=$result['gylis4'];
   $b=$result['gylis3'];
   $a1=$result1['plotis4'];
   $b1=$result1['plotis3'];
   $a2=$result2['aukstis4'];
   $b2=$result2['aukstis3'];
     }
    else{
    echo "There is no such a record.";
}
echo "$a";
//echo "$b<br>";
//echo "$a1";
//echo "$b1<br>";
//echo "$a2";
//echo "$b2";
//echo "$a<br>";
//echo "$a<br>";
//echo "$a<br>";
//echo "$a<br>";
?>

and i need to see the results in a.html file. Anybody could help me with that? Its something like that

<form id="form1" name="form1" method="post" action="a.php">

but it doesn't work for me :(

Thank you in advance.

Link to comment
Share on other sites

PHP files output (x)html to the browser. So it shouldn't matter.

 

If for some reason you really need your file to have the file extension as .html, then you have two options, both of which will require playing with your server settings. You need to either do a mod re-write, in which case you actually write the file in php, and the file extension is php, but when the user enters an address with a .html file extension, it shows in the browser as being .html, but in fact the page is .php in the background, or else you need to enable your server to parse .html files as .php. This will slow down your processing on static .html pages though, as the server will extend resources in attempting to parse the file even though it doesn't require parsing.

Link to comment
Share on other sites

Thanks for the reply, but i think you did not understand what i want (that is my fault, because i did not give enough information). What i want to do is:

lets say i have index.html file with some design, couple of buttons and table and i have that a.php file that coresponds with database. What i want to do is if i push one button in index.html file i get results from a.php file in some index.html tables cell.

Sorry for my bad english.

Thank you in advance.

Link to comment
Share on other sites

Ahh I see.

 

Well if you want to use only php, then you cannot do this without using the techniques I mentioned above. HTML files are static - they cannot be changed. This also means that they cannot interact with the database. The only way around this is to either set your server to parse html files as PHP, or to use mod re-write (which are the two methods I previously mentioned).

 

You CAN however do this with AJAX (using Javascript and Dom functions). You will need to write a php script that pulls the data from the database and echos it. Then you need to use javascript to access that script, and when the results come back, use dom scripting to insert the data into the proper data cell. This method works very good with one downside - it won't work if the user has javascript turned off.

Link to comment
Share on other sites

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.