Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

YUI, PHP, MySQL inline editing data

Posted on 2007-03-28
Last Modified: 2013-12-13
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?  

Question by:livegirllove
  • 6
  • 4

Expert Comment

ID: 18817696
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 ...

Expert Comment

ID: 18817807
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 ?

Author Comment

ID: 18818763
"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.
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center


Accepted Solution

Gitcho earned 500 total points
ID: 18819238
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 :

Author Comment

ID: 18820637
thanks for the help.  ill check those links and see what I see.

Author Comment

ID: 18820649
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. ;-)

Expert Comment

ID: 18825197
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/

Author Comment

ID: 18826138
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.

Author Comment

ID: 18827176
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...  

Author Comment

ID: 18827836
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}"];


Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Asp in server side with Mssql Server 7 4 27
ability to create nested list on the UI using PHP, HTML, Javascript 7 45
Html Newline 7 20
Copying table data to one another 15 29
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question