Not sure if I can explain this but here goes.
Im writing a few functions and the main one I will want to use is a simple straight forward "grab results from a SQL query". In the past Ive written each one seperately however Im now starting to get properly into OOP and am using classes (yay finally! I hear you cry!!!).
So using a few basic classes I have a simple pull results query of:
So I then thought, I can pass the query into the function to make it reusable ie.
great so far but heres where I come unstuck.
It won't always have the same table, therefore not the same output fields in the array and I may well want the results formatted differently.
With that in mind I thought, just pass the output string into the function as well.
eg
and thats where it fails, I get a "unexpected T_ENCAPSED_AND_WHITESPACE" error and no matter what I do I cant figure out how to correct it.
Basically I was calling it with:
Im guessing its to do with the ' chars but I've tried doing \' and that doesnt work. Am I missing a simple trick here? Am I doing this all wrong? or am I on the right lines but just making a slight mess of it?
Im writing a few functions and the main one I will want to use is a simple straight forward "grab results from a SQL query". In the past Ive written each one seperately however Im now starting to get properly into OOP and am using classes (yay finally! I hear you cry!!!).
So using a few basic classes I have a simple pull results query of:
Code:
function pull_sponsors2() {
$connector= new DbConnector();
$result = $connector->query("SELECT * FROM sponsors");
while($row = $connector->fetchArray($result)) {
echo "<li><a href='".$row['url']."' title='".$row['name']."'><img src='images/sponsors/".$row['logo']."' alt='".$row['name']."' class='sponsorlogo'></a></li>\n";
}
}
So I then thought, I can pass the query into the function to make it reusable ie.
Code:
function resueable_query($thequery) {
$connector= new DbConnector();
$result = $connector->query(thequery);
while($row = $connector->fetchArray($result)) {
echo "<li><a href='".$row['url']."' title='".$row['name']."'><img src='images/sponsors/".$row['logo']."' alt='".$row['name']."' class='sponsorlogo'></a></li>\n";
}
}
great so far but heres where I come unstuck.
It won't always have the same table, therefore not the same output fields in the array and I may well want the results formatted differently.
With that in mind I thought, just pass the output string into the function as well.
eg
Code:
function resueable_query($thequery,$output_string) {
$connector= new DbConnector();
$result = $connector->query(thequery);
while($row = $connector->fetchArray($result)) {
echo $output_string;
}
}
and thats where it fails, I get a "unexpected T_ENCAPSED_AND_WHITESPACE" error and no matter what I do I cant figure out how to correct it.
Basically I was calling it with:
Code:
resueable_query("SELECT * FROM sponsors","<li><a href='$row['url']' title='$row['name']'><img src='images/sponsors/$row['logo']' alt='$row['name']' class='sponsorlogo'></a></li>\n") {
Im guessing its to do with the ' chars but I've tried doing \' and that doesnt work. Am I missing a simple trick here? Am I doing this all wrong? or am I on the right lines but just making a slight mess of it?