Robust: The underlying data structure might change with a module update one day Your query would stop working while EFQ would not.The reason that changing to using EFQ is a good idea (apart from possibly fixing your issue) is that it will make your code more robust, transferable, extendable and secure. You should follow Oberoi's advice and use EntityFieldQuery (EFQ). Without knowing your requirements I couldn't advise on the best approach for your current query. ![]() If you want optimal performance and don't need to restrict results based on node access then db_query() is likely the best method. On the topic of EntityFieldQuery, there are multiple different ways to run a query in Drupal and the best solution depends on the particular use case. In the above example I also changed the type "IN" operator to "=" because you only had one value, removed the redundant brackets around the where clause and removed the table alias to make the query as simple as possible. When you do it like that Drupal will sanitize the $value and it will also know that it is a string and wrap it in quotes.įor more information see the documentation for Drupal's database API - Static queries. $result = db_query($query, array(':title' => $value)) That is not a great solution either though because it opens you up to possible SQL injection attacks so instead, use Drupal's built in sanitisation like this: $query = "SELECT title, type It should be like this: AND node.title = '". I'm going to assume the problem is that you are not putting quotes around your title string, so it is trying to use the title as a database column and it fails. What is wrong with my Query? is there something that stops me using the $row->title in drupal that I don't know about? I just cant figure out what is wrong with my SQL query. I have checked the value of $value and it returns the expected result. I have managed to get all the titles out and print them but as soon as i bring $value into it it breaks. After that I loop through them and get the value printed. So as you can see I get the value of title at the row I'm on and compare it to every value for title in the database, then return only results that match. $wat = $result->fetchAll(PDO::FETCH_COLUMN, 0) So I have built a view and selected a couple of column and now I want a column that will print out the name of the title the number of times it appears in the database. Here is the code as it stands, I've done loads of variations of it but cant get the result and think that there must be a core problem with my logic. I have built a view and cannot get the SQL query to return the result I want. I have a large table with lots of values and want to check if any of the names are repeating and only display those results.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |