[英]Recover Id or Value with PHP/JS/MYSQL
I'm working on a project and I need to recover Id in php or js 我正在做一个项目,我需要在php或js中恢复ID
I have 2 row in the same table (mySql) row 1 = id_answer and row 2 = text 我在同一表格(mySql)中有2行,第1行= id_answer,第2行=文本
I exploit the first row text with a foreach in my code. 我在代码中使用foreach利用第一行文本。
I search to associate in the same time in a div, my text and in value the Id who doing references to this answer. 我搜索同时在div中关联我的文本和值来引用此答案的ID。
<ul id="listQuestionResponseFaq" class="col-sm-12 pad-0">
<?php
foreach ($questionResponseArrayFaq as $questionResponseFaq ) {
?>
<li class="liSearchFaq col-sm-8 col-sm-offset-2 pad-0">
<div class='panel padding txtLeft' value="<?php $answerSearch ?> ">
<?php echo $questionResponseFaq; ?>
</div>
</li>
<?php
}
?>
</ul>
I dont know how to recover the id_answer and insert in my answer. 我不知道如何恢复id_answer并将其插入我的答案中。 Its not the same id for all answer.
所有答案的ID都不相同。 Every answer got a different ID
每个答案都有不同的ID
Thx to help me 谢谢我
$queryFaq = $pdoRepository->executeQuery("
SELECT DISTINCT fa.* FROM form_answer AS fa
LEFT JOIN form_option_filter AS fof
ON fof.id_option = fa.id_option
LEFT JOIN form_option AS fo
ON fo.id_option = fa.id_option
WHERE fof.statut = 1
AND fo.search = 1");
if ($queryFaq) {
$questionResponseArrayFaq = array();
while ($row = $queryFaq->fetch(PDO::FETCH_ASSOC)) {
$questionsSearch = $row['text'];
$answerSearch = $row['id_answer'];
array_push($questionResponseArrayFaq, $questionsSearch);
}
}
I think I understand what you are looking for and if so I am going to recomend you take a different approach to take advantage of PHP's associate array looping. 我想我了解您在寻找什么,如果可以,我建议您采用其他方法来利用PHP的关联数组循环。
$questions = array();
while ($row = $queryFaq->fetch(PDO::FETCH_ASSOC))
{
$questions[$row['text']] = $row['id_answer'];
}
foreach($questions as $question => $answer)
{
echo 'Question: ' . sanitize($question);
echo 'Answer:' . sanitize($answer);
}
If you really want 2 seperate arrays you can itterate through both using the reset
and next
functions. 如果您确实需要2个独立的阵列,则可以使用
reset
和next
函数来完成。 I found this on another stack overflow example a hwile ago but can't find it right now. 我在一个较早之前的另一个堆栈溢出示例中找到了它,但现在找不到。 If someone does feel free to reference and give credit.
如果有人愿意参考并给予好评。
$questions = array();
$answers = array();
while ($row = $queryFaq->fetch(PDO::FETCH_ASSOC))
{
$questions[] = $row['text']
$answers[] = $row['id_answer'];
}
$answer = reset($answers);
foreach($questions as $question)
{
echo 'Question: ' . sanitize($question);
echo 'Answer:' . sanitize($answer);
$answer = next($answers);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.