We help IT Professionals succeed at work.

C-R-U-D CSV file

debtonu sarkar
on
655 Views
Last Modified: 2018-12-14
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
Comment
Watch Question

Most Valuable Expert 2011
Author of the Year 2014
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION
CERTIFIED EXPERT

Commented:
You want to edit a spicific line or do you want to open the file for editting?
Most Valuable Expert 2011
Author of the Year 2014

Commented:
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
CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2019

Commented:
Is there any reason why you want to work off the CSV file and not a database?
Most Valuable Expert 2011
Author of the Year 2014
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION
gr8gonzoConsultant
CERTIFIED EXPERT
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION
Most Valuable Expert 2011
Author of the Year 2014
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions