Webmaster Forum

Go Back   Webmaster Forum > Web Development > Coding Forum

Coding Forum Problems with your code? Discuss coding issues, including JavaScript, PHP & MySQL, HTML & CSS, Flash & ActionScript, and more.


Reply
 
Thread Tools Display Modes
Share |
  #1  
Old 01-31-2012, 09:43 AM
mirohristov's Avatar
mirohristov mirohristov is offline
Contributing Member
 
Join Date: 01-11-12
Posts: 64
iTrader: 0 / 0%
DB to JSON to AJAX or echo html from DB

I'm having a "fundamentals", noob problem.
I can't figure out how to use JSON and AJAX

I'm trying to build a tiny "CMS" or form if you will.

I want to display an input field from database. Then the user can edit it's value. Then i want to update the database with the new value.
The input fields stored in db as id name value and the idea is that I can add more.

Right now I use:
PHP Code:
while($row = mysql_fetch_assoc($result)){ 
<td><input id="<? echo $row['id']; ?>"  name="<? echo $row['name']; ?>"  value="<? echo $row['value']; type="text" ?>" ></td>
}

Then when i want to update I collect the Id the Name and the Value as a json array, send it trough ajax, and run UPDATE on every key>value like this:

Code:
$array = json_decode($json, true); foreach ($array as $key1=>$value1) { mysql_query("UPDATE.... where id=.... }

My question is what is a more elegant way (best practice) for retrieving data from db, displaying it, editing it and updating it back to db.
I'm not so concerned about the code as for the actual logic.

Should I use JSON+AJAX for displaying the inputs as well (instead of echoing <input /> from php)

Anything that will shed some light will help me
Thanks
 
Reply With Quote

Advertisement

Advertisement

  #2  
Old 01-31-2012, 11:13 AM
lordspace's Avatar
lordspace lordspace is offline
Contributing Member
 
Join Date: 05-30-06
Location: Canada
Posts: 913
iTrader: 0 / 0%
maybe you could list the records and then use a plugin such as jeditable:
http://www.appelsiini.net/projects/jeditable to edit the contents.
 
Reply With Quote
  #3  
Old 01-31-2012, 04:09 PM
mirohristov's Avatar
mirohristov mirohristov is offline
Contributing Member
 
Join Date: 01-11-12
Posts: 64
iTrader: 0 / 0%
Quote:
Originally Posted by lordspace View Post
maybe you could list the records and then use a plugin such as jeditable:
http://www.appelsiini.net/projects/jeditable to edit the contents.
Excellent! Thanks a lot.
 
Reply With Quote
Go Back   Webmaster Forum > Web Development > Coding Forum

Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
ERROR cannot decode JSON object? joejoe Coding Forum 2 12-13-2011 05:37 AM
jQuery ajax, json, PHP array problem NayDreams Coding Forum 3 05-28-2011 11:08 PM
html/css/php/mysql/magento/wordpress/javascript/jquery/ajax - GURANTEED CODING!! dangys Sell Web Services 1 04-29-2011 10:53 PM
Automatically Conversion of Simple HTML Pages To AJAX Based Ones downloadtube Coding Forum 1 12-06-2008 01:37 PM


V7N Network
Get exposure! V7N I Love Photography V7N SEO Blog V7N Directory


All times are GMT -7. The time now is 04:15 AM.
Powered by vBulletin
Copyright 2000-2014 Jelsoft Enterprises Limited.
Copyright © 2003 - 2018 VIX-WomensForum LLC