I have a SQL string and two functions which have string returns. I’m trying to combine them like that:
JavaScript
x
echo "INSERT INTO product_cat( ".columnPrinter(getTables("product_cat"))." ) VALUES ( ".dataPrinter($_POST['addMenu'])." )";
but functions are not printing in the right place and they all just go to the first not in parentheses! the result is like: Result
My function is :
JavaScript
function dataPrinter($data){
foreach($data as $dt){
$names .= "'".$dt."',";
}
echo rtrim($names,",");
}
function columnPrinter($columns){
foreach($columns as $clm){
$names .= $clm['Field'].",";
}
echo rtrim($names,",");
}
I tried using variables even though the result was the same.
Advertisement
Answer
Just return the result, don’t print it:
JavaScript
function dataPrinter($data){
$names = '';
foreach($data as $dt){
$names .= "'".$dt."',";
}
return rtrim($names,",");
}
function columnPrinter($columns){
$names = '';
foreach($columns as $clm){
$names .= $clm['Field'].",";
}
return rtrim($names,",");
}