csv with php

In our earlier article, we have provided the demo with code for UI Data Base using Google spread sheet as back-end to show user interactive HTML form. Whereas in this article, we use CSV file as database and php as link code to get the required data. we are giving the source code. The following is source code for the given demo interactive sheet.

Nakshatra - Guna table
Enter Guna:                    

Three files are required for this script. And the three file source codes are given below.
  1. HTML File (link.html): This is the simple form where one can enter query to get the required output. You may design whatever manner you like or make stylish look.
  2. PHP File (link.php) : This is the back-end script to get the data with regards to the input entered in the html form. You may design this php code, if you require in more friendly manner.
  3. CSV File (link.csv): This is simple csv file (like excel file)where the total data is stored.
affiliate_link
HTML CODE (link.html)
<html> <head> </head> <body> <form method="post" name="demo form" action="link.php"> Enter Guna: <select name="name"> <option>Deva</option><option>Manushya</option> <option>Raksha</option> .................. .................. </select><br /> <input type="submit" name='submit' onclick="show_confirm()" value="SUBMIT"> &nbsp;&nbsp;&nbsp;<input type="reset" value="CLEAR"> </form> </body> </html>

PHP CODE (link.php)
<!--php if(!isset($_POST['submit'])) { //This page should not be accessed directly. Need to submit the form. exit; } $k = $_POST['name']; $handle = fopen("link.csv","r")or die("file dont exist"); $output = ''; while (!feof($handle )){ $data = fgetcsv($handle,4096,","); if(($data[2] ==$k)){ $output .= sprintf( "Against: %s ", $data[0]); $output .= sprintf( "; Venue: %s ", $data[2]); $output .= sprintf( "; on : %s <br-->", $data[8]); $output .= sprintf( "Sachin scored total runs: %d ", $data[4]); $output .= sprintf( "; Against Balls: %d <br>", $data[3]); $output .= sprintf( "No Of Fours: %d ", $data[5]); $output .= sprintf( "; & Sixs: %d ", $data[6]); $output .= sprintf( "; Position: %s <br><br>", $data[7]); } } echo "<span style='color: #abc123; font-weight: bold;'> SACHIN CRICKET SCORES DETAILS <br /> Where data checked with- <u>Venue:$k </u> </span> <br /><br />"; echo $output; fclose($handle); ?>

CSV File in following format (link.csv)
Nakshatra Lord Yoni Guna Presiding Diety
Ashwini Ketu Horse Deva Ashwini Kumar
Bhairini Venus Elephant Manushya Yama
Krittika Sun Goat Rakshasa Agni
Rohini Moon Serpent Manushya Brahma
Mrigasira Mars Serpent Deva Soma
Ardra Rahu Dog Manushya Rudra
PunarVasu Jupiter Cat Deva Aditi
Pushya Saturn Goat Deva Brihaspati

No comments:

Click Here To add Comment

Post a Comment