PHP - Php Code Example - Export Table Data
Hello everyone,
I have one humble request and I hope someone here will help me.
Before I start, I have to say that I'm clueless about PHP and I'm in a little rush, so that's why I don't have a lot time to learn about PHP.
My problem is:
- I have a IBM DB2 table on one side, and PHP application on other. DB2 table is like a "temporary" table.
- All data from table has to be inserted into PHP application, which should then send those data to another tables back in DB2, with same types.
I'm trying to automatically insert some values made in MS Excel solution via DB2. Values should be inserted into PHP application and saved, so that user can see those entries done. I'm just trying to eliminate double entering of same data from MS Excel. I believe when values are inserted and saved, all datas will be automatically send to another tables - because application allready does that.
Table data is: _Date_,_Name_,_Start_Time,_End_Time_ (and PHP application has input fields for that)
What I need is just some links to what kind of PHP coding I should use, or maybe even better If someone provides me a simple example. Code should prefferable be generated from a cmd_button in PHP application.
I'm sorry in advance If question is stupid, probably only some export command should be done, but I still need an example of PHP code for that.
I hope I was clear!
Thanks for help !!
Edited by Lukael, 14 October 2014 - 03:15 AM. Similar TutorialsHello, I had page that display results dynamically from the database, I need to export that html table to pdf. Any help? Thanks Hello, I want to export data from php-mysql to excel in a particular cell. 1. Get the data from php-Mysql and export data to excel sheet. I already create a template excel sheet format.I want to export data from mysql to a particular cell. Sorry I can't able to attach my template excel sheet. 2. Is it possible to export image? Thanks in advance Hello All, I am currently working on export to pdf, below is the code, i am able to see the data is getting retrieved from mysql table. I am having 2 issue: 1. When data is getting retrieved one column is on left corner it's now showing the data as it's Sno it gets hidden from left corner. 2. Second issue when i click on the link it's just adding a # tag on the url nothing else.
Please guide me to fix the code.
<!DOCTYPE html> <html> <head> <Title> Export Supplier / Visiters Details</Title> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css"/> <script type="text/javascript" src="tableExport.js"></script> <script type="text/javascript" src="jquery.base64.js"></script> <script type="text/javascript" src="html2canvas.js"></script> <script type="text/javascript" src="jspdf/libs/sprintf.js"></script> <script type="text/javascript" src="jspdf/jspdf.js"></script> <script type="text/javascript" src="jspdf/libs/base64.js"></script> <script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script> </head> <?php $con=mysqli_connect("localhost", "root", "", "cvmsdb"); $qry="SELECT * FROM tblsupvisitor"; $result=mysqli_query($con, $qry); $records = array(); while($row = mysqli_fetch_assoc($result)){ $records[] = $row; } ?> <div class="row" style="height:300px;overflow:scroll;"> <table id="tblsupvisitor" class="table table-striped"> <thead> <tr class="warning"> <th>SNO.</th> <th>Full Name</th> <th>Mobile Number</th> <th>Address</th> </tr> </thead> <tbody> <?php foreach($records as $rec):?> <tr> <td><?php echo $rec['ID']?></td> <td><?php echo $rec['FullName']?></td> <td><?php echo $rec['MobileNumber']?></td> <td><?php echo $rec['Address']?></td> </tr> <?php endforeach; ?> </tbody> </table> </div> <li><a href="#" onclick="$('#tblsupvisitor').tableExport({type:'json',escape:'false'});"> <img src="images/icon/logo.png" width="24px"> Export to Pdf</a></li> <li><a href="#" onclick="$('#tblsupvisitor').tableExport({type:'json',escape:'false'});"><img src="images/icon/logo.png" width="24px">JSON (ignoreColumn)</a></li> </html>
Kind Regards, Naveed. Hi i am new in PHP...have a project and have stuck...please please help.... I have a cart and i need to export the cart contents to excell...here is my code...please take a look and see if u can hepl... I also need to have an export button...and wen pressed the cart will be exported to excell thanks... <?php session_start(); if (!isset($_SESSION["customer"])) { header("location: customer_login.php"); exit(); } //error script error_reporting(E_ALL); ini_set('display_errors','1'); //connect to the database include "../storescripts/connect_to_mysql.php"; ?> <?php /////////////////////////////////////////////////////////////////////////////////// // SECTION ONE /////////////////////////////////////////////////////////////////////////////////// if(isset($_POST['pid'])){ $pid=$_POST['pid']; $wasFound=false; $i=0; //if the cart session is set or empty if(!isset($_SESSION["cart_array"]) || count($_SESSION["cart_array"])< 1){ //Runs if the cart is empty $_SESSION["cart_array"]= array(0 => array("item_id"=>$pid,"quantity"=>1)); }else{ //Runs if the cart has at least one item in it foreach($_SESSION["cart_array"] as $each_item){ $i++; while(list($key,$value)= each($each_item)){ if($key == "item_id"&&$value==$pid){ //the ite is in the cart..hence we adjust the quantity array_splice($_SESSION["cart_array"],$i-1,1,array(array("item_id"=>$pid,"quantity"=>$each_item['quantity']+1))); $wasFound=true; }//close if conditio }//close while loop }//close foreach loop if($wasFound==false){ array_push($_SESSION["cart_array"],array("item_id"=>$pid,"quantity"=>1)); } } header("location: cart.php"); } ?> <?php /////////////////////////////////////////////////////////////////////////////////// // SECTION TWO /////////////////////////////////////////////////////////////////////////////////// //if usser chooses to empty their sopping cart if(isset($_GET['cmd'])&& $_GET['cmd']=="emptycart"){ unset($_SESSION["cart_array"]); } ?> <?php /////////////////////////////////////////////////////////////////////////////////// // SECTION THREE /////////////////////////////////////////////////////////////////////////////////// //if usser chooses to empty their sopping cart if(isset($_POST['item_to_adjust'])&& $_POST['item_to_adjust']!=""){ //execute some code $item_to_adjust=$_POST['item_to_adjust']; $quantity=$_POST['quantity']; $quantity=preg_replace('#[^0-9]#i', '',$quantity); if($quantity >= 1000){$quantity=999;} if($quantity < 1){$quantity= 1;} $i=0; foreach($_SESSION["cart_array"] as $each_item){ $i++; while(list($key,$value)= each($each_item)){ if($key == "item_id"&&$value==$item_to_adjust){ //the ite is in the cart..hence we adjust the quantity array_splice($_SESSION["cart_array"],$i-1,1,array(array("item_id"=>$item_to_adjust,"quantity"=>$quantity))); }//close if conditio }//close while loop }//close foreach loop } ?> <?php /////////////////////////////////////////////////////////////////////////////////// // SECTION FOUR /////////////////////////////////////////////////////////////////////////////////// if(isset($_POST['index_to_remove'])&&$_POST['index_to_remove']!=""){ //access the array and run code to remove $key_to_remove= $_POST['index_to_remove']; if(count($_SESSION["cart_array"])<=1){ unset($_SESSION["cart_array"]); }else{ unset($_SESSION["cart_array"]["$key_to_remove"]); sort($_SESSION["cart_array"]); } } ?> <?php /////////////////////////////////////////////////////////////////////////////////// // SECTION FIVE /////////////////////////////////////////////////////////////////////////////////// $cartOutput=""; $cartTotal=""; if(!isset($_SESSION["cart_array"]) || count($_SESSION["cart_array"])< 1){ $cartOutput="<h2 align='center'>Your Cart Is Empty</h2>"; }else{ $i=0; foreach($_SESSION["cart_array"] as $each_item){ $item_id=$each_item['item_id']; $sql=mysql_query("SELECT * FROM products WHERE id='$item_id' LIMIT 1"); while($row=mysql_fetch_array($sql)){ $product_name=$row["product_name"]; $price=$row['price']; $details=$row['details']; } $pricetotal= $price*$each_item['quantity']; $cartTotal=$pricetotal + $cartTotal; //setlocale(LC_MONETARY,"en_KSHs"); //$pricetotal= money_format("%10.2n", $pricetotal); //dynamic table assembly $cartOutput .="<tr align='center'>"; $cartOutput .='<td><a href="../home.php?id=' . $item_id . '">' .$product_name . '</a><br/><img src="../inventory_images/' . $item_id . '.jpg" alt="' . $product_name . '" width="40" height="52" border="1"/></td>'; $cartOutput .='<td>' . $details . '</td>'; $cartOutput .='<td><form action="cart.php" method="post"> <input name="quantity" type="text" value="' . $each_item['quantity'] . '" size="1" maxlength="3" /> <input name="adjustBtn' . $item_id . '" type="image" value="change" src="../images/buttons/button_save.gif"/> <input name="item_to_adjust" type="hidden" value="' . $item_id . '" /> </form></td>'; //$cartOutput .='<td>' . $each_item['quantity'] . '</td>'; $cartOutput .='<td>' . $price . '</td>'; $cartOutput .='<td>' . $pricetotal . '</td>'; $cartOutput .='<td><form action="cart.php" method="post"> <input name="deleteBtn' . $item_id . '" type="image" value="X" src="../images/buttons/button_delete.gif"/> <input name="index_to_remove" type="hidden" value="' . $i . '" / ></form></td>'; $cartOutput .='</tr>'; $i++; } $cartTotal="<div align='right'>Your Total is KSHs. ".$cartTotal."</div>"; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Your Cart</title> <link rel="stylesheet" href="../style/style.css" type="text/css" media="screen"/> </head> <body> <div align="center" id="mainWrapper"> <?php include_once("../templates/template_header3.php");?> <div id="pageContent"> <div style="margin:24px;text-align:left;"> <br/> <table width="100%" border="1" cellspacing="0" cellpadding="6"> <tr bgcolor="#00FF66" align="center"> <td width="17%" bgcolor="#5BD7D7"><strong>Product</strong></td> <td width="50%" bgcolor="#5BD7D7"><strong>Product Details</strong></td> <td width="7%" bgcolor="#5BD7D7"><strong>Quantity</strong></td> <td width="9%" bgcolor="#5BD7D7"><strong>Unit Price<br/>(KHSs.)</strong></td> <td width="10%" bgcolor="#5BD7D7"><strong>Total<br/>(KHSs.)</strong></td> <td width="7%" bgcolor="#5BD7D7"><strong>Remove</strong></td> </tr> <?php echo $cartOutput; ?> <!-- <tr> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> </tr> --> </table> <?php echo $cartTotal; ?><br/> <br/> <a href="cart.php?cmd=emptycart">Empty Your Cart</a><br/> <a href="cart.php?cmd=export">Export</a><br/> </div> <?php include_once("../templates/template_footer.php");?> </div> </body> </html> I am new in programing. would like some help this is my cart.php file and i would like to export the cart contents into excel...after a user presses a submit button.. Please Please help...thanks I am new in programing. would like some help this is my cart.php file and i would like to export the cart contents into excel...after a user presses a submit button.. Please Please help...thanks This is my code so far:- Code: [Select] <?php session_start(); if (!isset($_SESSION["customer"])) { header("location: customer_login.php"); exit(); } //error script error_reporting(E_ALL); ini_set('display_errors','1'); //connect to the database include "../storescripts/connect_to_mysql.php"; ?> <?php /////////////////////////////////////////////////////////////////////////////////// // SECTION ONE /////////////////////////////////////////////////////////////////////////////////// if(isset($_POST['pid'])){ $pid=$_POST['pid']; $wasFound=false; $i=0; //if the cart session is set or empty if(!isset($_SESSION["cart_array"]) || count($_SESSION["cart_array"])< 1){ //Runs if the cart is empty $_SESSION["cart_array"]= array(0 => array("item_id"=>$pid,"quantity"=>1)); }else{ //Runs if the cart has at least one item in it foreach($_SESSION["cart_array"] as $each_item){ $i++; while(list($key,$value)= each($each_item)){ if($key == "item_id"&&$value==$pid){ //the ite is in the cart..hence we adjust the quantity array_splice($_SESSION["cart_array"],$i-1,1,array(array("item_id"=>$pid,"quantity"=>$each_item['quantity']+1))); $wasFound=true; }//close if conditio }//close while loop }//close foreach loop if($wasFound==false){ array_push($_SESSION["cart_array"],array("item_id"=>$pid,"quantity"=>1)); } } header("location: cart.php"); } ?> <?php /////////////////////////////////////////////////////////////////////////////////// // SECTION TWO /////////////////////////////////////////////////////////////////////////////////// //if usser chooses to empty their sopping cart if(isset($_GET['cmd'])&& $_GET['cmd']=="emptycart"){ unset($_SESSION["cart_array"]); } ?> <?php /////////////////////////////////////////////////////////////////////////////////// // SECTION THREE /////////////////////////////////////////////////////////////////////////////////// //if usser chooses to empty their sopping cart if(isset($_POST['item_to_adjust'])&& $_POST['item_to_adjust']!=""){ //execute some code $item_to_adjust=$_POST['item_to_adjust']; $quantity=$_POST['quantity']; $quantity=preg_replace('#[^0-9]#i', '',$quantity); if($quantity >= 1000){$quantity=999;} if($quantity < 1){$quantity= 1;} $i=0; foreach($_SESSION["cart_array"] as $each_item){ $i++; while(list($key,$value)= each($each_item)){ if($key == "item_id"&&$value==$item_to_adjust){ //the ite is in the cart..hence we adjust the quantity array_splice($_SESSION["cart_array"],$i-1,1,array(array("item_id"=>$item_to_adjust,"quantity"=>$quantity))); }//close if conditio }//close while loop }//close foreach loop } ?> <?php /////////////////////////////////////////////////////////////////////////////////// // SECTION FOUR /////////////////////////////////////////////////////////////////////////////////// if(isset($_POST['index_to_remove'])&&$_POST['index_to_remove']!=""){ //access the array and run code to remove $key_to_remove= $_POST['index_to_remove']; if(count($_SESSION["cart_array"])<=1){ unset($_SESSION["cart_array"]); }else{ unset($_SESSION["cart_array"]["$key_to_remove"]); sort($_SESSION["cart_array"]); } } ?> <?php /////////////////////////////////////////////////////////////////////////////////// // SECTION FIVE /////////////////////////////////////////////////////////////////////////////////// $cartOutput=""; $cartTotal=""; if(!isset($_SESSION["cart_array"]) || count($_SESSION["cart_array"])< 1){ $cartOutput="<h2 align='center'>Your Cart Is Empty</h2>"; }else{ $i=0; foreach($_SESSION["cart_array"] as $each_item){ $item_id=$each_item['item_id']; $sql=mysql_query("SELECT * FROM products WHERE id='$item_id' LIMIT 1"); while($row=mysql_fetch_array($sql)){ $product_name=$row["product_name"]; $price=$row['price']; $details=$row['details']; } $pricetotal= $price*$each_item['quantity']; $cartTotal=$pricetotal + $cartTotal; //setlocale(LC_MONETARY,"en_KSHs"); //$pricetotal= money_format("%10.2n", $pricetotal); //dynamic table assembly $cartOutput .="<tr align='center'>"; $cartOutput .='<td><a href="../home.php?id=' . $item_id . '">' .$product_name . '</a><br/><img src="../inventory_images/' . $item_id . '.jpg" alt="' . $product_name . '" width="40" height="52" border="1"/></td>'; $cartOutput .='<td>' . $details . '</td>'; $cartOutput .='<td><form action="cart.php" method="post"> <input name="quantity" type="text" value="' . $each_item['quantity'] . '" size="1" maxlength="3" /> <input name="adjustBtn' . $item_id . '" type="image" value="change" src="../images/buttons/button_save.gif"/> <input name="item_to_adjust" type="hidden" value="' . $item_id . '" /> </form></td>'; //$cartOutput .='<td>' . $each_item['quantity'] . '</td>'; $cartOutput .='<td>' . $price . '</td>'; $cartOutput .='<td>' . $pricetotal . '</td>'; $cartOutput .='<td><form action="cart.php" method="post"> <input name="deleteBtn' . $item_id . '" type="image" value="X" src="../images/buttons/button_delete.gif"/> <input name="index_to_remove" type="hidden" value="' . $i . '" / ></form></td>'; $cartOutput .='</tr>'; $i++; } $cartTotal="<div align='right'>Your Total is KSHs. ".$cartTotal."</div>"; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Your Cart</title> <link rel="stylesheet" href="../style/style.css" type="text/css" media="screen"/> </head> <body> <div align="center" id="mainWrapper"> <?php include_once("../templates/template_header3.php");?> <div id="pageContent"> <div style="margin:24px;text-align:left;"> <br/> <table width="100%" border="1" cellspacing="0" cellpadding="6"> <tr bgcolor="#00FF66" align="center"> <td width="17%" bgcolor="#5BD7D7"><strong>Product</strong></td> <td width="50%" bgcolor="#5BD7D7"><strong>Product Details</strong></td> <td width="7%" bgcolor="#5BD7D7"><strong>Quantity</strong></td> <td width="9%" bgcolor="#5BD7D7"><strong>Unit Price<br/>(KHSs.)</strong></td> <td width="10%" bgcolor="#5BD7D7"><strong>Total<br/>(KHSs.)</strong></td> <td width="7%" bgcolor="#5BD7D7"><strong>Remove</strong></td> </tr> <?php echo $cartOutput; ?> <!-- <tr> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> </tr> --> </table> <?php echo $cartTotal; ?><br/> <br/> <a href="cart.php?cmd=emptycart">Empty Your Cart</a><br/> </div> </div> <?php include_once("../templates/template_footer.php");?> </div> </body> </html> Hi all - new here so please be gentle! I have a html table generated from php and am using a script I found on the net to export it to csv. The problem is, the exported csv file stops at the 2nd column and never starts a new row, plus has an empty column at the end. Obviously i want several rows (depending on the mysql query used to populate the table, it could be tens of rows long.) Is any one please able to help me shed some light as to what's going wrong? Thanks <table class="statistics"> <thead> <tr><th> Name </th><th> </th><th> Date </th></tr> </thead> <tbody> <?php if( $page['reportByDate'] ) { ?> <?php foreach( $page['reportByDate'] as $row ) { ?> <tr> <td><?php echo $row['name'] ?></td> <td><?php echo $row['email'] ?></td> <td><?php echo $row['date'] ?></td> </tr> <?php } ?> <?php } else { ?> <?php } ?> </tbody> </table> <?php } ?> <? $csv_hdr = "Name, Email, Date"; $csv_output .= $row['name'] . ", "; $csv_output .= $row['email'] . ", "; $csv_output .= $row['date'] . ", "; $csv_output .= $row['value'] . "\n"; //ensure the last column entry starts a new line ?> <? ?> <br /> <center> <form name="export" action="export.php" method="post"> <input type="submit" value="Save as CSV"> <input type="hidden" value="<? echo $csv_hdr; ?>" name="csv_hdr"> <input type="hidden" value="<? echo $csv_output; ?>" name="csv_output"> </form> </center> <?php /* This file will generate our CSV table. There is nothing to display on this page, it is simply used to generate our CSV file and then exit. That way we won't be re-directed after pressing the export to CSV button on the previous page. */ //First we'll generate an output variable called out. It'll have all of our text for the CSV file. $out = ''; //Next we'll check to see if our variables posted and if they did we'll simply append them to out. if (isset($_POST['csv_hdr'])) { $out .= $_POST['csv_hdr']; $out .= "\n"; } if (isset($_POST['csv_output'])) { $out .= $_POST['csv_output']; } //Now we're ready to create a file. This method generates a filename based on the current date & time. $filename = $file."_".date("Y-m-d_H-i",time()); //Generate the CSV file header header("Content-type: application/vnd.ms-excel"); header("Content-disposition: csv" . date("Y-m-d") . ".csv"); header("Content-disposition: filename=".$filename.".csv"); //Print the contents of out to the generated file. print $out; //Exit the script exit; ?> Hi All, As we know........to export excel sheet the database content....we query the data base and then process the result and using Workbook and header we export the result in excel.................. Is there any way we can reduce the down load time or increase the performance for same. ? Thanks. I am trying to export a dynamically created table (one that has been filtered from user inputs) into a csv file format. I have simplified the database and code for ease of use. I also have generated the export file which will extract all information from the table in the database, but I need the information that is filtered by the user to be extracted. Files are shown below. How might I modify my export.php file (or other files) to accomplish this? Thanks in Advance export.php <?php include 'config.php'; $table = 'user'; $file = 'export'; $result = mysql_query("SHOW COLUMNS FROM ".$table.""); $i = 0; if (mysql_num_rows($result) > 0) { while ($row = mysql_fetch_assoc($result)) { $csv_output .= $row['Field'].", "; $i++; } } $csv_output .= "\n"; $values = mysql_query("SELECT * FROM ".$table.""); while ($rowr = mysql_fetch_row($values)) { for ($j=0;$j<$i;$j++) { $csv_output .= $rowr[$j].", "; } $csv_output .= "\n"; } $filename = $file."_".date("Y-m-d_H-i",time()); header("Content-type: application/vnd.ms-excel"); header("Content-disposition: csv" . date("Y-m-d") . ".csv"); header( "Content-disposition: filename=".$filename.".csv"); print $csv_output; exit; ?> config.php <?php $con = mysql_connect('localhost', 'root', ''); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("test", $con); ?> index.php <?php include('config.php'); //Include the database connections in it's own file, for easy integration in multiple pages. $lastname_result = mysql_query("SELECT lastname FROM user GROUP BY lastname"); $result = mysql_query("SELECT * FROM user"); ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <link href="start/jquery-ui-1.8.4.custom.css" rel="stylesheet" type="text/css"/></link> <link href="../themes/style.css" rel="stylesheet" type="text/css" media="print, projection, screen" /></link> <link href="../common.css" rel="stylesheet" type="text/css"></link> <script type="text/javascript" src="jquery-1.4.2.min.js"></script> <script type="text/javascript" src="jquery.tablesorter.js"></script> <script type="text/javascript" src="jquery-ui-1.8.4.custom.min.js"></script> <script type="text/javascript"> $(document).ready(function() { $("#myTable").tablesorter({widgets: ['zebra']}); $("#options").tablesorter({sortList: [[0,0]], headers: { 3:{sorter: false}, 4:{sorter: false}}}); } ); function reSort(par) { $("#tableBody").empty(); var vfrom = document.getElementById('from').value; var vto = document.getElementById('to').value; $.get('table.list.php?from='+vfrom+'&to='+vto+'&lastname='+par,function(html) { // append the "ajax'd" data to the table body $("#tableBody").append(html); // let the plugin know that we made a update $("#myTable").trigger("update"); // set sorting column and direction, this will sort on the first and third column var sorting = [[0,0]]; // sort on the first column $("#myTable").trigger("sorton",[sorting]); }); } function getNames() { var vfrom = document.getElementById('from').value; var vto = document.getElementById('to').value; $("#selectbox").empty(); $.get('select.list.php?from='+vfrom+'&to='+vto,function(html) { $("#selectbox").append(html); }); } </script> </head> <body> <table width="100%" border="0" cellspacing="0" cellpadding="5" class="main"> <tr> <td width="160" valign="top"></td> <td width="732" valign="top"> <table width="90%" border="0" align="center"> <form method="post"> <label for="from">From</label> <input type="text" id="from" name="from" onkeyup="getNames();"/> <label for="to">to</label> <input type="text" id="to" name="to" onkeyup="getNames();"/> <select id="selectbox" name="area" onchange="reSort(this.value);"> <option value="">Select an lastname</option> <option value=""></option> <?php while(list($lastname)=mysql_fetch_array($lastname_result)) { echo "<option value='$lastname'>$lastname</option>"; } ?> </select> </form> <form action="export.php"> <input type="Submit" value="Export to Excel"></input> </form> </table> <table id="myTable" class="tablesorter" border="0" cellpadding="5" cellspacing="1"> <thead> <tr> <th>First Name</th> <th>Last Name</th> <th>Age</th> <th>Birthday</th> <th>Hometown</th> <th>Job</th> </tr> </thead> <tbody id="tableBody"> <?php //added id to the tbody so we could change the content via javascript ?> </tbody> </table> <p> </p> <p> </p> <p align="right"> </p> </td> <td width="196" valign="top"> </td> </tr> </table> </body> </html> select.list.php <?php include('config.php'); //database connections. if(!isset($_GET['to']) && !isset($_GET['from'])) { //if the uri parameters are not there send em to google. header('Location: http://google.com'); exit(); } $from = (isset($_GET['from'])) ? date('Y-m-d',strtotime($_GET['from'])) : NULL; $to = (isset($_GET['to'])) ? date('Y-m-d',strtotime($_GET['to'])) : NULL; if($from != NULL && $to != NULL) { $where = " WHERE birthdate BETWEEN '$from' AND '$to'"; } elseif($from != NULL) { $where = " WHERE birthdate >= '$from'"; } elseif($to != NULL) { $where = " WHERE birthdate <= '$to'"; } $query = "SELECT lastname FROM user $where GROUP BY lastname"; //write the query. //echo $query; $lastname_result = mysql_query($query) or die($query . ' ' . mysql_error()); //execute the query, or die trying. echo '<option value="">Select an lastname</option> <option value=""></option> '; while(list($lastname)=mysql_fetch_array($lastname_result)) { echo "<option value='$lastname'>$lastname</option>"; } ?> table.list.php <?php include('config.php'); //database connection. if(!isset($_GET['lastname'])) { //if the proper get parameter is not there, redirect to google. header('Location: http://google.com'); exit(); } $lastname = preg_replace('~[^A-Za-z]+~','',$_GET['lastname']); //strip out anything but alpha for the name. $lastname = trim($lastname); //trim the name from all whitespace. if($lastname != '') { //check against an empty string. could have just used "empty()". $where = ' WHERE lastname = \'' . $lastname . '\''; //write the where clause. } else { //if lastname is empty, the where clause will be to, and it will return all names. $where = NULL; unset($lastname); } $from = (isset($_GET['from'])) ? date('Y-m-d',strtotime($_GET['from'])) : NULL; $to = (isset($_GET['to'])) ? date('Y-m-d',strtotime($_GET['to'])) : NULL; if($from != NULL && $to != NULL) { $where .= (isset($lastname)) ? ' AND ' : ' WHERE '; $where .= " birthdate BETWEEN '$from' AND '$to'"; } elseif($from != NULL) { $where .= (isset($lastname)) ? ' AND ' : ' WHERE '; $where .= " birthdate >= '$from'"; } elseif($to != NULL) { $where .= (isset($lastname)) ? ' AND ' : ' WHERE '; $where .= " birthdate <= '$to'"; } $query = "SELECT * FROM user $where"; $result = mysql_query($query); //get the database result. while($row=mysql_fetch_assoc($result)){ //loop and display data. ?> <tr> <td><?php echo $row['firstname']; ?></td> <td><?php echo $row['lastname']; ?></td> <td><?php echo $row['age']; ?></td> <td><?php echo $row['birthdate']; ?></td> <td><?php echo $row['hometown']; ?></td> <td><?php echo $row['job']; ?></td> </tr> <?php } // End while loop. ?> sql code Code: [Select] create table `user` ( `id` double , `firstname` varchar (60), `lastname` varchar (24), `age` double , `hometown` varchar (75), `job` varchar (75), `birthdate` date ); insert into `user` (`id`, `firstname`, `lastname`, `age`, `hometown`, `job`, `birthdate`) values('1','Peter','Griffin','41','Quahog','Brewery','1960-01-01'); insert into `user` (`id`, `firstname`, `lastname`, `age`, `hometown`, `job`, `birthdate`) values('2','Lois','Griffin','40','Newport','Piano Teacher','1961-08-11'); insert into `user` (`id`, `firstname`, `lastname`, `age`, `hometown`, `job`, `birthdate`) values('3','Joseph','Swanson','39','Quahog','Police Officer','1962-07-23'); insert into `user` (`id`, `firstname`, `lastname`, `age`, `hometown`, `job`, `birthdate`) values('4','Glenn','Quagmire','41','Quahog','Pilot','1960-02-28'); insert into `user` (`id`, `firstname`, `lastname`, `age`, `hometown`, `job`, `birthdate`) values('5','Megan','Griffin','16','Quahog','Student','1984-04-24'); insert into `user` (`id`, `firstname`, `lastname`, `age`, `hometown`, `job`, `birthdate`) values('6','Stewie','Griffin','2','Quahog','Dictator','2008-03-03'); Hi Guys.... I need to export data into excel file. So far its works on IE and Firefox. But if i using Google Chrome it download only php file. Eg(suppose file test.xls but it goes to test.php). Why it happen?? I'm trying to have a running total of the number of views an image gets. My test file works perfectly every time. The actual file, image_win.php, does not and after much testing can't see what's wrong. This files STRANGENESS: the first two views count fine, with 1 added the total in the field image_visit. But every time after that 2 is added to the total in image_visit. Very bizarre. Thanks for taking a look -Allen Code: [Select] <?php ////////TEST IMAGE_WIN //////////THIS WORKS include_once "scripts/connect_to_mysql.php"; include_once "scripts/paths.php"; $art_id = 372; $QUERY="SELECT user_id FROM artWork WHERE art_id = '$art_id'"; $res = mysql_query($QUERY); $num = mysql_num_rows($res); if($num >0){ while($row = mysql_fetch_array($res)){ $owner_id = $row['user_id']; } } mysql_query("UPDATE userInfo SET image_visit = image_visit +1 WHERE user_id = '$owner_id'"); ?> <?php //////// image_win.php /////////THIS DOES NOT WORK $user_id=$_SESSION['user_id']; include_once "scripts/connect_to_mysql.php"; include_once "scripts/paths.php"; $image_link = $_GET['image_link']; $art_id = $_GET['art_id']; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="viewport" content="width=device-width, height=device-height, target-densityDpi=device-dpi"> <title>Image Window</title> </head> <body bgcolor="#000000" leftmargin="0"> <div align="center" > <img src="slir/w640-h535/<?php echo $path.$image_link.$postCat; ?>" /> <?php $QUERY="SELECT user_id FROM artWork WHERE art_id = '$art_id'"; $res = mysql_query($QUERY); $num = mysql_num_rows($res); if($num >0){ while($row = mysql_fetch_array($res)){ $owner_id = $row['user_id']; } } mysql_query("UPDATE userInfo SET image_visit = (image_visit +1) WHERE user_id = '$owner_id' "); ?> MOD EDIT: code tags added. Hello to all, I have problem figuring out how to properly display data fetched from MySQL database in a HTML table. In the below example I am using two while loops, where the second one is nested inside first one, that check two different expressions fetching data from tables found in a MySQL database. The second expression compares the two tables IDs and after their match it displays the email of the account holder in each column in the HTML table. The main problem is that the 'email' row is displayed properly while its while expression is not nested and alone(meaning the other data is omitted or commented out), but either nested or neighbored to the first while loop, it is displayed horizontally and the other data ('validity', 'valid_from', 'valid_to') is not displayed.'
Can someone help me on this, I guess the problem lies in the while loop? <thead> <tr> <th data-column-id="id" data-type="numeric">ID</th> <th data-column-id="email">Subscriber's Email</th> <th data-column-id="validity">Validity</th> <th data-column-id="valid_from">Valid From</th> <th data-column-id="valid_to">Valid To</th> </tr> </thead> Here is part of the PHP code:
<?php while($row = $stmt->fetch(PDO::FETCH_ASSOC)) { echo ' <tr> <td>'.$row["id"].'</td> '; while ($row1 = $stmt1->fetch(PDO::FETCH_ASSOC)) { echo ' <td>'.$row1["email"].'</td> '; } if($row["validity"] == 1) { echo '<td>'.$row["validity"].' month</td>'; }else{ echo '<td>'.$row["validity"].' months</td>'; } echo ' <td>'.$row["valid_from"].'</td> <td>'.$row["valid_to"].'</td> </tr>'; } ?>
Thank you. I can add and delete data from my table. Now I need to be able to change one or more fields in an entry. So I want to retrieve a row from the db, display that data on a form where the user can change any field and then pass the changed data to an update.php program. I know how to go from form to php. But how do I pass the data from retrieve.php to a form so it will display? Do I use a URL and Get? Can I put the retrieve and form in the same program? Hey everyone. I am creating a website so my family can select from the list of present my daugther has asked for. I have them logging in, and that works. I have the table data set and the search and table display works. But I would like to display the list (as in the code below) but with a checkbox in the first column (add a column). From that the authenticated user can click on the item they have purchased and that selection will be moved to another table (called purchased). I have that code. The only thing I cannot figure out is to present the data in list form with a checkbox (like you would see on an order form). Here is the display code (there is no error checking at this point): <head><LINK REL="SHORTCUT ICON" HREF="cmwschl.ico"></head> <body bgcolor="#C0C0C0"> <font face="Arial" color="#000080">Books from the Selected Series</font> </h1> <hr font color="Navy" font size="3"> <center> <table border="1" cellpadding="5" cellspacing="0" bordercolor="#000000"> <tr> <td width="170" bgcolor="#FFCC66"><center><b><font color="navy" size="2" face="Trebuchet MS"><b><center>Book Number</center></font></b></center></td> <td width="140" bgcolor="#FFCC66"><center><b><font color="navy" size="2" face="Trebuchet MS"><b><center>Book Group</center></font></b></center></td> <td width="100" bgcolor="#FFCC66"><center><b><font color="navy" size="2" face="Trebuchet MS"><b><center>Book Title</center></font></b></center></td> </tr> <?php $con = mysql_connect("localhost","twilson","R00tb33r!") or die('Connection: ' . mysql_error());; mysql_select_db("CMWWeb", $con) or die('Database: ' . mysql_error()); ?> <? $group = $_POST['bookgrp']; //if ($Prod <> 0) { $sql = "SELECT * FROM `OpenBooks` WHERE `bookgrp`= '$group'"; $results = mysql_query($sql); if ($results) { //this will check if the query failed or not if (mysql_num_rows($results) > 0) { //this will check if results were returned while($copy = mysql_fetch_array($results)) { $variable1=$copy['booknum']; $variable2=$copy['bookgrp']; $variable3=$copy['booktitle']; //table layout for results print ("<tr>"); print ("<td><center>$variable1</center></td>"); print ("<td><center>$variable2</center></td>"); print ("<td><left>$variable3</left></td>"); print ("</tr>"); } } else { echo "No results returned"; } } else { echo "Query error: ".mysql_error(); } mysql_close($con); ?> </table> </center> hello friends I'm dealing with this problem for two days. I put here the screenshot for easier understanding.Sorry about my bad english. Here is the ss http://i61.tinypic.com/2rz5q55.jpg I don't want to inner join or table join. All image links which same sku should displayed in single row where products.resimler colon I can join the tables but i want to one table.Because i can import single csv file for e-commerce script.How can I use a update query for list multiple images in table products. Edited by nogai, 10 October 2014 - 07:01 AM. the second database found on the cloud
i try to get JSON data but how to insert and update them to another online database with the same table my php script to return json data <?php include_once('db.php'); $users = array(); $users_data = $db -> prepare('SELECT id, username FROM users'); $users_data -> execute(); while($fetched = $users_data->fetch()) { $users[$fetchedt['id']] = array ( 'id' => $fetched['id'], 'username' => $fetched['name'] ); } echo json_encode($leaders);
i get
{"1":{"id":1,"username":"jeremia"},"2":{"id":2,"username":"Ernest"}} Edited March 24 by mahenda Hi all I am describing my problem below can any body please look into this I have two databases DB1:datain1 DB2:datain2 having the below structure database, table, fields datain1 , student , id,name datain2 , student , id,name the two databases having same structure My query is i want copy all data from datain1 to datain2 on daily process through php script(script will be executed manually on daily) i don't want any duplicate or repeated data in datain2 give me some script to do this kindly help me to solve this its so urgent What I'm wanting to do is instead of March-July have it always display the last 5 months and for the Visits th have it display the number of hits to my main page for each month and display the number of logins for each month to my CMS script. Can someone point me in the right direction? Code: [Select] <?php function get_visit_data_table() { echo "<table class=\"visualize_dashboard\">"; echo "<caption>Dashboard Chart Example</caption>"; echo "<thead>"; echo "<tr>"; echo "<td></td>"; echo "<th scope=\"col\">March</th>"; echo "<th scope=\"col\">April</th>"; echo "<th scope=\"col\">May</th>"; echo "<th scope=\"col\">June</th>"; echo "<th scope=\"col\">July</th>"; echo "</tr>"; echo "</thead>"; echo "<tbody>"; echo "<tr>"; echo "<th scope=\"row\">Visits</th>"; echo "<td>175</td>"; echo "<td>145</td>"; echo "<td>212</td>"; echo "<td>175</td>"; echo "<td>182</td>"; echo "</tr>"; echo "<tr>"; echo "<th scope=\"row\">Logins</th>"; echo "<td>94</td>"; echo "<td>53</td>"; echo "<td>124</td>"; echo "<td>92</td>"; echo "<td>105</td>"; echo "</tr>"; echo "</tbody>"; echo "</table>"; } ?> First I need to create a table or add to an existing table - the table needs to contain a date -msg last sent date Then run the following email script for each record if the value of the msg last sent date is greater than >30 days??? after the script is run, it updates the records it emailed to todays date... <?php include "vsadmin/db_conn_open.php"; $allprods=mysql_query("select pID, pName, pPrice, pDropship, dsID, dsName, dsEmail from products, dropshipper where pDropship = dsID"); while ($yarr=mysql_fetch_assoc($allprods)){ $aname=$yarr["pID"]; $bname=$yarr["pName"]; $cname=$yarr["dsName"]; $dname=$yarr["dsEmail"]; $ename=$yarr["pPrice"]; $to = $dname; $subject = ("Your Ebook: " . $bname); $body = ("Hello " . $cname .",\n\nYou have the following ebook listed for sale on www.insertwebsite.com (". $bname ."). \nYour Ebook (product) is currently listed at the retail price of $" . $ename . "\n\nThe following link is provided to you as a marketing tool for your current or future email campaigns. This link is a direct link to your ebook on the Enlightened Ebooks site. \n www.www.insertwebsite.com/proddetail.php?prod=". $aname . "\n\nOnline sales is a safe secure way to increase your ebook sales. Simply provide the link in all your correspondences and you sales will increase. You are your own best promoter."); $headers = "From: neil@me.com\r\n" . "X-Mailer: php"; if (mail($to, $subject, $body, $headers)) { echo("<p><b>Message sent to.</b></P>". $cname . " for the following ebook " . $bname ); } else { echo("<p>Message delivery failed...</p>"); }} ?> Hi,
A little new to php programming... I have a question:
I have written this code:
<html> <head> <title>Test</title> </head> <FONT FACE="Verdana, sans-serif"> <H3>Movies</h3> <?php include 'config.php'; include 'opendb.php'; $result = mysql_query("SELECT * FROM DayMovie ORDER BY FileDate") or die(mysql_error()); echo "<table border='1'>"; echo "<tr> <th>Filename</th><th>Path</th><th>Date</th><th>Filetype</th> <th>Size</th></tr>"; // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table echo "<tr><td>"; echo $row['FileName']; echo "</td><td>"; echo $row['FilePath']; echo "</td><td>"; echo $row['FileDate']; echo "</td><td>"; echo $row['FileType']; echo "</td><td>"; echo $row['FileSize']; echo "</td></tr>"; } echo "</table>"; include 'closedb.php'; ?>I would like to have a link to these files on all the rows to open the files. How can I do that? I would also like that the link from the mysql row is not shown in the table. Only a text with the text "link" or "view". |