Hi guys,
I have spent a good proportion of time today looking into expanding a drupal site I inherited, convinced that the issues I face were down to my bespoke SQL query.
I have since realised that the SQL is ok (checked it in PHPMYadmin and got it executing of sorts within the drupal website). So I am happy I am getting all the results from the database I need, looping through them and outputting them on the page in the specific markup.
The problem I have is where the loop is displaying. I cannot seem to figure the theming system or understand what is going on in template.php.
Let me explain:
The code I needed to change was in the template.php file. My understanding is that this file allows you to overide certain functions and theme elements.
Within the template.php file this is the code I needed to change:
//old function from original development
function abc($node,$submitted,$node_url) {
//execute code
}
So I added my code within function abc(), as I wanted it to be output where the old code was output.
This is my psuedo code for the sql and the loop:
function abc($node,$submitted,$node_url) {
$sql = 'my sql query'
$results =db_query($sql);
while ($data = db_fetch_array($results)) {
//output my results here
}
}
What led me to believe that the sql was wrong is that I should have got 23 results, but I was getting a lot more duplicate entries. After wasting alot of time looking in the wrong place, and scrutinising the sql, I realised that it was the function executing the sql and the loop multiple times, not the sql returning duplicate entries. I did this like so:
function abc($node,$submitted,$node_url) {
$sql = 'my sql query'
$results =db_query($sql);
$x = 1;
while ($data = db_fetch_array($results)) {
if ($x == 1) {
echo '<p style="background-color:#ccc;">'. $x . '. '.$data['title'] . '</p>';
}else{
echo '<p>'. $x . '. '.$data['title'] . '</p>';
}
$x = $x + 1;
}
}
As the code executed I was expecting an incremented number to go on for as many duplicate entries and shade the first entry's background to grey, but it did not. At result 23, it reset itself to 1 and shaded that entry's background to grey, indicating to me that it was the function executing the sql and the loop multiple times.
I am not wholly sure what this abc() function is, apart from the fact that when I place my code within it, the output displays where I need it to on a specific page and nowhere else (with no duplicate entries).
When I take my code out of this function (still within template.php), my code is output in the head of all pages which is not desirable.
Does anyone have any ideas as to what might be happening, where I can look to find out what this function is or know of a way for me to determine the display of my code?
I have been reading a bit about themes etc, but working with someone else's code is turning into a bit of a confusion nightmare.
Cheers in advance!