Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By davecoventry on
$query=db_query('SELECT title FROM {node} WHERE type = \'new_boats\' ');
$categories=Array('');
while($row=db_fetch_array($query)){
$categories[]=$row['title'];
echo $row['title'];
}
Can anyone suggest what's wrong with the above code?
I had something similar working under D6, but I'm getting just a blank page.
The above code is in a block.
http://localhost/bmarine/#overlay=?q=admin/structure/block/manage/block/...
Comments
In D6, you weren't supposed
In D6, you weren't supposed to directly insert values into queries. In D7, you cannot:
Read more about the Database API here: https://drupal.org/node/310069
Thanks
Thanks, Jaypan.
No WSOD, but no result either.
I have altered my code:
The page is almost rendered as expected, but the code is not executed.
There is no "~~~~~~~~~~~~Check~~~~~~~~~~~~~~~", no print_r($result) and the node's title isn't printed either.
Well, you've given us no
Well, you've given us no context as to where your code lies, what it is doing, and what it is supposed to be doing, so it's pretty hard to give you a relevant answer.
But, you almost never print things in Drupal, you return them. Which is probably why you aren't seeing anything.
I think I said in the opening
I think I said in the opening post that it's in a Block. I even gave the URL. :)
This will display the contents of $result.
This doesn't.
The if($result) block appears to suppress not only the printing of the Title, but also the print_r($result).
The only reason I'm printing the output is to make sure that the arrays have the values I'm expecting.
Thanks, again.
Thanks again for your help, Jaypan.
It seems to have come together as expected.
I think I had a typo in my code :blush:.
Thank you!
~ Dave
I think I said in the opening
So you did! Apologies :)