如何在php中正确地为我的tbl_item做下拉列表菜单 [英] How to properly make drop down list menu for my tbl_item in php

查看:76
本文介绍了如何在php中正确地为我的tbl_item做下拉列表菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的下拉列表菜单有问题,它一直在收到错误的错误。
我的下拉列表菜单将来自tbl_item(postgresDB)的itemname



funcContainer.php页面

 函数DropdownListMenu($ label,$ name,$ sql,$ value,$ item,$ submit_name,$ submit_val)
{
echo $ label。 & nbsp;< select name ='$ name'>;
$ rs = pg_query($ sql);
while $($ row = pg_fetch_array($ rs,NULL,PGSQL_ASSOC))
{
echo< option value ='。$ row [$ value]。';
if($ row [$ value] == $ _POST [$ name])
echo'selected';
echo>。$ row [$ item]。< / option>;
}
echo< / select>& nbsp;;
echo< input type ='submit'name ='。$ submit_name。'value ='。$ submit_val。'/>;
}

search.php页面

 <?php 
require_once(funcContainer.php);
Connect();


$ sql =从tbl_item中选择itemid,itemname;
DropdownListMenu(Select Item,Item,$ sql,'itemid','itemname',Submit,Search);?>



tbl_item结构:
itemid> itemname> highquantitythreshold> lowquantitythreshold> qpunit> ...



wamp错误:
SCREAM:ERROR suppresion ignored&在D中未定义的索引项目:.....
有人可以请再次借给我一个援助之手:)谢谢!。 在初始页面加载 $ _ POST [$ name] (或者更具体地说 $ _ POST ['Item'] 可能没有设置,所以你需要检查它是否在使用之前设置。



更改

  if($ row [$ value] == $ _POST [$ name])

  if(isset($ _ POST [$ name])&& $ row [$值] == $ _POST [$ name])


Im having trouble with my drop down list menu its keeps getting wamp error. my drop down list menu will be from the itemname of tbl_item(postgresDB)

funcContainer.php page

function DropdownListMenu ($label, $name, $sql, $value, $item, $submit_name, $submit_val)
{
    echo $label."&nbsp;<select name='$name'>";
    $rs = pg_query($sql);
    while ($row = pg_fetch_array($rs, NULL, PGSQL_ASSOC))
    {
        echo "<option value='".$row[$value]."'";
        if ($row[$value] == $_POST[$name])
            echo ' selected';
        echo ">".$row[$item]."</option>";
    }
    echo "</select>&nbsp;";
    echo "<input type='submit' name='".$submit_name."' value='".$submit_val."' />";
}

search.php page

<?php 
require_once("funcContainer.php");
Connect();


$sql = "Select itemid, itemname from tbl_item";
DropdownListMenu ("Select Item", "Item", $sql, 'itemid', 'itemname', "Submit", "Search");?>

tbl_item structure: itemid>itemname>highquantitythreshold>lowquantitythreshold>qpunit>...

wamp error: SCREAM: ERROR suppresion ignored & Undefined Index Item in D:..... can someone please lend me a helping hand here again :) thanks!.

解决方案

On initial page load $_POST[$name] (or more specifically $_POST['Item'] may not be set. So you will want to check if it is set before using.

Change

if ($row[$value] == $_POST[$name])

to

if (isset($_POST[$name]) && $row[$value] == $_POST[$name])

这篇关于如何在php中正确地为我的tbl_item做下拉列表菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆