Peuplarchie Posted May 30, 2010 Share Posted May 30, 2010 Good day to you all, I'm working on a MySQL database production area. I don't yet have access to my SSH connect ion and I'm trying to not use it since it's for a project orther that my regular. I have my adding , deleting and editing script all in separate php pages. For each table that I want to be able to play with I have to rename and edit thos pages acordingly. Is there a way that I can make only a single adding, deleting and editing page work for each table in all database ? What is all the people do ?, that is the part I don't catch. Here is my pages: notes.php <?PHP //check if the starting row variable was passed in the URL or not if (!isset($_GET['startrow']) or !is_numeric($_GET['startrow'])) { //we give the value of the starting row to 0 because nothing was found in URL $startrow = 0; //otherwise we take the value from the URL } else { $startrow = (int)$_GET['startrow']; } mysql_connect("localhost","USER","PASSWORD");//database connection mysql_select_db("DB"); $order = mysql_query("SELECT * FROM Notes"); $num_rows = mysql_num_rows($order); // Sort Process debut $ord = (isset($_GET['ord']) && ($_GET['ord'] == 'ASC' || $_GET['ord'] == 'DESC') ? $_GET['ord'] : 'ASC'); // sets 'desc' as default $link = ($ord == 'ASC' ? 'DESC' : 'ASC'); if(empty($_GET['coll'])) { $_GET['coll'] = "priorite"; } $col = mysql_real_escape_string(trim($_GET['coll'])); // Sort Process fin //General mysql query debut $order = "SELECT * FROM Notes ORDER BY `$col` $ord LIMIT $startrow, 30"; if($order == false) { user_error(mysql_error() . "<br />\n$order"); die("SQL error"); } //General mysql query fin // Headers $result = mysql_query($order); for ($i = 0; $i < mysql_num_fields($result); $i++) { if (mysql_field_name($result, $i) == "id"){ print "<th id=\"title\" style=\"color:#FF0000;\"><a href=\"".$_SERVER['PHP_SELF']."?coll=".mysql_field_name($result, $i)."&ord=".$link."&time=".date("hisu")."\" title=\"Sort by : ".mysql_field_name($result, $i)."\" style=\"color:#000000;\">ID</a></th>\n"; }else{ print "<th id=\"title\"><a href=\"".$_SERVER['PHP_SELF']."?coll=".mysql_field_name($result, $i)."&ord=".$link."&time=".date("hisu")."\" title=\"Sort by : ".mysql_field_name($result, $i)."\"style=\"color:#000000;\">".mysql_field_name($result, $i)."</a></th>\n"; } } echo "</tr>"; // Headers fin // Form Debut echo "<tr><form method=\"post\" name=\"action\" action=\"add_row_notes.php\">"; print "<td id=\"submit\"><input type=\"submit\" id=\"envoyer\" value=\" \"></td>\n"; for ($i = 0; $i < mysql_num_fields($result); $i++) { if (mysql_field_name($result, $i) == "modif"){ print "<td id=\"submit\"><input id=\"submitt\" type=\"text\" size=\"10\" name=\"".mysql_field_name($result, $i)."\" value=\"".date('Y-m-d G:i:s')."\"></td>\n"; }else{ if (mysql_field_name($result, $i) == "note"){ print "<td id=\"submit\"><input id=\"submitt\" type=\"text\" size=\"50\" name=\"".mysql_field_name($result, $i)."\" value=\"".$_SESSION[mysql_field_name($result, $i)]."\"></td>\n"; }else{ if (mysql_field_name($result, $i) == "titre"){ print "<td id=\"submit\"><input id=\"submitt\" type=\"text\" size=\"30\" name=\"".mysql_field_name($result, $i)."\" value=\"".$_SESSION[mysql_field_name($result, $i)]."\"></td>\n"; }else{ if (mysql_field_name($result, $i) == "priorite"){ print "<td id=\"submit\"><select name=\"".mysql_field_name($result, $i)."\"><option value=\"1-Urgent\" selected>1-Urgent</option><option value=\"2-Normal\">2-Normal</option><option value=\"3-Eventuellement\">3-Eventuellement</option><option value=\"4-Autre\">4-Autre</option></select></td>\n"; }else{ if (mysql_field_name($result, $i) == "status"){ print "<td id=\"submit\"><select name=\"".mysql_field_name($result, $i)."\"><option value=\"Ouvert\" selected>Ouvert</option><option value=\"Attente_Discussion\">Attente Discussion</option><option value=\"Fermer\">Fermer</option></select></td>\n"; }else{ if (mysql_field_name($result, $i) == "categorie"){ print "<td id=\"submit\">"; print "<select name=\"".mysql_field_name($result, $i)."\">"; print "<option value=\"**-Franck\" selected>**-test</option>"; print "<option value=\"**-Rocky\" selected>**-test2</option>"; print "<option value=\"Vivants\" selected>Vivants</option>"; print "<option value=\"Inspirations\">Inspirations</option>"; print "<option value=\"Connaissances\">Connaissances</option>"; print "<option value=\"Ensemble\">Ensemble</option>"; print "<option value=\"Outils\">Outils</option>"; print "</select></td>\n"; }else{ print "<td id=\"submit\"><input id=\"submitt\" type=\"text\" size=\"1\" name=\"".mysql_field_name($result, $i)."\" value=\"".$_SESSION[mysql_field_name($result, $i)]."\"></td>\n"; } } } } } } } echo "</form></tr>"; // Headers Fin //Grid $result = mysql_query($order); $i = 1; while(($data = mysql_fetch_row($result))!== false){ $i++; if ($data[1] == ''){$data[1] = "<br>";}else{} if ($data[2] == ''){$data[2] = "<br>";}else{} if ($data[3] == ''){$data[3] = "<br>";}else{} if ($data[4] == ''){$data[4] = "<br>";}else{} if ($data[5] == ''){$data[5] = "<br>";}else{} if ($data[5] == ''){$data[6] = "<br>";}else{} if ($data[5] == ''){$data[7] = "<br>";}else{} echo("<tr style=\"border:0px;\" onMouseOver=\"this.className='highlight'\" onMouseOut=\"this.className='normal'\"> <td id=\"fields".($i & 1)."\"> <a href=\"delete_row_notes.php?id=" . $data['0'] . "\" title=\"DELETE : Row ID #:" . $data['0'] . "\"> <img src=\"Template/Images/delete.png\" border=\"0\"/></a> <a href=\"editor_row.php?id=".$data['0']."\" title=\"Edit : Row ID #:".$data['0']."\" onclick=\"load('editor_row.php?id=".$data['0']."','".$data['0']."');return false;\"> <img src=\"Template/Images/edit_icon.png\" border=\"0\"/></a> </td> <td id=\"fields".($i & 1)."\">". $data[0]."</td> <td id=\"fields".($i & 1)."\">". $data[1]."</td> <td id=\"fields".($i & 1)."\">". $data[2]."</td> <td id=\"fields".($i & 1)."\">". $data[3]."</td> <td id=\"fields".($i & 1)."\">". $data[4]."</td> <td id=\"fields".($i & 1)."\">". $data[5]."</td> <td id=\"fields".($i & 1)."\">". $data[6]."</td> </tr><tr><td colspan=\"8\" id=\"".$data['0']."\"></td></tr>"); } // Grid fin //PREV & NEXT debut echo "<tr><td colspan=\"8\" align=\"center\" id=\"listpage\">"; //only print a "Previous" link if a "Next" was clicked $prev = $startrow - 30; if ($prev >= 0) echo '<a href="'.$_SERVER['PHP_SELF'].'?startrow='.$prev.'" title="Précedante ('.$prev.'/'.$startrow.')" style=\"color:#FFFFFF;\"> ('.$prev.'/'.$startrow.') Précedante</a> '; $next = $startrow+30; echo '<a href="'.$_SERVER['PHP_SELF'].'?startrow='.($startrow+30).'" title="Prochaine ('.$startrow.'/'.$next.')" style=\"color:#FFFFFF;\">Prochaine <font style="color:#003300">(</font>'.$startrow.'<font style="color:#003300">-</font>'.$next.'<font style="color:#003300"> / </font>'.$num_rows .'<font style="color:#003300">)</font></a>'; $prev = $startrow - 30; echo "</td></tr>"; //PREV & NEXT fin echo "</table></td></tr></table>"; ?> Add_row.php <?PHP $id = $_POST['id']; $_SESSION['id'] = $_POST['id']; $modif = $_POST['modif']; $_SESSION['modif'] = $_POST['modif']; $priorite = $_POST['priorite']; $_SESSION['priorite'] = $_POST['priorite']; $status = $_POST['status']; $_SESSION['status'] = $_POST['status']; $categorie = $_POST['categorie']; $_SESSION['categorie'] = $_POST['categorie']; $titre = $_POST['titre']; $_SESSION['titre'] = $_POST['titre']; $note = $_POST['note']; $_SESSION['note'] = $_POST['note']; mysql_connect("localhost","USER","PASSWORD");//database connection mysql_select_db("DB"); //inserting data order $order = "INSERT INTO Notes (id, modif, priorite, status, categorie, titre, note) VALUES ('NULL', '$modif', '$priorite', '$status', '$categorie', '$titre', '$note')"; //declare in the order variable $result = mysql_query($order); //order executes if($result){ echo("<br>Input data is succeed"); } else{ echo("<br>Input data is fail"); } $time = date("hisu"); ?> <script language="javascript"><!-- location.replace("Notes.php?time=<?PHP echo $time; ?>") //--> </script> I won't put my deleting and editing script, but I have added my script for adding a row to the db so you can see more of what I mean. I hope you will understand my question. Thanks ! Quote Link to comment https://forums.phpfreaks.com/topic/203319-add-delete-edit-page-working-for-each-table-automaticly/ Share on other sites More sharing options...
ignace Posted May 30, 2010 Share Posted May 30, 2010 What is all the people do ? They use a Table Data Gateway Quote Link to comment https://forums.phpfreaks.com/topic/203319-add-delete-edit-page-working-for-each-table-automaticly/#findComment-1065256 Share on other sites More sharing options...
Peuplarchie Posted May 30, 2010 Author Share Posted May 30, 2010 Yeah that is what I want to do, but I dont know how to code it, can you help me on this ? Quote Link to comment https://forums.phpfreaks.com/topic/203319-add-delete-edit-page-working-for-each-table-automaticly/#findComment-1065487 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.