Jump to content

Help with SELECT FUNCTION


Canman2005

Recommended Posts

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

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..

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.