質問に答える質問があるときにこれを表示しようとしています
これは、答える質問がない場合です。質問無し
これは私が試したコードです。コメントアウトされた行は、私が試したifループですが、常に1を返しました
<?php
$dbtype = "mysql";
$dbhost = "localhost";
$dbname = "starsqa";
$dbuser = "root";
try {
$pdo_conn = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbuser);
} catch (PDOException $ex) {
echo $ex->getMessage();
}
$qry_string = "select * from questions inner join stars on stars.starID = questions.starID where stars.starID = ? && approved = 1 && answered = 1 && `check` = 0";
$prep = $pdo_conn->prepare($qry_string);
$starid = $_SESSION['starid'];
$prep->execute(array($starid));
//if (count($qry_string) > 0) {
//echo count($qry_string);
echo "<table style='border:0px; background-color:#8C7E6C;'><thead style='border:0px;'><tr style='border:0px solid white; background-color:#153E7E; color:white; padding: 5; margin: 5;'><th style='border:1px white; padding: 5; margin: 5;'>Question</th><th style='border:1px white; padding: 5; margin: 5;'>Response</th></tr></thead><tbody>";
while ($row = $prep->fetch(PDO::FETCH_ASSOC)) {
echo "<tr style='border:1px white; background-color:lightblue; padding: 5; margin: 5;'><td style='border:1px white; padding: 5; margin: 5;'>{$row['question']}</td>
<td style='border:1px white; padding: 5; margin: 5;'><textarea rows='4' cols='50' id='{$row['questionID']}' class='response'>{$row['response']}</textarea></td></tr>";
}
echo "</tbody></table>";
echo "<br><button type='button' class='save_btn'>Save All</button><br><br>";
//}
// if (count($qry_string) < 1) {
// echo count($qry_string);
// echo "no question to answer atm";
// }
?>
なぜこれが機能しないのか、またはこれを達成する別の方法について誰かがアイデアを持っていますか?
これを使用して現在動作しています(showdevに感謝します):
$prep->execute(array($starid));
//if (count($qry_string) > 0) {
//echo count($qry_string);
// $count= count($prep->fetchAll());
$count = $prep->rowCount();
//echo "$count";
if ($count > 0){
echo "<table style='border:0px; background-color:#8C7E6C;'><thead style='border:0px;'><tr style='border:0px solid white; background-color:#153E7E; color:white; padding: 5; margin: 5;'><th style='border:1px white; padding: 5; margin: 5;'>Question</th><th style='border:1px white; padding: 5; margin: 5;'>Response</th></tr></thead><tbody>";
while ($row = $prep->fetch(PDO::FETCH_ASSOC)) {
echo "<tr style='border:1px white; background-color:lightblue; padding: 5; margin: 5;'><td style='border:1px white; padding: 5; margin: 5;'>{$row['question']}</td>
<td style='border:1px white; padding: 5; margin: 5;'><textarea rows='4' cols='50' id='{$row['questionID']}' class='response'>{$row['response']}</textarea></td></tr>";
}
echo "</tbody></table>";
echo "<br><button type='button' class='save_btn'>Save All</button><br><br>";
}
if ($count < 1) {
echo "no question to answer atm";
}
ページを更新して新しい/現在の情報を表示するために ajax の [すべて保存] を押したら、他に必要なものを考えただけです。これを行うにはどの関数を使用しますか?
私はそれをしました:-)これを使用して: location.reload();
var html = '';
$(document).ready(function(){
$(".save_btn").live('click', function() {
$('.response').each(function(){
//alert($(this).attr('id'));
//alert($(this).val());
if ($(this).val() == '') {
html = $.ajax({
url: "response.php?questionID=" + $(this).attr('id') + "&response=" + $(this).val() + "&check=0",
async: false
}).responseText;
}
if ($(this).val() !== '') {
html = $.ajax({
url: "response.php?questionID=" + $(this).attr('id') + "&response=" + $(this).val() + "&check=1",
async: false
}).responseText;
}
});
alert(html);
location.reload();
});
})