By yonadav on
Hi,
I am not sure this is the right location to post this - please direct me to the correct location if I'm mistaken.
We have CCK installed and several content types + fields deployed. We are interested in getting access to an array which contains all of the values of one of the fields (specifically, a text field which we use as an unique ID field). We are not interested in data in the specific content type's other fields in this piece of code.
How is it possible to get our hands on such an array?
Thank you in advance,
yonadav
Comments
View or SQL
You could easily create a View that contains this information. You can even invoke the View programmatically (within a module) and get the results, which you can then process via PHP. The advantage of using a view is that it does the complicated SQL assembly for you, in the event that you need to add relationships, arguments, fields, sort order and filters.
Alternatively, you can just hand-write a SQL query if you prefer, especially if it is a very simply query. In the end, Drupal is just running MySQL and you can always access the data directly if you chose.
---------------------------------
Steven Wright
Slalom
Thanks, now stuck on the next level
Thanks, so after creating the view the code looks like this:
Any idea how to get this to work?
Doing what?
What is the goal for that code? It's not obvious to me from what you wrote.
---------------------------------
Steven Wright
Slalom
Oops
Yeah, sorry about that.
There's a content type of a field called Article ID which should be a random value but a unique one. So far I was using the PHP code to generate the random (return array etc.). But I somehow need to make sure this article ID is not used already.
PS
Any idea how to make this forum notify me when there's a new reply to my post?
Just checking for a unique ID?
If you just want to know if a random generated value is or is not being used, why not just call the view with that value as an argument? If the view results are empty, then you know the value is not being used.
The way you have it setup, you are loading all values into memory and looping over all of them. This is not really the most efficient way of finding out if the value is unique.
FYI I found a helpful post:
http://drupal.org/node/342132
---------------------------------
Steven Wright
Slalom
Works!
Thank you for your help, what you have said works great!