3raser Posted June 11, 2012 Share Posted June 11, 2012 <?php require('../structure/base.php'); require('../structure/forum.php'); require('../structure/forum.forum.php'); require('../structure/database.php'); require('../structure/user.php'); if($user->getRank($user->getUsername($_COOKIE['user'], 2)) > 2) { //get selected threads and our action $threads = explode('-', $_GET['threads']); $action = $_GET['action']; //ACTION LIST //1 = HIDE //2 = LOCK //3 = MOVE //4 = AUTO-HIDE //5 = STICKY //6 = DELETE if($action == 3) { foreach($threads as $thread) { moveThread(); } function moveThread($id, $moveTo) { //make sure it exists $thread = $database->processQuery("SELECT * FROM `threads` WHERE `id` = ? LIMIT 1", array($id), true); if($database->getRowCount() == 1) { //array on a different line so it's not so messy $values = array($thread['parent'], $thread['title'], $thread['username'], $thread['date'], $thread['lastpost'], $thread['lastposter'], $moveTo.':'.$id, $thread['timestamp'], $thread['autohiding']); //thread exists, so let's continue and create a new thread where it was orgionally to indicate it has been moved $database->processQuery("INSERT INTO `threads` VALUES (null, ?, ?, '', ?, ?, '', ?, ?, '', '', '', '', '', ?, '0', ?, ?)", array($values), false); //now let's make the orgional thread be moved to the selected destination $database->processQuery("UPDATE `threads` SET `parent` = ? WHERE `id` = ? LIMIT 1", array($moveTo, $id), false); } } } else { } } else { $base->redirect('index.php'); } ?> I'm completely rewriting my website to more efficient/neater code, and I'm curious: the function in the above code moveThread() - should I leave it where it's at, implement the code within the function as a part of the foreach loop, or should I put the function at the very bottom of the page where it's in every scope? Quote Link to comment https://forums.phpfreaks.com/topic/263969-where-should-i-place-this-function-im-looking-for-the-neatness-factor/ Share on other sites More sharing options...
smoseley Posted June 11, 2012 Share Posted June 11, 2012 Bottom of the page. Better yet, put it in an external php script so it can be reusable in other code. Quote Link to comment https://forums.phpfreaks.com/topic/263969-where-should-i-place-this-function-im-looking-for-the-neatness-factor/#findComment-1352783 Share on other sites More sharing options...
3raser Posted June 11, 2012 Author Share Posted June 11, 2012 Bottom of the page. Better yet, put it in an external php script so it can be reusable in other code. That's actually what I was thinking of doing, but I'm 99% certain it won't be used anywhere else. Quote Link to comment https://forums.phpfreaks.com/topic/263969-where-should-i-place-this-function-im-looking-for-the-neatness-factor/#findComment-1352795 Share on other sites More sharing options...
smoseley Posted June 11, 2012 Share Posted June 11, 2012 Bottom of script should be fine then. Quote Link to comment https://forums.phpfreaks.com/topic/263969-where-should-i-place-this-function-im-looking-for-the-neatness-factor/#findComment-1352804 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.