G's blog

Just some stuff, mostly random.

SQL update query with a subselect

update nat inner join (select tn.tid, tn.nid from node n
inner join term_node tn on tn.nid = n.nid
inner join term_data td on td.tid = tn.tid and td.vid = 11
where n.type = 'customer') s on s.nid = nat.nid set nat.tid = s.tid
where nat.nid = s.nid

Using Node title as a view argument in Drupal

Its always better to use the nid instead of the node title as a view argument, but in a very special case I need to use the node title as a view argument, as the node argument is also a vocabulary term and rather than having a clumsy way of passing it in the url it be much better to use the node title.

Voila!

Simple as that.

Validate all required fields in jquery

$(document).ready(function(){
$('#webform-id').submit(function(){

var $val=0;

//check text fields
    $("input.required").each(function(){
        if (($(this).val())== ""){
              $(this).addClass("error");
              $val = 1
        }
        else{
            $(this).removeClass("error");
        }
     
    });
  // if you want to check select fields 
    $("select.required").each(function(){
        if (($(this).val())== ""){
              $(this).addClass("error");
              $val = 1
        }
        else{
            $(this).removeClass("error");
        }
     
    });
    if ($val > 0) {
        alert('Please enter the hightlighted values');
        return false;
    }
    });
 });

This is the jquery you need for a form where all the required fields have a class=”required”. This code will loop through each input/select field with class required and add class error:

select.error { border: 2px solid red; }

For a form like so:

<form action="submission_url" method="post">

<select id="salutation" class="form-select required" name="salutation">
<option value="" selected="selected">- Select -</option>
<option value="Mr">Mr</option>
<option value="Mrs">Mrs</option>
<option value="Miss">Miss</option>
<option value="Sir">Sir</option>
<option value="Doctor">Doctor</option>
<option value="Professor">Professor</option>
</select>

<input type="text" value="" name="firstname" class="required"/>

<input type="text" value="" name="lastname" class="required"/>

</form>

And will do the follow:

             

Oblivion, questions unanswered

image

*** LOTS of Spoilers ***

I enjoyed the movie even thought some of it was quite predictable, but they left a lot of questions unanswered.

1. Why was Area 49 Jack is the Jack they should approach? Morgan Freeman says its because she said he was the one. Who is She?

2. In the end Area 52 Jack shows up to find Julia, because its him, its his memories, then why couldn’t they approach the Area 52 or Area 1002 Jack, I mean they are all the same, they all dream about Julia, how is Area 49 any different.

3. Why did the Scavs set up the beacon to get the odyssey down now. Its been out there for 60 years how come is hasn’t re-entered earth already? And how did they know now was the right time? Clearly it wasn’t for just the plutonium or was it just that and Julia being in there is just a coincidence?

4. The flight recorder from the Odyssey is in the stasis pod rather than with Jack and Vick in the command module/cockpit. Lets say there were two recorders one for the pod and one for the cockpit, then how come the recording for the pod has the conversation between Jack and Vick after they ejected the pod.

5. What happened to all the other thousands of Victorias and Jacks who were manning all the other Areas. Surely there are thousands more. What happens to them after the ‘Tet’ is destroyed.

Despite the unanswered questions, I enjoyed the movie for what it was. It was well done and had a good storyline. I give it a big thumbs up.

Windows junction links

Go to the path that you need to create the junction link in:

D:>cd dev/drupal/sites

D:\dev/drupal/sites>mklink dev.mysite.com www.mysite.com

mklink link target

link being the folder that  you want to create

target being the one that you want to point to

or specify the whole path in the link and target, if you run the command from you C: or D: drive

I am creating a local development environment for my drupal and using git to clone the files etc to the development server. I have my own internal url dev.mysite.com. I dont want to copy all the files that are in www.mysite.com folder in sites to dev.mysite.com as commiting changes etc back would be a real problem so I am creating junction links so I can use the same files that are committed.