When using the function, it returns:PHP Code:function insert($table, $fields, $values)
{
$q .= "INSERT INTO `" . $table . "` (";
foreach ($fields as $field)
{
$q .= "`" . $field . "`, ";
}
$q = str_replace(strrchr($q, ','), '', $q);
$q .= ") VALUES (";
foreach ($values as $value)
{
$q .= "'" . $value . "', ";
}
$q .= ");";
INSERT INTO `members` (`userid``username``password`) VALUES ('1', 'dan', 'dan', );
If I use the strrchr function like so:
It returns:PHP Code:$string = "('value1', 'value2', '2value3', 'value4',);";
$string = str_replace(strrchr($string, ','), ");", $string);
('value1', 'value2', '2value3', 'value4');
Which works....
As you can see my main goal is to get rid of the last comma in a mysql query to make a function for queries.
If you know an alternative that works as well, though I'm curious why this does not work.
Thank you.





Bookmarks