Frequently, I need to change only one single field in a database. For that purpose I am using a short php script – it basically outputs all fields and highlights them with a javascript popup where you can do any changes (or even delete a row) while a “return” writes the change back to the database.
You will immediately see, where the script needs some adaptation – all the trick is in line 28.
line 2: your database
line 5,9…: your mytable
line 23: your columns
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 34: | <?php
$db = @mysql_connect('server','user','password');
if ($_GET['change']!='') {
if ($_GET['value']=='d') {
$sql = 'DELETE FROM mytable
WHERE mytable.Index=' . $_GET['id'] . ' LIMIT 1';
}
else {
$sql = 'UPDATE mytable ';
if (is_numeric($_GET['value'])) {
$sql = $sql . 'SET mytable.' . $_GET['field'] . '=' . $_GET['value'];
}
else {
$sql = $sql . 'SET mytable.' . $_GET['field'] . '="' . $_GET['value'] . '"';
}
$sql = $sql . ' WHERE mytable.Index=' . $_GET['id'];
}
$result = mysql_db_query('test',$sql);
}
$sql = 'SELECT DISTINCTROW *
FROM mytable';
$result = mysql_db_query('test',$sql);
$sc_vars = array("FirstCol","SecndCol","ThrdCol");
echo '<table>';
while($row = mysql_fetch_array($result)){
echo '<tr>';
for ($i=0;$i<9;$i++) {
echo '<td><a href="javascript:void(str=prompt(\'(d)el\',\'' . $row[$sc_vars[$i]] . '\'));if(str)void(window.location.href=\'liste.php?change=T&field=' . $sc_vars[$i] . '&id=' . $row['Index'] . '&value=\'+escape(str));">' . $row[$sc_vars[$i]] . '</td></a>';
}
echo '</tr>';
}
echo '</table>';
?>
|