LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General > LinuxQuestions.org Member Success Stories
User Name
Password
LinuxQuestions.org Member Success Stories Just spent four hours configuring your favorite program? Just figured out a Linux problem that has been stumping you for months?
Post your Linux Success Stories here.

Notices


Reply
  Search this Thread
Old 12-16-2009, 07:48 PM   #1
julianb
LQ Newbie
 
Registered: Nov 2009
Posts: 2

Rep: Reputation: 0
a beginner's PHP/MySQL script: MySQL in spreadsheet-like layout


This was pretty exciting for me when I finally got it to work!

I'm a real newbie at writing PHP/MySQL code. But I successfully took some boilerplate PHP code and modified it into the following.

It lays out your MySQL table as though it were a spreadsheet, where you can type in values.

Totally unfinished... it shows a "submit" button, but that button doesn't do anything at all. So there's no mechanism for data you enter to get back into the MySQL database.

Code:
<?php

mysql_connect("localhost", "root", "pass") or die(mysql_error());
echo "<form action=\"process.php\" method=\"post\">" ;
$db_selected = mysql_select_db('testing123');
//$query = 'SELECT * FROM example';
//$result = mysql_query('SELECT * FROM example');

$result = mysql_query('select * from example');
if (!$result) {  die('Query failed: ' . mysql_error()); }
echo "<table border=0 cellpadding=0 cellspacing=0>";

$y = 0;
$num_fields = mysql_num_fields($result);
$num_rows = mysql_num_rows($result);

while ($y < $num_rows) { $x = 0; echo "<tr>";
    $row = mysql_fetch_row($result);
    while ($x < $num_fields){
    $columnName = "col_" . $x ;
    $value = $row[$x] ;
       echo "<td><input type=\"text\" name=\"$y","_","$columnName\" value=\"$value\"></td>";
    $x++; }
$y++;echo "</tr>";}
echo "</table>";
echo "<input type=\"submit\" value=\"Submit\">" ;
echo "</form>" ;

/* data (column headers should be col_1,col_2,col_3)
row1column1,row1column2,row1column3
row2column1,row2column2,row2column3
row3column1,row3column2,row3column3
*/
?>

<!--

<form action="process.php" method="post">
Your Name: <input type="text" name="name"><br>
E-mail: <input type="text" name = "email"><br>
Location: <input type="text" name = "location"><br>
<input type="submit" value="Submit">
</form>
PS - I'm posting from a CentOS liveCD, first time CentOS user as of a few minutes ago. I figure I'd like to learn to use CentOS, so here I am. Didn't realize that the LiveCD was not intended for a Hard Drive install (!) but I might try to make it install to my hard drive anyway.

Last edited by julianb; 12-17-2009 at 05:14 PM.
 
Old 01-01-2010, 09:11 AM   #2
carltm
Member
 
Registered: Jan 2007
Location: Canton, MI
Distribution: CentOS, SuSE, Red Hat, Debian, etc.
Posts: 703

Rep: Reputation: 99
Good job working on the php/mysql.

Have you tried installing CentOS? The easy way is to download the
boot.iso image and perform a network install.
 
Old 01-01-2010, 08:25 PM   #3
kstan
Member
 
Registered: Sep 2004
Location: Malaysia, Johor
Distribution: Dual boot MacOS X/Ubuntu 9.10
Posts: 851

Rep: Reputation: 31
congratulation, try to start create some module from some cms (xoops,drupal,joomla) or php framework(zend,cakephp). It will save lot of your time at future.
 
  


Reply

Tags
centos5, php, php5 apache mysql, spreadsheet



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
php/shell script to install mysql,apache and php automatically stranger_6_7 Linux - General 2 08-11-2009 02:07 AM
yum install php-mysql fails with mysql 5.1 - "Error: mysql conflicts with MySQL" rebelde Linux - Software 2 03-13-2009 10:32 AM
Is 'nice' inherited to child processes? e.g. bash script/php script that calls MySQL SirTristan Linux - Newbie 1 12-04-2008 12:57 AM
LXer: Title: PHP/MySQL Classifieds Script AddAsset1.php Script Insertion LXer Syndicated Linux News 0 07-02-2006 06:21 PM
mySQL and excel spreadsheet zuessh Linux - Software 1 06-12-2003 07:26 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General > LinuxQuestions.org Member Success Stories

All times are GMT -5. The time now is 04:19 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration