livegirllove
asked on
YUI, PHP, MySQL inline editing data
Ok, I'm feeling extremely dense here.
I'm using YUI. I downloaded the library and examples.
Their example for inline editing is pulling it's data from a flat file. I spent about 4 hours reading and trying things but I can't figure out how the query to get the full table data and then post back single fields works.
I think if I could see a code sample using YUI and php and a table in MySQL I could go from there. I think I'm understanding the principle but I haven't seen the actually queries and how they are called.
for instance how could I duplicate http://developer.yahoo.com/yui/examples/datatable/inlineediting.html
assuming the data came from "tablea"
with coloms:sku,quantity,items, descriptio n
assuming the query to get the table data is
"SELECT sku,quantity,item,descript ion FROM tablea WHERE blah=blah"
and the update db code snip is
$fieldname = $_GET(THEFIELDBEINGUPDATED )
$content = $_GET(THEDATATOUPDATE)
$sku = $GET_(THEPRIMARYKEYROWID)
UPDATE tablea SET $fieldname = $content WHERE sku = $sku
And I'm only guessing at it being a $_GET. Is that correct?
thanks
I'm using YUI. I downloaded the library and examples.
Their example for inline editing is pulling it's data from a flat file. I spent about 4 hours reading and trying things but I can't figure out how the query to get the full table data and then post back single fields works.
I think if I could see a code sample using YUI and php and a table in MySQL I could go from there. I think I'm understanding the principle but I haven't seen the actually queries and how they are called.
for instance how could I duplicate http://developer.yahoo.com/yui/examples/datatable/inlineediting.html
assuming the data came from "tablea"
with coloms:sku,quantity,items,
assuming the query to get the table data is
"SELECT sku,quantity,item,descript
and the update db code snip is
$fieldname = $_GET(THEFIELDBEINGUPDATED
$content = $_GET(THEDATATOUPDATE)
$sku = $GET_(THEPRIMARYKEYROWID)
UPDATE tablea SET $fieldname = $content WHERE sku = $sku
And I'm only guessing at it being a $_GET. Is that correct?
thanks
The above code will only pull the data via XHR. In the YUI inline editor example, it does not update a database each time a cell is modified - it simply outputs the change to the log window.
If you are also looking to update a DB each time a cell value changes, that's a different question. The code above will help you duplicate the example (http://developer.yahoo.com/yui/examples/datatable/inlineediting.html) as per your request. To do what I think you're tryin to do, you'll need to [1] add code for an ajax request (to your PHP page) in the onCellEdit event, and [2] PHP code to receive the reqeust, update the DB and return the result. Those should probably be asked in seperate questions. Am i on the right track with what you're looking to do ?
If you are also looking to update a DB each time a cell value changes, that's a different question. The code above will help you duplicate the example (http://developer.yahoo.com/yui/examples/datatable/inlineediting.html) as per your request. To do what I think you're tryin to do, you'll need to [1] add code for an ajax request (to your PHP page) in the onCellEdit event, and [2] PHP code to receive the reqeust, update the DB and return the result. Those should probably be asked in seperate questions. Am i on the right track with what you're looking to do ?
ASKER
"If you are also looking to update a DB each time a cell value changes, that's a different question."
What would be different about the question? How can I re-ask it differently? My goal as stated in the question is to retrieve data from a database and then change the data (in the database) inline. I'm not sure what good doing an inline edit that doesnt update on the backend would be?
so http://url/datafeed.php should look something like this:
<? $sqlvendor44 = "SELECT sku,quantity,item,descript ion FROM tablea WHERE blah=blah";
$res_cat44 = mysql_query($sqlvendor44); // handle to category set ?>
<?php while ($row44 = mysql_fetch_assoc($res_cat 44)) {
$count+;
?>
echo "
<SalesDatabase totalItems=\"$rowsindataba se\" itemsFound=\"$count\">
<Item>
<sku>$row44['sku']</sku>
<quantity>$row44['quantity ']</quanti ty>
<item>$row44['item']</item >
<description >$row44['description ']</description >
</Item>
"
?>
so after I have then data where do I send it?
Or are you saying I should open 2 questions. 1 being how do I get data into a YUI table
and another one of how to post it back to the DB?
thanks for your help. Im a little suprised that in all my searchs I havent found a simple example/tutorial that shows A-Z how to do this.
What would be different about the question? How can I re-ask it differently? My goal as stated in the question is to retrieve data from a database and then change the data (in the database) inline. I'm not sure what good doing an inline edit that doesnt update on the backend would be?
so http://url/datafeed.php should look something like this:
<? $sqlvendor44 = "SELECT sku,quantity,item,descript
$res_cat44 = mysql_query($sqlvendor44);
<?php while ($row44 = mysql_fetch_assoc($res_cat
$count+;
?>
echo "
<SalesDatabase totalItems=\"$rowsindataba
<Item>
<sku>$row44['sku']</sku>
<quantity>$row44['quantity
<item>$row44['item']</item
<description >$row44['description ']</description >
</Item>
"
?>
so after I have then data where do I send it?
Or are you saying I should open 2 questions. 1 being how do I get data into a YUI table
and another one of how to post it back to the DB?
thanks for your help. Im a little suprised that in all my searchs I havent found a simple example/tutorial that shows A-Z how to do this.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks for the help. ill check those links and see what I see.
ASKER
because it's far easier to use standard editing
I assume you mean. click edit, open page with editable fields. click submit and reload the whole page with the new data? Then well yes it's easy.... but I want to AJAX it because PHP by itself seems very Web 1.0. The idea of AJAX and inline editing is about the most user friendly thing I've seen and I can't wait to get one example that works so I can build on it. I'm the type that learns by seeing a working model and butchering it to make it do what I want. ;-)
I assume you mean. click edit, open page with editable fields. click submit and reload the whole page with the new data? Then well yes it's easy.... but I want to AJAX it because PHP by itself seems very Web 1.0. The idea of AJAX and inline editing is about the most user friendly thing I've seen and I can't wait to get one example that works so I can build on it. I'm the type that learns by seeing a working model and butchering it to make it do what I want. ;-)
heh heh ... that's how I learn most of my stuff too =)
PHP doesn't really have anything to do with Web 1.0 or 2.0 ... its the client side code that defines the "web 2.0" experience, with AJAX being the most commonly used framework in "web 2.0" ...
The YUI data table + YUI connection manager will allow you do do inline editing with AJAX updating on a PHP backend.
This might be an example you're looking for, but its not based on the yui framework : http://www.yvoschaap.com/index.php/weblog/ajax_inline_instant_update_text_20/
PHP doesn't really have anything to do with Web 1.0 or 2.0 ... its the client side code that defines the "web 2.0" experience, with AJAX being the most commonly used framework in "web 2.0" ...
The YUI data table + YUI connection manager will allow you do do inline editing with AJAX updating on a PHP backend.
This might be an example you're looking for, but its not based on the yui framework : http://www.yvoschaap.com/index.php/weblog/ajax_inline_instant_update_text_20/
ASKER
i tried that. It is for single items. ie it doesnt do so well with a table of data. it would work if it was just one line item. Ill poke around some more. thatnks for the tips.
ASKER
hmm. actually i think i can get it to work in a table. however ill definately be lost when trying to use a select list.. Im going to award points and then open new questions one at a time...
ASKER
Ah Ha. I got it. This doesnt use YUI...
Ok so using the js from the page below:
http://www.yvoschaap.com/index.php/weblog/ajax_inline_instant_update_text_20/
assuming you have a table called tblInLineEdit with fields id, name,descr
**ajaxtest.php**
<?
$db_user = "";
$db_pass = ""; // password here
$db = "";
$host = "";
$link = mysql_connect($host,$db_us er,$db_pas s) or die("Database connection broken");
mysql_select_db($db,$link) or die("Database connection unavailable - ".mysql_error() );
$result = mysql_query("SELECT * FROM tblInLineEdit");
//$row = mysql_fetch_assoc($result) ;
?>
<script type="text/javascript" src="instantedit.js"></scr ipt>
<table>
<? while ($row = mysql_fetch_assoc($result) ) { ?>
<tr>
<td><span id="name-|||-<?php echo $row['id']; ?>" class="editText"><? echo $row['name']; ?></span></td>
<td><span id="descr-|||-<?php echo $row['id']; ?>" class="editText"><? echo $row['descr']; ?></span></td>
</tr>
<?php } ?>
</table>
**update.php**
<?
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0"); // HTTP/1.1
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache"); // HTTP/1.0
$db_user = "";
$db_pass = "";
$db = "";
$host = "";
$link = mysql_connect($host,$db_us er,$db_pas s) or die("Database connection broken");
mysql_select_db($db,$link) or die("Database connection unavailable - ".mysql_error() );
$content = $_GET['content'];
list($fieldname, $id) = explode("-|||-",$_GET['fie ldname']);
mysql_query("UPDATE tblInLineEdit SET $fieldname = '$content' WHERE id = $id ") or die("blah failure - ".mysql_error() );
$result = mysql_query("SELECT * FROM tblInLineEdit WHERE id = $id");
$row = mysql_fetch_assoc($result) ;
echo $row["{$fieldname}"];
?>
Ok so using the js from the page below:
http://www.yvoschaap.com/index.php/weblog/ajax_inline_instant_update_text_20/
assuming you have a table called tblInLineEdit with fields id, name,descr
**ajaxtest.php**
<?
$db_user = "";
$db_pass = ""; // password here
$db = "";
$host = "";
$link = mysql_connect($host,$db_us
mysql_select_db($db,$link)
$result = mysql_query("SELECT * FROM tblInLineEdit");
//$row = mysql_fetch_assoc($result)
?>
<script type="text/javascript" src="instantedit.js"></scr
<table>
<? while ($row = mysql_fetch_assoc($result)
<tr>
<td><span id="name-|||-<?php echo $row['id']; ?>" class="editText"><? echo $row['name']; ?></span></td>
<td><span id="descr-|||-<?php echo $row['id']; ?>" class="editText"><? echo $row['descr']; ?></span></td>
</tr>
<?php } ?>
</table>
**update.php**
<?
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0"); // HTTP/1.1
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache"); // HTTP/1.0
$db_user = "";
$db_pass = "";
$db = "";
$host = "";
$link = mysql_connect($host,$db_us
mysql_select_db($db,$link)
$content = $_GET['content'];
list($fieldname, $id) = explode("-|||-",$_GET['fie
mysql_query("UPDATE tblInLineEdit SET $fieldname = '$content' WHERE id = $id ") or die("blah failure - ".mysql_error() );
$result = mysql_query("SELECT * FROM tblInLineEdit WHERE id = $id");
$row = mysql_fetch_assoc($result)
echo $row["{$fieldname}"];
?>
--------------------------
// Point to a local or proxy URL
var myDataSource = new YAHOO.util.DataSource("http://url/datafeed.php");
// Set the responseType as JSON
myDataSource.responseType = YAHOO.util.DataSource.TYPE
// Define the data schema
myDataSource.responseSchem
resultsList: "SalesDatabas.items", // Dot notation to results array
fields: ["Company","Title","Name",
};
--------------------------
Your http://url/datafeed.php needs to output xml like so :
--------------------------
<SalesDatabase totalItems="40" itemsFound="2">
<Item>
<Company>A1 Services</Company>
<Title>CEO</Title>
<Name>Jane Jones</Name>
<Phone>800-555-2121</Phone
<Email>janejones@a1service
</Item>
<Item>
<Company>Acme</Company>
<Title>President</Title>
<Name>John Smith</Name>
<Phone>800-555-1212</Phone
<Email>johnsmith@acme.com<
</Item>
</SalesDatabase>
--------------------------
If you'd rather send/receive data in plain text, rather than XML, the you just need to define your data source differenly, and output differently. The code examples are also on that page ...