Hi,
I want to dynamically load an image into an HTML
The HTML5 page:
[code]
Ct
Ny
Ha
Az
Ts
You have chosen
nothing.
[/code]The PHP script:
[php]<?php
class MyDB extends SQLite3
{
function __construct()
{
$this->open(‘mydb.db’);
}
}
$db = new MyDB();
if(!$db){
echo $db->lastErrorMsg();
} else {}
$sql =<<<EOF
CREATE TABLE MYTABLE
(ID INT PRIMARY KEY,
NAME TEXT,
VS VARCHAR,
VB VARCHAR,
DENIED BOOL DEFAULT n,
USING BOOL DEFAULT n);
INSERT INTO MYTABLE (ID,NAME,VS,VB,DENIED,USING)
VALUES(1,'CT','soo1.jpg','boo1.jpg','n','n');
INSERT INTO SUMMON (ID,NAME,VIDEOS,VIDEOB,DENIED,USING)
VALUES(2,'NY','soo2.jpg','boo2.jpg','n','n');
// Other values for more records
EOF;
$ret = $db->exec($sql);
if(!$ret){
echo $db->lastErrorMsg();
} else {}
$ret = $db->exec($sql);
if(!$ret){
echo $db->lastErrorMsg();
} else {}
// Check if there is an active record
$sql = (“SELECT * FROM MYTABLE WHERE USING=‘y’”);
if(num_rows($result)>0)
{
// Select record where USING=‘y’. This should be only 1 record.
// Using Javascript load image: “boo1.jpg” to
echo // None for this yet.
}
else
{
if(isset($_POST[choices])) {
if($_POST['choice'] == 'CT') {
$sql = ("UPDATE MYTABLE SET USING='y' WHERE ID='1'");
// Using Javascript load image: "soo1.jpg" to <div class="choiceS"></div> element.
echo '<script type="text/javascript">getImage()</script>
// Using Javascript load 'name' of record into <span> of form2
echo <script type="text/javascript">
}
// Other values for other records in database.
}
}
}
$db->close();
?>
[/php]
And the AJAX script:
[code]function getImage(str) {
if (str == “”) {
document.getElementById(“choiceS”).innerHTML = “”;
return;
} else {
if (window.XMLHttpRequest) {
// code for browser
xmlhttp = new XMLHttpRequest();
} else {
// code for IE
xmlhttp = new ActiveXObject(“Microsoft.XMLHTTP”);
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById(“choiceS”).innerHTML = xmlhttp.responseImage;
}
};
xmlhttp.open(“GET”,“somescript.php?q=”+str,true);
xmlhttp.send();
}
}
// for in form2
document.getElementById(‘name’).innerHTML = ‘newtext’;
[/code]