php

 
Exercises result

Create your module with info file. I named mine ac_exercise.module. Replace anything with ac_exercise with the name of your module
Here's my ac_exercise.info file:

name = Exercise
description = Exercise (ac_exercise)
core = 7.x
package = AC Modules

Here is my ac_exercise.module file:

<?php

function ac_exercise_menu()
{
$items['health/exercise'] = array(
'page callback' => 'ac_exercise',
'access arguments' => array('view exericse'),
'title' => 'Exercise',
'description' => 'Exercise',
'weight' => 2,
'type' => MENU_CALLBACK,
);

return $items;
}

/**
* Implements hook_perm().
*/
function ac_exercise_permission()
{
return array(
"view exercise" => array("title" => "View Exercise"),
"modify exercise" => array("title" => "Modify Exercise"),
);
}

function ac_exercise()
{
return drupal_get_form("ac_exercise_modify_form");
}

function ac_exercise_modify_form($form, &$form_state)
{
//TODO: Make this dynamic
$obj = new stdClass();
$obj->id = 1;
$obj->name = "Lat Pulldown";
$obj->weight = 50;
$obj->reps = 10;
$obj->sets = 3;

$obj2 = new stdClass();
$obj2->id = 2;
$obj2->name = "Mid Row";
$obj2->weight = 20;
$obj2->reps = 8;
$obj2->sets = 4;

$records = array($obj, $obj2);
//End of variables

$form['exercises'] = array(
'#type' => 'fieldset',
'#title' => t('Exercises'),
'#theme' => 'ac_exercise_exercises',
);

foreach ($records as $record)
{
$form['exercises']['exercises_name_' . $record->id] = array(
'#type' => 'textfield',
'#value' => $record->name,
'#size' => 20,
);

$form['exercises']['exercises_weight_' . $record->id] = array(
'#type' => 'textfield',
'#value' => $record->weight,
'#size' => 3,
);

$form['exercises']['exercises_reps_' . $record->id] = array(
'#type' => 'textfield',
'#value' => $record->reps,
'#size' => 3,
);

$form['exercises']['exercises_sets_' . $record->id] = array(
'#type' => 'textfield',
'#value' => $record->sets,
'#size' => 3,
);
}

return $form;
}

function ac_exercise_theme()
{
return array('ac_exercise_exercises' => array('render element' => 'form'),);
}

function theme_ac_exercise_exercises($variables)
{
$form = $variables['form'];
$rows = array();

for ($i = 1; $i <= 2; $i++)
{

$row = array();
$row[] = drupal_render($form['exercises_name_' . $i]);
$row[] = drupal_render($form['exercises_weight_' . $i]);
$row[] = drupal_render($form['exercises_reps_' . $i]);
$row[] = drupal_render($form['exercises_sets_' . $i]);
$rows[] = array('data' => $row, 'id' => 'exercise_' . $i);
}
$header = array(t('Exercise'), t('Weight'), t('Reps'), t('sets'));
$output = drupal_render_children($form);
$output .= theme('table', array('header' => $header, 'rows' => $rows, 'id' => 'exercises_table', 'class' => 'form-item'));

return $output;
}

Fatal error: Uncaught SCA_RuntimeException: Instantiation of unknown type :http://Reward Reseller thrown in C:\...\Reward\SCA\Bindings\local\Proxy.php on line 138

This error is generated when using SCA for PHP. The cause of this error is most likely due to missing targetNamespace="http://Reward" in the xsd file

Tags: 

The cause of this error is most likely due to the statement object returning false when attempting to be created. The cause of the statement object returning false is that the SQL statement is incorrect. Try running the same SQL command line and see if you get errors there.


$updateStatement = "UPDATE $db_table SET refID = ? WHERE trans_num = ?";

$stmt = $mysqli->prepare($updateStatement);

if(!$stmt) echo "error"; //Will print "error"

$stmt->bind_param("ss", $newTransNum, $originalTransNo); //This fails

//The SQL statement is wrong (there is no field trans_num in the table)

Tags: 

I was looking all around for this and even tried to do it manually, but I found this function number_format. I used it to make sure that a dollar amount was to have two decimal places. Original amount: 5.3
$newAmount = number_format(5.3, 2);
$newAmount = 5.30.

Tags: 

To see if a function is defined, use the function function_exists. It takes a function name (as a string) as the parameter.
http://us3.php.net/function_exists

Tags: 

Pages

randomness