当前位置: 动力学知识库 > 问答 > 编程问答 >

php - How to store row for later use when generated element is clicked without updating page?

问题描述:

How can I store the QuestionID of the specific clicked question generated by my query without adding it to the URL as I have done below?

I want to store the QuestionID value so that I can put it into my database with the IP address of my user (no login), without updating the page.

$stmt = $conn->prepare("SELECT * FROM question ORDER BY QuestionVotes DESC LIMIT 4");

$stmt->execute();

$result = $stmt->get_result();

if ($result->num_rows > 0) {

// output data of each row

while($row = $result->fetch_assoc()) {

//$row["QuestionID"] to add id to url

echo "<div class=\"col-md-3\"><h2>". $row["QuestionHeader"]. "</h2><p>". $row["QuestionText"]. "</p><p><a href=\"index.php?id=". $row["QuestionID"]. "\" class=\"btn btn-success\"> " . $row["QuestionVotes"] . "</a></p></div>";

$id = $row["QuestionID"];

}

}

else

{

echo "0 results";

}

Table:

Question: QuestionID (PK), QuestionHeader, QuestionText, QuestionVotes

I'd appreciate any help, suggestions or such!

分享给朋友:
您可能感兴趣的文章:
随机阅读: