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 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝