miracle Posted September 22, 2013 Share Posted September 22, 2013 Hi If I create example section and under section category linking to each other how can I do and this is my tables $inf_newtable[1] = "".$db_prefix."section ( `id` int(10) NOT NULL auto_increment, `name` varchar(255) NOT NULL default '', `photo` varchar(255) NOT NULL default 'no-photo.jpg', PRIMARY KEY (`id`) ) ENGINE=MyISAM;"; $inf_newtable[2] = "".$db_prefix."category ( `id` int(10) NOT NULL auto_increment, `name` varchar(255) NOT NULL default '', `section_id` int(10) NOT NULL default '0', PRIMARY KEY (`id`) ) ENGINE=MyISAM;"; Link to comment https://forums.phpfreaks.com/topic/282356-linking-table-to-table-php/ Share on other sites More sharing options...
Barand Posted September 22, 2013 Share Posted September 22, 2013 Are you trying to create a single SQL query linking the tables or do you want two linked selection dropdowns.? We need more info on what you are trying to do Link to comment https://forums.phpfreaks.com/topic/282356-linking-table-to-table-php/#findComment-1450645 Share on other sites More sharing options...
miracle Posted September 22, 2013 Author Share Posted September 22, 2013 I am trying to create a section then in section page, i want to send a link creating category under section Link to comment https://forums.phpfreaks.com/topic/282356-linking-table-to-table-php/#findComment-1450647 Share on other sites More sharing options...
Barand Posted September 22, 2013 Share Posted September 22, 2013 What code have you got so far? Link to comment https://forums.phpfreaks.com/topic/282356-linking-table-to-table-php/#findComment-1450649 Share on other sites More sharing options...
miracle Posted September 22, 2013 Author Share Posted September 22, 2013 if (isset($_GET['op'])) { $op = $_GET['op']; } else { $op = ""; } if (isset($_GET['id'])) { $id = intval($_GET['id']); } else { $id = 0; } if (isset($_GET['ok'])) { $ok = stripinput($_GET['ok']); } else { $ok = false;} if (isset($_POST['name'])) { $name = stripinput($_POST['name']); } else { $name = "";} if (isset($_POST['photo'])) { $photo = stripinput($_POST['photo']); } else { $photo = "";} if (isset($_POST['bio'])) { $bio = stripinput($_POST['bio']); } else { $bio = "";} if (isset($_POST['scholar'])) { $scholar = $_POST['scholar']; } else { $scholar = "";} if (isset($_POST['desc'])) { $desc = stripinput($_POST['desc']); } else { $desc = "";} function scholar(){ global $db_prefix; opentable("scholar <span class='label label-success'><a href='admin.php?op=addscholar' style='color:#fff'>Add scholar</a></span>"); $rows = dbcount("(id)", "".$db_prefix."todoscholar"); if ($rows != 0) { $n = 0; echo "<table class='table table-bordered'><tr>"; $res = dbquery("SELECT * FROM ".$db_prefix."todoScholar ORDER BY name"); while ($row = dbarray($res)) { echo "<tr><td><a href='admin.php?op=editscholar&id={$row['id']}'>{$row['name']}</a></td>"; echo "<td width='6%'><a href='admin.php?op=editscholar&id={$row['id']}'><i class='icon-edit'></i></a><a href='admin.php?op=deletescholar&id={$row['id']}'><i class='icon-remove'></i></a></td>"; echo "</tr>"; $n++; } echo "</tr></table>"; } closetable(); } function addscholar($name,$photo,$bio,$ok=true){ global $db_prefix; opentable('Add scholar'); if (!$ok) { echo "<table width='100%' align='center' cellspacing='0' cellpadding='1' class=''>\n"; echo "<form name='form_arg' method='post' action='admin.php?op=addscholar&ok=true'>"; echo "<tr><td><b>Name</b><td><input type='text' name='name' size='40' maxlength='255' placeholder='Type Title'></tr>\n"; echo "<tr><td><b>Photo</b><td><input type='text' name='photo' size='40' maxlength='255' placeholder='Poto.jpg'></tr>\n"; echo "<tr><td><b>Body</b><td><textarea rows='3' name='bio' placeholder='Texterea Body'></textarea></tr>\n"; echo "<tr><td colspan='2'><button type='submit' class='btn btn-primary'>Save</button></tr>\n"; echo "</form>\n"; echo "</table>\n"; } else { $save = true; if ($name=="") { $save = false; $msg = "Word field required"; } if ($save) { $checkCat = dbcount("(id)", "".$db_prefix."todoscholar", "name='".$name."'"); if ($name=="") { $save = false; $msg = "Word field required"; } if ($checkCat == 0) { $query = dbquery("INSERT INTO ".$db_prefix."todoscholar (name,photo,bio) VALUES ('$name','$photo','$bio')"); echo "<div align='center' class='alert alert-success'><b>$name Added</b></div>"; echo "<meta http-equiv='refresh' content='3;URL=".INFUSIONS."todo/admin.php'>"; } else { echo "<div align='center' class='alert alert-error'><b>$msg</b></div>"; echo "<meta http-equiv='refresh' content='0;URL=".INFUSIONS."todo/admin.php?op=addtype'>"; } } else { echo "<div align='center' class='alert alert-error'><b>$msg</b></div>"; echo "<meta http-equiv='refresh' content='3;URL=".INFUSIONS."todo/admin.php?op=addtype'>"; } } closetable(); } function editscholar($id,$name,$photo,$bio,$ok=true){ global $db_prefix; opentable('Edit scholar'); if (!$ok) { $row = dbarray(dbquery("SELECT * FROM ".$db_prefix."todoscholar WHERE id=$id")); find_selected_page(); echo "<table width='100%' align='center' cellspacing='0' cellpadding='1' class=''>\n"; echo "<form name='form_arg' method='post' action='admin.php?op=editscholar&id=$id&ok=true'>"; echo "<tr><td><b>Name</b><td><input type='text' name='name' value='{$row['name']}' placeholder='Type Title'></tr>\n"; echo "<tr><td><b>Photo</b><td><input type='text' name='photo' value='{$row['photo']}' placeholder='Poto.jpg'></tr>\n"; echo "<tr><td><b>Body</b><td><textarea rows='3' name='bio' placeholder='Texterea Body'>{$row['bio']}</textarea></tr>\n"; echo "<tr><td colspan='2'><button type='submit' class='btn btn-primary'>Save</button> <a href='admin.php?op=addbook&id={$_GET['id']}'><i class='icon-edit'></i></a></tr>\n"; echo "</form>\n"; echo "</table>\n"; } else { $save = true; if ($name=="") { $save = false; $msg = "Word field required"; } if ($save) { $query = dbquery("UPDATE ".$db_prefix."todoscholar SET name='$name', photo='$photo', bio='$bio' WHERE id='$id'"); echo "<div align='center' class='alert alert-success'><b>$name Updated</b></div>"; echo "<meta http-equiv='refresh' content='3;URL=".INFUSIONS."todo/admin.php?op=scholar'>"; } else { echo "<div align='center' class='alert alert-error'><b>$msg</b></div>"; echo "<meta http-equiv='refresh' content='3;URL=".INFUSIONS."todo/admin.php'>"; } } closetable(); } function deletescholar($id,$ok=true){ global $db_prefix; opentable('Delete scholar'); $id = intval($id); if ($ok) { dbquery("DELETE FROM ".$db_prefix."todoscholar WHERE id=$id"); echo "<meta http-equiv='refresh' content='0;URL=admin.php'>"; } else { echo "<div align='center'><b>Are you sure you want delete</b><br><a href='admin.php?op=deletescholar&id=$id&ok=true' title='YES'>YES</a> - <a href='admin.php' title='NO'>NO</a></div>"; } closetable(); } // Book // scholar function book(){ global $db_prefix; opentable("Books <span class='label label-success'><a href='admin.php?op=addbook' style='color:#fff'>Add book</a></span>"); $rows = dbcount("(id)", "".$db_prefix."todotype"); if ($rows != 0) { $n = 0; echo "<table class='table table-bordered'><tr>"; $res = dbquery("SELECT * FROM ".$db_prefix."todobook WHERE scholar='{$id}' ORDER BY name"); while ($row = dbarray($res)) { echo "<tr><td><a href='admin.php?op=editbook&id={$row['id']}'>{$row['name']}</a></td>"; echo "<td width='6%'><a href='admin.php?op=editbook&id={$row['id']}'><i class='icon-edit'></i></a><a href='admin.php?op=deletescholar&id={$row['id']}'><i class='icon-remove'></i></a></td>"; echo "</tr>"; $n++; } echo "</tr></table>"; } closetable(); } function addbook($name,$scholar,$ok=true){ global $db_prefix; opentable('Add book'); if (!$ok) { //$row = dbarray(dbquery("SELECT * FROM ".$db_prefix."todoscholar WHERE id=$id")); echo "<table width='100%' align='center' cellspacing='0' cellpadding='1' class=''>\n"; echo "<form name='form_arg' method='post' action='admin.php?op=addbook&ok=true'>"; echo "<tr><td><b>Name</b><td><input type='text' name='name' size='40' maxlength='255' placeholder='Type Title'></tr>\n"; echo "<tr><td><b>Name</b><td><input type='text' name='scholar' size='40' maxlength='255' placeholder='Type Title'></tr>\n"; echo "<tr><td colspan='2'><button type='submit' class='btn btn-primary'>Save</button></tr>\n"; echo "</form>\n"; echo "</table>\n"; } else { $save = true; if ($name=="") { $save = false; $msg = "Word field required"; } if ($save) { $query = dbquery("INSERT INTO ".$db_prefix."todoBook (name,scholar) VALUES ('$name','$scholar')"); echo "<div align='center' class='alert alert-success'><b>$name Added</b></div>"; } else { echo "<div align='center' class='alert alert-error'><b>$name already exists</b></div>"; echo "<meta http-equiv='refresh' content='8;URL=".INFUSIONS."todo/admin.php?op=book'>"; } } closetable(); } function editbook($id,$name,$scholar,$ok=true){ global $db_prefix; opentable('Edit book'); if (!$ok) { $row = dbarray(dbquery("SELECT * FROM ".$db_prefix."todobook WHERE id=$id")); echo "<table width='100%' align='center' cellspacing='0' cellpadding='1' class=''>\n"; echo "<form name='form_arg' method='post' action='admin.php?op=editbook&subj={$scholar['id']}&ok=true'>"; echo "<tr><td><b>Name</b><td><input type='text' name='name' value='{$row['name']}' placeholder='Type Title'></tr>\n"; echo "<tr><td colspan='2'><button type='submit' class='btn btn-primary'>Save</button> </tr>\n"; echo "</form>\n"; echo "</table>\n"; } else { $save = true; if ($name=="") { $save = false; $msg = "Word field required"; } if ($save) { $query = dbquery("UPDATE ".$db_prefix."todobook SET name='$name', scholar='$scholar' WHERE id='$id'"); echo "<div align='center' class='alert alert-success'><b>$name Updated</b></div>"; echo "<meta http-equiv='refresh' content='3;URL=".INFUSIONS."todo/admin.php'>"; } else { echo "<div align='center' class='alert alert-error'><b>$msg</b></div>"; echo "<meta http-equiv='refresh' content='3;URL=".INFUSIONS."todo/admin.php'>"; } } closetable(); } function deletebook($id,$ok=true){ global $db_prefix; opentable('Delete book'); $id = intval($id); if ($ok) { dbquery("DELETE FROM ".$db_prefix."todobook WHERE id=$id"); echo "<meta http-equiv='refresh' content='0;URL=admin.php'>"; } else { echo "<div align='center'><b>Are you sure you want delete</b><br><a href='admin.php?op=deletebook&id=$id&ok=true' title='YES'>YES</a> - <a href='admin.php' title='NO'>NO</a></div>"; } closetable(); } opentable('Admin Panel'); ?> <div class="navbar"> <div class="navbar-inner"> <!--<a class="brand" href="#">Title</a>--> <ul class="nav"> <li><a href="admin.php?op=type">Types</a></li> <li><a href="admin.php?op=scholar">Scholars</a></li> <li><a href="admin.php?op=book">Books</a></li> <li><a href="admin.php?op=videos">Videos</a></li> <li><a href="admin.php?op=audios">Audio</a></li> <li><a href="admin.php?op=fatwas">Fatwa</a></li> </ul> </div> </div> <?php closetable(); switch ($op) { // scholar case 'scholar': scholar(); break; case 'addscholar': addscholar($name,$photo,$bio,$ok); break; case 'editscholar': editscholar($id,$name,$photo,$bio,$ok); break; case 'deletescholar': deletescholar($id,$ok); break; // scholar case 'book': book(); break; case 'addbook': addbook($name,$scholar,$ok); break; case 'editbook': editbook($id,$name,$scholar,$ok); break; case 'deletebook': deletebook($id,$ok); break; default: break; } After submit button see the link function editscholar($id,$name,$photo,$bio,$ok=true){ global $db_prefix; opentable('Edit scholar'); if (!$ok) { $row = dbarray(dbquery("SELECT * FROM ".$db_prefix."todoscholar WHERE id=$id")); find_selected_page(); echo "<table width='100%' align='center' cellspacing='0' cellpadding='1' class=''>\n"; echo "<form name='form_arg' method='post' action='admin.php?op=editscholar&id=$id&ok=true'>"; echo "<tr><td><b>Name</b><td><input type='text' name='name' value='{$row['name']}' placeholder='Type Title'></tr>\n"; echo "<tr><td><b>Photo</b><td><input type='text' name='photo' value='{$row['photo']}' placeholder='Poto.jpg'></tr>\n"; echo "<tr><td><b>Body</b><td><textarea rows='3' name='bio' placeholder='Texterea Body'>{$row['bio']}</textarea></tr>\n"; echo "<tr><td colspan='2'><button type='submit' class='btn btn-primary'>Save</button> <a href='admin.php?op=addbook&id={$_GET['id']}'><i class='icon-edit'></i></a></tr>\n"; echo "</form>\n"; echo "</table>\n"; } else { $save = true; if ($name=="") { $save = false; $msg = "Word field required"; } if ($save) { $query = dbquery("UPDATE ".$db_prefix."todoscholar SET name='$name', photo='$photo', bio='$bio' WHERE id='$id'"); echo "<div align='center' class='alert alert-success'><b>$name Updated</b></div>"; echo "<meta http-equiv='refresh' content='3;URL=".INFUSIONS."todo/admin.php?op=scholar'>"; } else { echo "<div align='center' class='alert alert-error'><b>$msg</b></div>"; echo "<meta http-equiv='refresh' content='3;URL=".INFUSIONS."todo/admin.php'>"; } } closetable(); } I have linked <a href='admin.php?op=addbook&id={$_GET['id']}'> Link to comment https://forums.phpfreaks.com/topic/282356-linking-table-to-table-php/#findComment-1450650 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.