Notes of the PHP from within Drupal 2nd session

Manal's picture
Submitted by Manal on Sun, 21/01/2007 - 00:15.
::

Here are the notes of the PHP from within Drupal, 2nd session

Examples we used:

Example 1:

between the php tags:


$result = taxonomy_select_nodes( array(1, 3), 'or', 'all', true);
$html = node_title_list($result);
$html.= theme('pager');
print $html;

We tried to guess what these functions do from their output, then we read their documentation

Example 2:

Working on the same poll of the last example in the 1st session, we wanted to get the number of votes corresponding to each choice.

between the php tags:


$node = node_load(55);
$i=$_GET['choice'];
print $node->choice[$i]['chvotes'];

and add to the url:


?choice=1

try 0 and 2 instead of one, to get the number of votes for the first and third choice respectively.

Example 3:

Doing the same thing but using Drupal functions.

between the php tags:


$node = node_load(55);
$i=arg(2);
print $node->choice[$i]['chvotes']."<br />";
print arg(0)."<br />";
print arg(1)."<br />";
print arg(2)."<br />";
print arg(3);

and add to the url:


/0

Functions that we used in the 2nd session:

We can look up drupal functions @ http://api.drupal.org, to learn about what does a particular function do, what type of arguments (and default arguments) does it take, etc.

Drupal functions we learned:

PHP functions:

HTTP variables:

$_GET
for getting data from the database. usually the URL changes, so that u can use the same URL to GET the same data (results) if used at other times.
$_POST
for submitting/sending data to the database, e.g. in forms.