选择并显示图像而无需刷新页面| PHP | AJAX

时间:2019-02-19 22:33:40

标签: javascript php mysql ajax mysqli

我正在尝试在页面上显示基于表单中两个字段从MySQL获取的图像。

在我的程序中,用户选择一个日期,然后选择一个游戏名称,并使用这两个值上的两个值将显示其地址来自MySQL的图像。

当前,我的代码允许我选择游戏的日期和名称,但是选择图像和显示的实际操作不起作用/

我的代码:

<?php

require "config.php";
?>

<!doctype html public "-//w3c//dtd html 3.2//en">

<html>

<head>
<SCRIPT language=JavaScript>
function reload(form)
{
    var val=form.cat.options[form.cat.options.selectedIndex].value; 
    self.location='dd3.php?cat=' + val ;
}
function reload3(form)
{
    var val=form.cat.options[form.cat.options.selectedIndex].value; 
    var val2=form.subcat.options[form.subcat.options.selectedIndex].value; 
    self.location='dd3.php?cat=' + val + '&cat3=' + val2 ;
}
</script>
</head>

<body>
<?php
///////// Getting the data from Mysql table for first list box//////////
$quer2="SELECT DISTINCT category,cat_id FROM category order by category"; 
///////////// End of query for first list box////////////

/////// for second drop down list we will check if category is selected else we will display all the subcategory///// 
$cat=$_GET['cat']; // This line is added to take care if your global variable is off
if(isset($cat) and strlen($cat) > 0){
    $quer="SELECT DISTINCT subcategory,subcat_id 
            FROM subcategory 
            where cat_id=$cat 
            order by subcategory"; 
}else{
    $quer="SELECT DISTINCT subcategory,subcat_id 
            FROM subcategory 
            order by subcategory"; 
} 
////////// end of query for second subcategory drop down list box ///////////////////////////

echo "<form method=post name=f1 action='dd3ck.php'>";
?>

<input type=text name=cat id='s1' size='8' onchange="reload(this.form)">
<a href="javascript:void(0);" NAME="plus2net Calendar" onClick=window.open("select_date.php","Ratting","width=350,height=270,left=150,top=200,toolbar=1,status=1,");>Select date</a>

<?php
//////////        Starting of second drop downlist /////////
echo "<select name='subcat' onchange=\"reload3(this.form)\"><option value=''>Select one</option>";
foreach ($dbo->query($quer) as $noticia) {
    if($noticia['subcat_id']==@$cat3){
        echo "<option selected value='$noticia[subcat_id]'>$noticia[subcategory]</option>"."<BR>";
    }else{
        echo  "<option value='$noticia[subcat_id]'>$noticia[subcategory]</option>";}
    }
    echo "</select>";
    //////////////////  This will end the second drop down list ///////////
?>

</body>
</html>

0 个答案:

没有答案