Estado luchando con esto desde alrededor de las 10 pm (2 a.m. ahora), y soy enfermo de google y mensajes de error - tiempo de pedir a los profesionales.
¿Qué Im tratando de hacer: Si existe una entrada en la base de datos MySQL, llenar el cuadro con los datos de
de lo contrario, comenzar con una tabla en blanco y añadir filas de forma dinámica con cuadros de texto.
cuando el usuario presenta la forma, debe realizar la validación de los datos (es necesario un código válido de una lista)
entonces se debe enviar a la base de datos mysql (si ya existe, debe editar / eliminar según sea necesario)
¿Qué Ive consiguió hasta ahora: Javascript & #058;
var initial_count = new Array();
var rows_limit = 0; // Set to 0 to disable limitation
function addRow(table_id)
{
var tbl = document.getElementById(table_id);
// counting rows in table
var rows_count = tbl.rows.length;
if (initial_count[table_id] == undefined)
{
// if it is first adding in this table setting initial rows count
initial_count[table_id] = rows_count;
}
// determining real count of added fields
var tFielsNum = rows_count - initial_count[table_id];
if (rows_limit!=0 && tFielsNum >= rows_limit) return false;
var text = 'Unit code:';
var input = '<input type="text" name="postvar[]" style="width:100%;"/>';
var remove= '<input type="button" value="Remove" onclick="removeRow(\''+table_id+'\',this.parentNode.parentNode)" style="width:100%;"/>';
try {
var newRow = tbl.insertRow(rows_count);
var newCell = newRow.insertCell(0);
newCell.innerHTML = text;
var newCell = newRow.insertCell(1);
newCell.innerHTML = input;
var newCell = newRow.insertCell(2);
newCell.innerHTML = remove;
} catch (ex) {
//if exception occurs
alert(ex);
}
}
function removeRow(tbl,row)
{
var table = document.getElementById(tbl);
try {
table.deleteRow(row.rowIndex);
} catch (ex) {
alert(ex);
}
}
- var initial_count = new Array();
- var rows_limit = 0; // Set to 0 to disable limitation
- function addRow(table_id)
- {
- var tbl = document.getElementById(table_id);
- // counting rows in table
- var rows_count = tbl.rows.length;
- if (initial_count[table_id] == undefined)
- {
- // if it is first adding in this table setting initial rows count
- initial_count[table_id] = rows_count;
- }
- // determining real count of added fields
- var tFielsNum = rows_count - initial_count[table_id];
- if (rows_limit!=0 && tFielsNum >= rows_limit) return false;
- var text = 'Unit code:';
- var input = '<input type="text" name="postvar[]" style="width:100%;"/>';
- var remove= '<input type="button" value="Remove" onclick="removeRow(\''+table_id+'\',this.parentNode.parentNode)" style="width:100%;"/>';
-
- try {
- var newRow = tbl.insertRow(rows_count);
- var newCell = newRow.insertCell(0);
- newCell.innerHTML = text;
- var newCell = newRow.insertCell(1);
- newCell.innerHTML = input;
- var newCell = newRow.insertCell(2);
- newCell.innerHTML = remove;
- } catch (ex) {
- //if exception occurs
- alert(ex);
- }
- }
- function removeRow(tbl,row)
- {
- var table = document.getElementById(tbl);
- try {
- table.deleteRow(row.rowIndex);
- } catch (ex) {
- alert(ex);
- }
- }
index.php:
<form id="form1" name="form1" method="post" action="setunits.php">
<h3>Set up units:</h3>
<table width="400" border="1" cellspacing="0" cellpadding="4" id="mytable">
<tr><th colspan="3"><h3>Units</h3></th></tr>
<tr><th colspan="3"><input type="button" name="Button" value="Add unit" onClick="addRow(\'mytable\')"></th></tr>
</table><br>
<input name="submitbutton" type="submit" value="Submit"/>
</form>
- <form id="form1" name="form1" method="post" action="setunits.php">
- <h3>Set up units:</h3>
- <table width="400" border="1" cellspacing="0" cellpadding="4" id="mytable">
- <tr><th colspan="3"><h3>Units</h3></th></tr>
- <tr><th colspan="3"><input type="button" name="Button" value="Add unit" onClick="addRow(\'mytable\')"></th></tr>
- </table><br>
- <input name="submitbutton" type="submit" value="Submit"/>
- </form>
setunits. PHP:
(ni idea de lo que esto debería ser)
¿Tiene problemas con:
Rellenar la tabla de MySQL (no acabo de hacer la tabla con php? No está seguro de qué hacer con el javascript)
De validación - comprobación de los datos con una lista en la base de datos
Obtener la matriz de la forma (ni idea de aquí)
Si lo he entendido todo lo que a finales de este mal hacer un tutorial completo sobre él.
En la acción:
http://uwadb.com/timetable/setup.php?id=unitsGracias por adelantado!