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
PHP

Avatar of undefined
Last Comment
Ray Paseur

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Ray Paseur

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Anwar Saiah

You want to edit a spicific line or do you want to open the file for editting?
Ray Paseur

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
Julian Hansen

Is there any reason why you want to work off the CSV file and not a database?
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
SOLUTION
Ray Paseur

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.