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,description

assuming the query to get the table data is
"SELECT sku,quantity,item,description FROM tablea WHERE blah=blah"

and the update db code snip is

UPDATE tablea SET $fieldname = $content WHERE sku = $sku

And I'm only guessing at it being a $_GET.  Is that correct?  

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hey livegirllove : understanding yui isn't all that easy - don't feel dense ...  from what I gather, you want to use PHP/MySQL as your data source, correct ?  If so, you need to define your source this way (from : http://developer.yahoo.com/yui/datatable/) :

// 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_JSON;

// Define the data schema
myDataSource.responseSchema = {
    resultsList: "SalesDatabas.items", // Dot notation to results array
    fields: ["Company","Title","Name","Phone","Email"] // Field names

Your http://url/datafeed.php needs to output xml like so :

<SalesDatabase totalItems="40" itemsFound="2">
        <Company>A1 Services</Company>
        <Name>Jane Jones</Name>

        <Name>John Smith</Name>

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 ...
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 ?
livegirlloveAuthor Commented:
"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,description FROM tablea WHERE blah=blah";
     $res_cat44 = mysql_query($sqlvendor44); // handle to category set      ?>
<?php while ($row44 = mysql_fetch_assoc($res_cat44)) {

        echo "
<SalesDatabase totalItems=\"$rowsindatabase\" itemsFound=\"$count\">
        <description >$row44['description ']</description >

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.
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

hey livegirllove : sorry if i wasn't clear on that one ... what I meant to say, is that you should probably split this question and post another question in the PHP zone on how to receive the XHR request, grab the DB info, and return the results. The reason you don't see many examples on this is likely because it's far easier to use standard editing, and anyone who has gone to the work of putting a full ajax inline editor together doesn't want to give away his/her code for free =)

As far as getting this question answered, you're not that far off with the code you have in yui.  In the yui example, when a change is made to the cell, the onCellEdit function is called.  You need to add code to that function to send the change to your PHP page, and wait for the response.  The yahoo connection manager (http://developer.yahoo.com/yui/connection/) is what you need.  It is yui's framework for ajax requests.

There's a connection manager video tutorial on dustindiaz.com that was super helpful to me. I think he's got 5 video tutorials (screecasts) on YUI stuff.  http://www.dustindiaz.com/screencast-episode-02/

The other screencasts are here :

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
livegirlloveAuthor Commented:
thanks for the help.  ill check those links and see what I see.
livegirlloveAuthor Commented:
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. ;-)
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/
livegirlloveAuthor Commented:
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.
livegirlloveAuthor Commented:
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...  
livegirlloveAuthor Commented:
Ah Ha.  I got it.  This doesnt use YUI...
Ok so using the js from the page below:

assuming you have a table called tblInLineEdit with fields id, name,descr

$db_user = "";
$db_pass = ""; // password here
$db = "";
$host = "";
$link = mysql_connect($host,$db_user,$db_pass) 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"></script>
<? while ($row = mysql_fetch_assoc($result)) { ?>
<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>
<?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_user,$db_pass) 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['fieldname']);
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}"];

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.