1
的WordPress 4.4.2主题=从WPZoom的WordPress:含有表格和自定义表的查询自定义模板
我已经创建了一个包含狗的自定义表的SQL查询自定义模板Meeta。查询通过WPDB类正常工作,我可以以可接受的格式显示输出数据。
现在在相同的自定义模板中,我插入一个php表单以允许用户输入搜索条件。
表单显示正常,但查询立即执行而无需等待用户点击提交,因此我无法输入任何搜索条件。我应该怎么做才能保留查询,直到表单被提交?
,如果我介绍主页错误在其他地方显示返回而不显示错误,我已经摆弄周围了一段时间,很多次。我是否必须打开错误显示或将它发送到某处的日志中。
<?php the_content(); ?>
//=================================
<?php
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
// set variables to wildcard
$dog_name = "%";
?>
<h2>Chercher dans la base</h2>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
Dog_name: <input type="text" dog_name="dog_name" value="<?php echo $dog_name;?>">
<input type="submit" name="submit" value="Submit">
</form>
<?php
$dog_name = test_input($_POST["dog_name"]);
global $wpdb;
$query = "SELECT offspring.dog_name, offspring.sex, offspring.color, offspring.dob, offspring.cotation, offspring.titles, offspring.hd, offspring.titles, offspring.eyes, offspring.dna, offspring.born_in, offspring.prod_prop, sire.dog_name AS sire, dam.dog_name AS lice
FROM BP_dog AS offspring
JOIN BP_dog AS sire ON sire.dog_id = offspring.sire_id
JOIN BP_dog AS dam ON dam.dog_id = offspring.dam_id
ORDER BY dog_name";
word
$results = $wpdb->get_results($query);
$num_rows = $wpdb->num_rows;
print "Number of rows = $num_rows.<br>";
foreach ($wpdb->get_results($query)as $row) {
print $row->dog_name . "\t";
print $row->sex . "\t";
print $row->dob . "\t";
print $row->color . "\t";
print $row->cotation . "\t";
print $row->titles . "\t";
print $row->hd . "\t";
print $row->eyes . "\t";
print $row->dna . "\t";
print $row->born_in . "<br>";
print "Sire = " . $row->sire . "\t";
print "Lice = " . $row->lice . "<br>";
print $row->prod_prop . "<br><br>";
}
?>
非常感谢湿婆。我得到了正确运行和查询执行感谢您的建议的形式。 – Gary
谢谢加里:) –