简体   繁体   中英

How do I prevent my php from displaying a column from csv file?

This is a script I'm working on that parses a CSV file and dynamically generates an HTML table with the data it receives.

How can I get the script to ignore the InputID column when outputting the data to HTML, as shown in the example CSV?

I still need access to the values in the third column, but I don't want them displayed in my HTML output.

Item,Price,InputID
Apple,10,1
Orange,8,2
Banana,12,3

$a = 1;
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
    $name = $data[0];
    $quanid = $data[2];
    //generate HTML
    echo('<tr>');
    foreach ($data as $index=>$val) {
        echo('<td>');
        echo htmlentities($val, ENT_QUOTES);
        echo('</td>');
    }
    echo('<td>
        <button class="toggler" data-prod-cat="' . $cssId . '">Vote</button>
    </td>');
    echo('</tr>');
    echo('<tr class="cat' . $cssId . ' hidden" style="display:none">');
    echo('<td colspan="4" style="white-space: nowrap">Enter ' . $name . ' Price:
    <input type="text" maxlength="4" name="' . $quanid . '" value="" class="input" />&nbsp;
    <button class="submit" type="submit" value="Submit">Submit</button>
    </td>
    </tr>');
    $cssId = 'row-'.$a;
    $a++;

try like this,

unset($data[2])

after getting value...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM