By Phillip Mc on
Hi Guys,
Need some sql help with a snippet.
I am trying to create a PHP snippet that lists the teasers of a specific cck content type, sorted by a specific cck field.
<?php $nlimit = 10; ?>
<?php $contentname = 'content_gig'; ?>
<?php $result1 = pager_query(db_rewrite_sql("SELECT n.nid, n.created FROM {node} n WHERE n.type = '$contentname' AND n.status = 1 ORDER BY n.created ASC"), variable_get('default_nodes_main', $nlimit)); ?>
<?php while ($node = db_fetch_object($result1)) {$output2 .= node_view(node_load(array('nid' => $node->nid)), 1);}; ?>
<h1>Upcoming Gigs</h1>
<?php print $output2; ?>
the above snippet is sorted by n.created or the "date it was created". I would like to change that to be a specific cck field. i.e. order by field_date_time_on_stage ASC
Where field_date_time_on_stage is a date field set with each cck node from the content type 'content_gig'.
I've tried fiddling about with INNER JOIN, but, I'm unable to get it working.
Any SQL wizards out there able to help? Even a link to another forum post/help page would help.
thanks.
phil
Comments
btw
fortgot to mention - I have already tried views.module but that's like using jcb to eat your dinner for what I want to do.
phil
I have already tried
I'm not positive what jcb is, but I understand the sense of what you are saying.
But are you sure? This seems to me to be exactly what Views is designed to do, and exactly the type of situation it is supposed to handle.
---
www.whatwoulddrupaldo.org
JCB
the views module is great but, to give you an idea to what a JCB looks like: http://www.publiquip.com/photo/JCB-3CX-Backhoe-K.jpg
Phil
cck doesn't lend itself to
cck doesn't lend itself to being manually queried. View module is really the way to go here. If you had to do it manually here's a completely untested guess to start with. You'd have to look up your field, I have a textfield set up from playing with and it uses the table node_data_field_myfield with the data stored in the column field_myfield_value so the field is 'field_myfield'. Not sure if cck uses different structures for different data types...
thanks
thanks for posting that debtman...but I wasn't able to work it out from there. I looked up the field in phpmyadmin and the ql query that gives me is:
Using your snippet, here's my revised attempt:
Can you spot anything obviously wrong with the above? (it's giving me no output)
Phil
try this
this should work for you Phil.
Dub
Currently in Switzerland working as an Application Developer with UBS Investment Bank...using Drupal 7 and lots of swiss chocolate
thanks Dub
That works but, it only displays the teasers, which is fine as I can add an extra field to my cck content type to get around that.
It would be useful, though if the snippet could display the titles as well as I have other cck content types that I would like to use the same snippet for.
Phil
Corrected Snippet..
Hi Phil,
This is the corrected snippet with node Titles included.
I just tried this with 4.7.3 and it works. Please note that I'm not an expert in sql queries, so there is probably a much simpler and shorter way of doing this.
dub
Currently in Switzerland working as an Application Developer with UBS Investment Bank...using Drupal 7 and lots of swiss chocolate