Link to home
Start Free TrialLog in
Avatar of debtonu sarkar
debtonu sarkar

asked on

C-R-U-D CSV file

I have a csv file. i need to read it which i already done but cannot edit it and also need to delete a particular line....  Can anybody help me for doing this......

the csv file is given bellow
https://drive.google.com/file/d/0B-9jQIuzx-JYYjlBZTFaX3JWN28/view?usp=sharing

and the read code is also given bellow with in table format:
<html>
    <head>
        <title>Reading Form Csv File Training</title>
        <meta charset="UTF-8">
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

    </head>
    <body>
        <div class="container">
            <div class="col-sm-3"><h1>Pages</h1></div>
            <div class="col-sm-3"><a href="index.php"><h2>Web1</h2></a></div>
            <div class="col-sm-3"><a href="p1.php"><h2>web1-fino-al-20170105</h2></a></div>
            <div class="col-sm-3"><a href="p2.php"><h2>web1-fino-al-20151118</h2></a></div>
            <table class="table table-striped">
                <thead>
                <th>No</th>
                <th class="text-center">Data 1</th>
                <th class="text-center">Data 2</th>
                <th class="text-center">Data 3</th>
                <th class="text-center">Data 4</th>
                <th class="text-center">Data 5</th>
                <th class="text-center">Data 6</th>
                <th class="text-center">Data 7</th>
                <th class="text-center">Data 8</th>
                <th class="text-center">Data 9</th>
                <th class="text-center">Data 10</th>
                <th class="text-center">Data 11</th>
                </thead>
                <?php
                $row = 1;
                if (($handle = fopen("csvfile/web1-fino-al-20151118.csv", "r")) !== FALSE) {
                    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
                        $num = count($data);
                       
                        for ($c = 0; $c < $num; $c++) :
             
                            $va = explode(";", $data['0']);
         
                            $cx = 0;
                            ?>
                            <tr>
                                <td class="text-center"><?php echo $row; ?></td>
                                <?php
                                for ($cx = 0; $cx < count($va); $cx++) {
                                    ?>


                                    <td class="text-center"><?php echo $va[$cx]; ?></td>



                                    <?php
                                }
                                ?>
                                <td><button type="button" class="btn btn-warning">Edit</button></td>
                                <td><a href="deletecsvline.php?$data['0']=<?php echo $data['0'] ?>"<button type="button" class="btn btn-danger">X</button></a></td>
                            </tr> 
                            <?php
                        endfor;
                        $row++;
                    }
                    fclose($handle);
                }

                ?>

               
            </table>
        </div>
    </body>
</html>

Open in new window




waiting for help
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Anwar Saiah
Anwar Saiah

You want to edit a spicific line or do you want to open the file for editting?
Please verify that this file contains the CSV, thanks.  It looks like it's not really "comma" separated but actually "semicolon" separated, right?
temp_sarkar.csv
Is there any reason why you want to work off the CSV file and not a database?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial