473,382 Members | 1,424 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

creating the row dynamically and saving the data to a database

hello guys...

today i need again help...
actually i face problem the in adding new row at run time...

coding....
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <script type ="text/javascript">
Expand|Select|Wrap|Line Numbers
  1. var counter=0;
  2. function addRow()
  3. {
  4.  
  5.  var trow=document.getElementById('tblGrid').insertRow();
  6.  
  7.  var tdata1=trow.insertCell(0);
  8.  var tdata2=trow.insertCell(1);
  9.  
  10.  
  11.  
  12. tdata1.innerHTML="<input type='text' id='product' maxlength='50' class='Text' name='product'>";
  13. tdata2.innerHTML="<input type='text' id='price' maxlength='50' class='Text' name='price'>";
  14. }
  15.  
Expand|Select|Wrap|Line Numbers
  1. </script>
  2. <body>
  3. <form name="sample" action="sample1.php" method="post">
  4.   <table id="tblGrid" style="table-layout:fixed">
  5.     <tr>
  6.       <th width="150">Product Name</th>
  7.       <th width="150">Price</th>
  8.       <input name="button" type="button" onClick= "return addRow();" value="Add" >
  9.       <input type="submit" value = "save" name="submit">
  10.     </tr>
  11.     <tr>
  12.       <td height="21"></td>
  13.       <td></td>
  14.       <td width="14">&nbsp;&nbsp;</td>
  15.     </tr>
  16.   </table>
  17. </form>
  18. </body>
  19. </html>
  20.  
the above is my code which create the row dynmically...
my problem is thati want to store the value of each row in database using php...
how we accomplish this task...
pleas tell me...
i try last one week but not successfull...
so please help me...
and send me the solution...
i requested u to please try solve this problem using example...
i shall be very thank ful to you...
i wait your reply...


vivek kumar
Sep 24 '07 #1
5 4108
pbmods
5,821 Expert 4TB
Heya, Vivek.

Please use CODE tags when posting source code:

[CODE=html]
HTML code goes here.
[/CODE]

This is not the first time you've been asked.

PHP operates on the server side. To dynamically create a row, you need to use JavaScript. To communicate with the server, you'll want to use AJAX.

I'm going to go ahead and move this thread to the JavaScript / AJAX forum, where our resident Experts will be better able to help you out.
Sep 24 '07 #2
Lmac
2
This is a similar problem I am having. I have used a clone tool, but I find your way of going about it even better.

The problem I'm faced with however is making the new rows uniquely identifiable in my SQL Database. Any suggestions on how to go about that?

Here is the current code I've been using (obviously I won't be able to use the clone method anymore, so I don't know how helpful it will be - it's based on code I found somewhere around the web)

Expand|Select|Wrap|Line Numbers
  1.  
  2. <script type="text/javascript">
  3.  
  4. var counter = 0;
  5.  
  6. function moreFields() {
  7.     counter++;
  8.     var newFields = document.getElementById('readroot').cloneNode(true);
  9.     newFields.id = '';
  10.     newFields.style.display = 'block';
  11.     var newField = newFields.childNodes;
  12.     for (var i=0;i<newField.length;i++) {
  13.         var theName = newField[i].name
  14.         if (theName)
  15.             newField[i].name = theName + counter;
  16.     }
  17.     var insertHere = document.getElementById('writeroot');
  18.     insertHere.parentNode.insertBefore(newFields,insertHere);
  19. }
  20. window.onload = moreFields;
  21.  
  22. function toggleField(val) {
  23. var o = document.getElementById('other');
  24. (val == 'other')? o.style.display = 'block' : o.style.display = 'none';
  25.  
  26. </script>
  27.  
  28. <div id="readroot" style="display: none">
  29.  
  30.     <input type="button" value="Remove review"
  31.         onclick="this.parentNode.parentNode.removeChild(this.parentNode);" /><br /><br />
  32.  
  33.     <input name="cd" value="title" />
  34.  
  35.     <select name="rankingsel">
  36.         <option>Dansblog</option>
  37.         <option value="excellent">Excellent</option>
  38.         <option value="good">Good</option>
  39.         <option value="ok">OK</option>
  40.         <option value="poor">Poor</option>
  41.         <option value="bad">Bad</option>
  42.     </select><br /><br />
  43. <input type="text" name="other" id="other" style="display: none;">
  44.     <textarea rows="5" cols="20" name="review">Short review</textarea>
  45.     <br />Radio buttons included to test them in Explorer:<br />
  46.     <input type="radio" name="something" value="test1" />Test 1<br />
  47.     <input type="radio" name="something" value="test2" />Test 2
  48. <form action="" method="post">
  49. <select name="sel" id="sel" onChange="toggleField(this.value);">
  50. <option value="">No Option</option>
  51. <option value="Out of Office">Out of Office</option>
  52. <option value="Holiday/Birthday">Holiday/Birthday</option>
  53. <option value="other">other</option>
  54. </select>
  55. <input type="text" name="other" id="other" style="display: none;">
  56. </form>
  57. </div>
  58.  
  59.     <span id="writeroot"></span>
  60.  
  61.     <input type="button" onClick="moreFields()" value="Give me more fields!" />
  62.     <input type="submit" value="Send form" />
  63.  
  64. </form>
  65.  
Apologies for over running the thread, but i had a similar problem and thought it would be better to discuss in a pre-existing thread.
Sep 26 '07 #3
acoder
16,027 Expert Mod 8TB
Welcome to TSDN!
The problem I'm faced with however is making the new rows uniquely identifiable in my SQL Database. Any suggestions on how to go about that?
Is this uniquely identifiable over all records or just within one page use? If it's over all records, you will need to use Ajax to query the database for a unique number.
Sep 26 '07 #4
Lmac
2
Welcome to TSDN!
Is this uniquely identifiable over all records or just within one page use? If it's over all records, you will need to use Ajax to query the database for a unique number.
Well, to describe the problem more in depth.

What I want to do is include a career pathway section. These values (course, date enrolled, course start date, course end date etc) need to be stored in the database. The first one is fine obviously, but I need to add another 3 of these forms, and they all need to be unique to help keep track of all 4 career pathways.

Just to clarify, there is a table for the student's details and another table for the pathways. The pathways already have an automatically incrementing ID, so keeping them separate probably isn't the root of the problem. More so actually being able to create the fields to be unique (ie careerPath1, careerPath2 etc.) so that I may withdraw the data from the form into the database.

I hope that makes sense.

I'm not particularly well versed in AJAX, in all honesty I don't think we've even been taught how to use it nor when it would be good to use. So any help on this matter is appreciated.

Thanks for the welcome.
Sep 27 '07 #5
acoder
16,027 Expert Mod 8TB
Create a counter and increment it each time. If careerPath1, 2, 3, etc. is for just the page and it's only used to identify fields on the next page, that will be fine.

However, if you already have, say, careerPath1 through to 12 in the database and you need the next field to be called careerPath13, you could check the database with the server-side code when loading the page and set the counter to that value.
Sep 27 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: adrin | last post by:
hi, i am writing a program that is supposed to create a database of my music and albums. i want it to consist of 3 'modules' input<->processing<->output. input should enable reading data from cd...
2
by: Jake_adl | last post by:
Is there any way to create a Microsoft.Practices.EnterpriseLibrary.Data.Database object without reading from a configuration file? I am writing a utility that manages databases in SQL Server....
0
by: Roger Moore | last post by:
I have a DataGrid that needs to dynamically sum data for each column of data into the footer. The number of rows will differ for each person based on the projects they are working on at the time -...
2
by: Barry | last post by:
Hi can anyone tell me if there if any code snippet available for creating a SQL Server Database and Table using C# web application. TIA Barry
1
by: pmclinn | last post by:
I have a formated a structure as follows: <Serializable()>public structure stcOutPut private data as string private visi as string end structure Instances of this strucuture are stored in an...
0
by: alex | last post by:
hi whats the different methods in saving a database i'm alternathing between laptop& desktop and external hard drive.losing data here and there. will "briefcase" help me and or shall i upgrate to...
1
by: Magnus | last post by:
I'm testing walkthrough saving data to a Database (Multiple Tables). http://msdn2.microsoft.com/en-us/library/4esb49b4(VS.80).aspx In the famous Customer/Order example, I'm getting referential...
6
by: fjm | last post by:
Hello all.. Can someone recommend a tutorial on how to go about uploading a file (Image) and saving the url to the database? It would be great if the script could name the file also. There...
8
meenakshia
by: meenakshia | last post by:
hi forum i m using ie6 and the solution is for a standalone no internet connected machine there is dynamically generated data in tables and i m trying to get that printed in landscape mode. pls...
1
by: kayox007 | last post by:
hello everyone, am having trouble creating dynamically populated XML files using data from a database. i wouldn't mind coldfussion script that can do that. thanks ya'll
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.