callingrohit
New Members-
Posts
9 -
Joined
-
Last visited
Never
Profile Information
-
Gender
Not Telling
callingrohit's Achievements
Newbie (1/5)
0
Reputation
-
Hi everyone, I have a form with checkbox input and the data is stored into a MYSQL table. So I serialize this checkbox data before inserting it into the database. Now I also export the data with a click of a button into a spreadsheet. The data in the mysql table looks like this [b]a:3:{i:0;s:3:"uno";i:1;s:3:"dos";i:2;s:4:"tres";}[/b] I was wondering if its possible to modify the above data to just [b]uno,dos,tres[/b] and then insert it into my excel table. Thanks cheers rohit
-
Exporting 2 MySQL tables into an Excel Spreadsheet
callingrohit replied to callingrohit's topic in PHP Coding Help
hi talreja_sapna, thanks for your reply. I'm not sure what you meant by schema of the tables ??? Did you mean the structure ??? both the tables 1 & 2 will have different stuff in them for example - Table 1 can contain a person's general information like name, address, city etc. and Table 2 can contain their hobbies and interests. cheers rohit -
Hi All, I know how to export one table into an excel spreadsheet, but what I would like to do is export 2-3 tables in one spreadsheet instead of having sep spreadsheets for all my tables. So suppose Table1 has 5 fields and Table2 has 3 fields.....each of them will have ID...not sure how to avoid that from coming in the spreadsheet for Table2 since ID will come from Table1 ??? Anyways, so on spreadsheet what I would like is this //field1 to 5 are headers from Table1 & field-1-2-3 are from Table2 field1 field2 field3 field4 field5 field-1 field-2 field-3 data data data data data data data data Is this possible ??? here is the code for exporting just one table into the spreadsheet... [code] <?php header("Content-type: application/vnd.ms-excel"); header("Content-Disposition: attachment; filename=spreadsheet.xls"); header("Pragma: no-cache"); header("Expires: 0"); define(db_host, "your_hostname"); define(db_user, "your_username"); define(db_pass, "your_password"); define(db_link, mysql_connect(db_host,db_user,db_pass)); define(db_name, "your_database_name"); mysql_select_db(db_name); $select = "SELECT * FROM your_tablename"; $export = mysql_query($select); $fields = mysql_num_fields($export); for ($i = 0; $i < $fields; $i++) { $header .= mysql_field_name($export, $i) . "\t"; } while($row = mysql_fetch_row($export)) { $line = ''; foreach($row as $value) { if ((!isset($value)) OR ($value == "")) { $value = "\t"; } else { $value = str_replace('"', '""', $value); $value = '"' . $value . '"' . "\t"; } $line .= $value; } $data .= trim($line)."\n"; } $data = str_replace("\r","",$data); if ($data == "") { $data = "\n(0) Records Found!\n"; } // print the db echo "$header \n $data" ; ?> [/code] cheers rohit
-
Storing Checkbox & other text data into MYSQL Database
callingrohit replied to callingrohit's topic in PHP Coding Help
Hi, I solved the problem by combining the 2 insert statements and so now my code looked like this [code] <snip> $type_transport=serialize($_POST['type_transport']); $insertquery = "INSERT INTO $table (id,name,email,opinion,type_transport) VALUES('$id','$name','$email','$opinion','$type_transport')"; $results_1 = mysql_query($insertquery); <snip> [/code] Now, all the data has reached properly into the appropriate columns. If I were to display the items back onto HTML, I do know I would have to choose UNSERIALIZE but would it come in a single row as in if I chose multiple options - car, walk, other. When displayed onto the HTML - will it come out under the column "TYPE of TRANSPORT" as car,walk,other or would that be on 3 different rows ??? Also, could you please tell me what does this statement do? ?? --- TYPE=MyISAM AUTO_INCREMENT=8 ; cheers vivek -
Storing Checkbox & other text data into MYSQL Database
callingrohit replied to callingrohit's topic in PHP Coding Help
hi daniel, I tried something here.... I changed my code like you said with serialization and it looks like this [code] <snip> $sqlquery = "INSERT INTO $table VALUES('$id','$name','$email','$opinion')"; $results = mysql_query($sqlquery); $type_transport=serialize($_POST['type_transport']); //type_transport is the checkbox field and is an array $insertquery = "INSERT INTO $table (type_transport) VALUES('$type_transport')"; $results_1 = mysql_query($insertquery); [/code] Once done, I check my database table and this is what I get (I exported the single row as a SQL file ---displayed below) [code] -- -- Table structure for table `information` -- CREATE TABLE `information` ( `id` int(11) NOT NULL auto_increment, `name` varchar(50) default NULL, `email` varchar(50) default NULL, `opinion` varchar(30) default NULL, `type_transport` varchar(70) default NULL, PRIMARY KEY (`id`) ) TYPE=MyISAM AUTO_INCREMENT=8 ; -- -- Dumping data for table `information` -- INSERT INTO `information` VALUES (7, NULL, NULL, NULL, 'a:1:{i:0;s:3:"car";}'); //car is the correct checkbox which I had checked but why didn't the name,email and opinion fields get populated ????? [/code] cheers vivek -
Storing Checkbox & other text data into MYSQL Database
callingrohit replied to callingrohit's topic in PHP Coding Help
Thanks for your reply daniel. I've used php but i'm very new with mysql and php. I know you wrote the code but I can't figure out where exactly and how it will fit into my code bcoz all the checkboxes are gng into a single array.. cheers rohit -
Hello everyone, I'm facing a problem in storing the multiple checkbox values on only one row of the MYSQL database. As in when a single person enters his data along with his name and other details. On the MySQL it would look like id name phone checkbox_values 1 abc 89898989 value1,value2 Unfortunately I'm unable to achieve this. What I get is --- id name phone checkbox_values 1 abc 89898989 NULL 2 value1 3 value2 Following is the HTML code - [code]<!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> <TITLE>Form Handling with PHP</TITLE> </HEAD> <BODY BGCOLOR="#FFFFFF"> <FORM METHOD=POST ACTION="add.php"> <input type="hidden" name="id" value="NULL"> <TABLE> <TR height="20"> <TD colspan="2"><FONT SIZE="+0" face="verdana"> Below is a Sample Form </TD> </TR> <TR height="50"> <td></td> </TR> <TR> <TD align="left"><FONT SIZE="+0" face="verdana"> <b>Your Name <br> Your E-Mail Address</b></td> <td><INPUT TYPE="text" NAME="name"> <br> <INPUT TYPE="text" NAME="email"> </TD> </TR> <tr> <td colspan="2"><center> <SELECT NAME="opinion"> <option value="is great">I like your site</option> <option value="is OK">Your Site is OK</option> <option value="is horrible">Your Site is horrible</option> </SELECT> </td> </tr> <tr> <td align="right"> <p>How will you travel <br>to work? *<br> <span class="style18">(Please tick the applicable boxes)</b></span></p> </td> <td colspan="2"><input type="checkbox" name="type_transport[]" value="car" style="width:20px"> Own Car <input type="checkbox" name="type_transport[]" value="public transport" style="width:20px"> Public Transport <p> <input type="checkbox" name="type_transport[]" value="bike" style="width:20px"> Bike <input type="checkbox" name="type_transport[]" value="walk" style="width:20px"> Walk <p> <input type="checkbox" name="type_transport[]" value="other" style="width:20px"> Other<br> <br> </td> </tr> <tr><td> <INPUT TYPE="submit" value="Tell us!"> </td></tr> </TABLE> <p> </p> </FORM> </BODY> </HTML> [/code] Here's the PHP code [code] <? $DBhost = "my-host-name"; $DBuser = "my-username"; $DBpass = "my-password"; $DBName = "my-database-name"; $table = "information"; mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database"); @mysql_select_db("$DBName") or die("Unable to select database $DBName"); $sqlquery = "INSERT INTO $table VALUES('$id','$name','$email','$opinion')"; $results = mysql_query($sqlquery); $tt_count=count($type_transport); for ($i=0; $i < $tt_count; $i++) { $insertquery = "INSERT INTO $table (type_transport) VALUES('$type_transport."')"; $results_1 = mysql_query($insertquery); } mysql_close(); echo "Thank You"; ?> [/code] Any help would be highly appreciated.... thanks rohit
-
Export PHP Form Data into Excel without MySQL
callingrohit replied to callingrohit's topic in PHP Coding Help
Thanks for the info guru , but to get a license for commercial purposes, it will cost me $1000 and I think MySQL is 100 times cheaper if I could afford MySQL right now. Let me know if you find anything else, I'm just loosing hope..... cheers callingrohit -
HI everyone, I would like to know if its possible to export the data which entered by a user on the HTML form(processed using php) into an excel without installing MySQL. I do know that its very easy with MySQL, but its just that my webhost doesn't provide MySQL and wants a hundred bucks for installing one. So I would like to avoid that and somehow export the user entered data in the form directly into the excel file. Unfortunately I won't be able to get MySQL atleast for 4-5 months and right now, all information entered in the form comes to me in email. So can someone tell me if its possible to get the data entered in a form that is processed by PHP into a spreadsheet. Regards callingrohit