Jump to content

Can someone please help me write php code for Drupal 6?


jdmcelica01

Recommended Posts

I am in the process of finishing a review website and am looking for some php code for the fivestar voting target. I have two content types which include Review and Location. In the Location content type I am using the node comments module. With this module, the core drupal comments are replaced with the review content type. When a user decides to review a location, they select the "add a new review" link on that particular location node which opens the review content type. The Review content type includes a single CCK field which includes each day of the week and another field which contains a single CCK fivestar voting widget. When filling out a review, I would like the person to select the day of the week they visited a particular location as well as a rating for that particular day. After submitting the review, I would like the vote to be saved to the parent node with a tag corresponding to the day of the week which was selected by the user. In CCK fivestar there is a voting target box which allows you to input custom php code to designate where the vote is saved. I was thinking I add 7 "if" statements in this box, one for each day of the week. Something similar to this:

 

If field_dayofweek='sunday'

then save to parent node id with sunday tag or voting axis

 

If field_dayofweek='monday'

then save to parent node id with monday tag or voting axis

 

If field_dayofweek='tuesday'

then save to parent node id with tuesday tag or voting axis

 

etc...

 

I believe that something similar to this would work, but am having difficulty in determining what the correct syntax would be. If you have any experience with php and drupal I would really appreciate some assistance. This is the last feature that needs to be implemented before the site goes live. Any assistance at all would be very helpful.

 

Thank you.

Link to comment
Share on other sites

Case statements work easier for multiple if/else statements. You can try something like this:

switch($field_dayofweek) {
case "sunday":
   // save to parent node with sunday
  break;
case "monday":
  // save to parent node with monday
  break;
case "tuesday":
  // save to parent node with tuesday
  break;
...
  default:
  // whatever you want default statement to be
  break;
}

Link to comment
Share on other sites

Thank you for your response to my question. After looking at the code you posted, I was wondering if you have any insight one what I should replace "// save to parent node with..."? Is it just a return command? Something similar to this:

 

<?php

switch($field_dayofweek) {

case "sunday":

  return parent node id with sunday tag

  break;

case "monday":

  return parent node id with monday tag

  break;

case "tuesday":

  return parent node id with tuesday tag

  break;

...

  default:

  // whatever you want default statement to be

  break;

}

?>

 

Thank you again for your assistance.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.