D. Fox
D. Fox

Reputation: 1

Finding the row id number of a specific field

The organization that I work for has a voting platform that was built before my tenure and I cannot find the specific index needed to get the voting conditions needed to trigger (limiting votes to one per person). I was told that a print_r would give me the appropriate data needed but I am not a php developer by any means and can't quite figure out how to even run the print_r. Code below:

if ($thewebform->data[6][0] == $row->id) //this is the row that needs to be 
edited

echo '<link type="text/css" rel="stylesheet" 
href="/sites/default/files/awardsvoting/awardsvoting.css"/>';
echo '<hr/>';
echo "<strong>form name</strong><br/>";


// get the webform module
include_once(drupal_get_path('module', 'webform') 
."/includes/webform.submissions.inc");

// get all the webform submissions with the nid of the webform
$filters = array('nid' => 6548);

try {
$thewebforms = webform_get_submissions($filters);
// print_r($thewebforms);

//determine how many votes the project is entitled to, based on membership 
type
// if it's a corporate membership, they get two votes
if ($row->membership_type == '6'){
$votesallowed = 2;  
}
// if it's a non-profit membership, they get two votes
else if ($row->membership_type == '3'){
$votesallowed = 2;  
}

// if it's a student membership, they get none
else if ($row->membership_type == '5') {
$votesallowed = 0;  
}

// if it's any other type of membership, they get one
else {
$votesallowed = 1;
}
//echo "votes allowed = " . $votesallowed;
// figure out how many votes the project has already cast, if any
// the index of $thewebform->data has to be readjusted for the index of the 
org_id in the webform
$votesused = array();
    foreach($thewebforms as $thewebform) {
    // echo $thewebform->data[6][0];
    // print_r($row->id);
    if ($thewebform->data[6][0] == $row->id) {
        $votesused[] = $thewebform;
        }
    }

// determine if the project has any votes left  
$votesremaining = $votesallowed - count($votesused);
//echo "remaining votes: " . $votesremaining;
echo "Votes remaining: " . $votesremaining . "/" . $votesallowed . "<br/>";

if ($votesremaining > 0) {
    echo '<a class="myButton" href="voting url' . $row->id . '&cid=' . 
$_SESSION[CiviCRM][userID] . '">Vote! 
</a>';
}
echo '<hr/>';
}
catch (exception $e) {
drupal_set_message($e->getMessage());
}

Upvotes: 0

Views: 46

Answers (1)

Worthwelle
Worthwelle

Reputation: 1271

There is a print_r for the row ID already in the code on line 10. You can uncomment this by deleting the //. This will show you all the data inside $row->id, which is likely just a number. I don't know what the rest of your code or your database looks like, so this may or may not actually give you what you want.

There is more information about print_r in the documentation.

Doing a print_r like this is part of what's called debugging. Be sure to do your debugging only on a development server and not in the live environment. Otherwise, anyone using the voting system might be able to see the debugging information.

EDIT: As mentioned in the comments below, you can also try using echo instead of print_r by replacing

print_r($row->id);

with

echo $row->id;

Upvotes: 1

Related Questions