I'm using a table that stores metadata about other tables in the db, and I want to pull out a comma-separated string to use in an INSERT query as well as create variables out of it, pre-pending "$" in front of each part of the array.
Problem One: Ignoring First Element
The query looks like this:
$element_list = "Select tblFieldName from tblTables where tblNumber = 2 AND tblGroup='AD'";
Then I wrote a function to implode the result for use in the INSERT statement:
function array_sql_list($resultset, $rowcount, $fieldname) {
if ($rowcount > 0)
{
while ($column = mysql_fetch_object($resultset))
{
$row_names[] = $column->$fieldname;
}
$row_names = implode(", ",$row_names);
return $row_names;
} elseif ($rowcount < 1) {
echo "Nothing to add";
}
}
It's not the prettiest thing in the world, but it does work...kinda. The problem is that it's returning 23 of the 24 fields, ignoring the first element of the result. Can anyone recommend a better way to do this so that the result captures all elements?
Problem Two: Prepending "$"
Actually, two sub-issues in one.
The first is that I'm using the same result set as above, but on sending it through a loop to prepend the "$", it tells me that the result set is no longer an array. I tried to reset() the array (thinking that the pointer was stuck on the last element from the first loop through), but that didn't work. I know it's an array because it worked the first time through, but arguing with the keyboard isn't getting me anywhere.
The second issue is that prepending the "$" to each result, then imploding them into a comma-separated list isn't working at all. I want to write a function to prepend the "$", then implode the result - is there a better way to accomplish this?
Thanks in advance for any suggestions,