duanqiu9104 2019-07-16 23:28
浏览 158

如何将Oracle DB中的行正确插入HTML选择框

I am fetching rows from an Oracle table to put them into a select box but the output is not as expected. To give some context, i am querying the database to give me 4 columns of the desired rows to put each row on a single line in the drop menu but instead, i get every column of each row individually on a line. I would like to get help on how i could proceed to have each individual row with their 4 columns on a single line.

This is my oracle table from which i am retrieving data:

create table TP2_ITEM (
    NO_ITEM number generated always as identity,
    NO_ENCAN number(9) not null,
    NO_ITEM_ENCAN_ITE number(9) not null,
    TITRE_ITE varchar2(50) not null,
    CHEMIN_PHOTO_ITE varchar2(200) default 'N/A',
    DESC_ITE varchar2(200) default 'N/A',
    DONATEUR_ITE varchar2(25) not null,
    MNT_VALEUR_ITE number(8,2) not null,
    MNT_PRIX_DEPART_ITE number(8,2) not null,
    MNT_INCREMENT_MINI_ITE number(8,2) not null,
    MNT_ACHAT_IMMEDIAT_ITE number(8,2) not null,
    EST_FERME_ITE number(1) default 0,
    EST_PAYE_ITE number(1) default 0,
    constraint PK_ITEM primary key(NO_ITEM),
    constraint FK_NO_ENCAN1 foreign key(NO_ENCAN)
    references TP2_ENCAN(NO_ENCAN) on delete cascade,
    constraint AK_ENCAN_ITEM unique(NO_ENCAN,NO_ITEM_ENCAN_ITE));

this is the code to fetch my rows and put them into a select box:

<?php 
    $stid = oci_parse($conn, "select I.NO_ITEM, NO_ITEM_ENCAN_ITE, TITRE_ITE, 
                              MNT_VALEUR_ITE from TP2_ITEM I,TP2_ITEM_FAVORI F
                              where NOM_UTILISATEUR = '" .$nom_utilisateur. "' 
                              and F.NO_ITEM = I.NO_ITEM and NO_ENCAN = '" 
                              .implode(',', $no_encan_uti). "'";
    oci_execute($stid);
    echo "<select>";
    while (($row = oci_fetch_array($stid, OCI_ASSOC)) != false {
        foreach ($row as $item) {
            echo "<option>" .$item. "</option>;
        }
    }
    echo "</select>";
    oci_free_statement($Stid);
?>
```[![Output from my program][1]][1]

P.S. I do not have any errors when i run the program but the result is not what i expect, like i described earlier.

**This is an image of the result i get with the drop menu.

  • 写回答

1条回答 默认 最新

  • duan1396 2019-07-17 04:44
    关注

    Assuming that I.NO_ITEM is the identifier, and you want to use that field as the value of the option, and the other three as the text, you can do

    while ($row = oci_fetch_array($stid, OCI_ASSOC) {
    
        $value = $row[0];
        $text = $row[1] . ' ' . $row[2] . ' ' . $row[3];
    
        echo "<option value='$value'>$text</option>"; 
    
    }
    

    You don't need to compare a value to false in a conditional, is enough to use that value as the condition, if it is false the condition fails.

    If you check the code you posted, you will also see that you have two sets of parenthesis around the assignment ((while ($row = oci_fetch_array(...)), but no parethesis after the !=false condition and before the { so your code probably is not running.

    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!