uramagget Posted April 5, 2008 Share Posted April 5, 2008 I'm having so many headaches building a function for selecting data from a Database easier in mySQL, so I tried a simple function out: function select($table, $fields, $options = null, $loop = false) { if (!defined('MYSQL_NOCONNECT')) { if (isset($table) && isset($fields)) { $sql = "SELECT ".$this->escape($fields)." FROM ".$this->escape($table)." ".$options.""; $result = mysql_query($sql); if ($result) { if (mysql_num_rows($result) > 0) { return $result; } else { return false; } } } else { echo "Wrong number of parameters supplied for select(). Try again, buddy boy."; exit; } } else { return null; } } Usage if (is_numeric($_GET['view'])) { $view = $_GET['view']; $sub = $mysql->select("submissions", "*", "WHERE sub_id=".$mysql->escape($view).""); if ($sub) { while ($subview = mysql_fetch_array($sub)) { //Define Variables for template $sub_id = $view; $sub_name = $subview['sub_title']; $sub_author = $subview['sub_author']; $sub_description = $subview['sub_description']; //Load Template $tpl->load('submission/submission_view'); } } else { echo "The requested submission was not found. Are you sure it exists?"; } } else { echo 'Numerical values only.'; } But then, all it returns is: Resource id #15 I'd really appreciate if anybody could help me out with this headache.. Link to comment https://forums.phpfreaks.com/topic/99731-custom-select-function/ Share on other sites More sharing options...
uramagget Posted April 5, 2008 Author Share Posted April 5, 2008 Seems to be that there was a syntax error in my post. I have changed it. Link to comment https://forums.phpfreaks.com/topic/99731-custom-select-function/#findComment-510162 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.