duanfeiqu1989 2015-12-03 02:38 采纳率: 100%
浏览 46

如果条件在数组中显示表中的数据

I have a dropdown list contains "Processed","Unreleased","Paid", that are from the Status Column. I want to add the Scanned Copy in the option but that is from the other column Scanned copy. What will Im going to do to make it work? Here's my code.

$searchstat = (!empty($_REQUEST['optstat']) ? $_REQUEST['optstat'] : '%');
$vartxtsummryNo = (!empty($_REQUEST['txtsummryNo']) ?   $_REQUEST['txtsummryNo'] : '%');

if($searchstat!="%"){
  $vartxtsummryNo="%";
}

$sc=ScanCopy();
$scan_copy=array("Scanned Copy");
$astatus = array("Processed","Unreleased","Paid");
$astatus = array_merge($astatus, $scan_copy);

if ($astatus[$scan_copy]) { $sc; }

foreach ($astatus as $stat){

$optstatus  .= "<option " . ($searchstat  ==  $stat ? "selected" : "") . ">$stat</option>";
}

This is the query for fetching data when Scanned copy is selected.

function ScanCopy() {

  $sql2="SELECT * FROM payment_summary_log WHERE Scanned_copy IS NOT NULL ORDER BY Date_Created";
  $mesconn = dbConnect();
  $messtmt1 = $mesconn->prepare($sql2);
  $data = $messtmt1->fetchAll(PDO::FETCH_ASSOC);
  $mesconn=null;  
  return $data;
}

Here's the structure of search box and the dropdownlist.

echo "<form method=get name='" . $_REQUEST['option'] . ".form' autocomplete='off'>";
echo "<input type='hidden' name='option' value='" . $_REQUEST['option'] . "'>";
echo "<table class=normal2 style='font-size:0.6em;'>";
echo "<h2 style='color:blue'>Payment Summary Tracking</h2><hr>";

echo "<tr><th>Payment Summary No. :</th><td colspan=2><input type=text name='txtsummryNo' value='".$vartxtsummryNo."'> <input type=submit name='bnt_setdate' value='Find'></td>";
echo "<tr><th>Status :</th><td colspan=2><select name=optstat onchange='document.forms[\"" .$_REQUEST['option'] . ".form\"].submit();'>$optstatus</select></td></tr>";
echo "</tr></table></form>";
echo "<h2></h2><hr>";
  • 写回答

1条回答 默认 最新

  • dqwh1209 2015-12-03 02:52
    关注
    1. First you need to return a valid $data from ScanCopy() function, which is not happening currently
    2. Second You need to merge the return from scancopy function to $astatus array and add it to the dropdown :

       $astatus = array_merge($astatus, $scan);
      

    Please modify the array accordingly before merging, I just provided you the hint, for more details look below:

    http://php.net/manual/en/function.array-merge.php

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据