Canman2005 Posted December 29, 2009 Share Posted December 29, 2009 HI all I have been battling with making a SELECT funtion and wonder if anyone can help. To pull the function, i'm using $data = select("members",array("id"),"id='1'"); foreach($data as $d){ print $d["id"]; } and the function code is function select($table, $fields=array(), $where=NULL, $limit=NULL, $order=array(), $group=array()) { $string .= "SELECT ".implode(", ", $fields)." FROM ".$table; $string .= ($where) ? " WHERE ".$where : NULL ; $string .= (count($group) > 0) ? " GROUP BY ".implode(", ", $group) : NULL ; $string .= (count($order) > 0) ? " ORDER BY ".implode(", ", $order) : NULL ; $string .= ($limit) ? " LIMIT ".$limit : NULL ; $result = mysql_query($string); while($row = mysql_fetch_array($result)) { $row = array_map('stripslashes', $row); } } Can anyone help? Thanks in advance Dave Link to comment https://forums.phpfreaks.com/topic/186557-help-with-select-function/ Share on other sites More sharing options...
Buddski Posted December 29, 2009 Share Posted December 29, 2009 Are you getting any errors? I also noticed that your function doesnt return anything to the $data variable.. function select($table, $fields=array(), $where=NULL, $limit=NULL, $order=array(), $group=array()) { $string .= "SELECT ".implode(", ", $fields)." FROM ".$table; $string .= ($where) ? " WHERE ".$where : NULL ; $string .= (count($group) > 0) ? " GROUP BY ".implode(", ", $group) : NULL ; $string .= (count($order) > 0) ? " ORDER BY ".implode(", ", $order) : NULL ; $string .= ($limit) ? " LIMIT ".$limit : NULL ; $result = mysql_query($string); $data = array(); while($row = mysql_fetch_array($result)) { $data[] = array_map('stripslashes', $row); } return (empty($data) ? null : $data); } Might help you out a little.. Link to comment https://forums.phpfreaks.com/topic/186557-help-with-select-function/#findComment-985280 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.