Hello all!

An utter newbie at Drupal, I'm slowly getting along with my little site, but this thing is killing me! I'm trying to put together a CV-maker of sorts using a Flexinode node, where I want to display taxonomy terms as so (strong=taxo-terms):

Born in Happyville, 1978. Lives and works in Taxonomyhell, Norway.
Artistic expression: Sculpture, Installation and Video.

This is what I have in my node-flexinode-n.tpl.php file so far (it may be extra stoopid due to fatigue):

<?php		    $vocabulary_id = 5;
				$userid=$user->uid;
				$content_type = 'cv';
				
				$result = db_query("SELECT term FROM $vocabulary_id WHERE term AND $uid AND n.status = 1 ORDER BY created DESC");
							
				$output = '';
				while ($category = db_fetch_object($result)) {
				$output .= ($category->name);	
				}

				print $output;
				?>

I know it must be possible, but my Drupal-skills are not up to it yet! Anyone have a quick solution out there? It would be greatly appreciated!!!

Best regards,
joeboris

Comments

ericwagner’s picture

I needed to do something similar. See:

http://drupal.org/node/31841#comment-131629

joeboris’s picture

Thank you, sir!

This solved my entire problem in a matter of minutes! An excellent piece of informaion to wake up to after a late night of code-frustration!!

mpamphile: Hehe, I'm aware of the critical flaws in my "code". When I posted, I had been fumbling around in the dark for so long that it probably looked even more retarded than necessary. I will be reading up on sql queries after this!

Best regards,
joeboris

pamphile’s picture

The SQL is seriously flawed. The FROM clause is flawed. It is searching a number. It should search a actual database table.

Wholesale Directory
Businesss Letters
Bigvertiser.com

BlackSash’s picture

What that query is actually saying now is:

SELECT term FROM 5 where term AND $uid AND n.status = 1 ORDER BY created DESC;

first of all,
SELECT ... FROM: should be all the fields you want returned: if you want only the term names, that's fine, but you do have to specify the table to pull them from.

SELECT [prefix].term FROM [table containing terms] AS [prefix to use for table]

The WHERE should contain not only what you want to look for, but also what value it should be. WHERE term AND n.status ain't gonna cut it.
If you want to use a specific term (or set of terms) use the term = '[value]' syntax, otherwise omit it.

WHERE term = [list of terms to compare against] AND uid = $user->uid

OR

WHERE uid = $user->uid

Further more: n.status won't do anything whatsoever, because you're using the prefix 'n' without defining it. Also, you haven't involved the node table into your query, as a result of which you can't pull records from it.

The entire query sould probably read something like this:

SELECT [prefix].term FROM [table containing terms] AS [prefix to use for table] INNER JOIN {node} AS n ON [prefix].nid = n.nid WHERE [prefix].uid = $user->uid AND n.status = 1 ORDER BY n.created DESC

Of course, this only works if you have already figured out which user the profile belongs to, because I believe the $user global returns the currently logged in user.

As a little excercise, i'll leave it up to you to figure out which tables to use. (Also, i haven't used flexinode in like, forever ;) )

Come to think of it... I may have misunderstood your original question. If this isn't what your looking for, could you please try to describe what it is you're trying to do more clearly?

-------------------------------
GU d- -p+ c++++ l++ e* m* s+ n+ h+ f? g+ w+++ t- r y?
Madcap - design - development - consultancy
http://www.madcap.nl - Running on Drupal, of course.

joeboris’s picture

Mr.Wagner directed me to a snippet which worked expertly, thankfully!

I'm no coder (!), and just getting into Drupal and PHP, so for now, I'm happily (sometimes miserably) banging away at the cut and paste buttons, trying to get stuff to work and learning a bit along the way.

After last night, I realize that I will have to seriously read up on basic queries, and your exercise will surely help!

Thanks!!

Best regards,
joeboris

pamphile’s picture

your welcome.

i was a similar situation at 3:30 AM yesterday and got help. see http://drupal.org/node/70258