<?php
$id = $modx->documentIdentifier;
echo $id; //just for debugging
$result = $modx->db->query( 'SELECT...
// long nasty query
...WHERE
(problem.is_here = "$id")' );
while($row = $modx->db->getRow( $result )) {
// presenting data...
}
?><?php
// do we know where we are? yes
$id = $modx->documentIdentifier;
echo $modx->documentIdentifier;
// do it
$result = $modx->db->query( 'SELECT * FROM animals left join species on animals.species = species.species_idx WHERE
// (animals.animal_id = "28")' ); this works when I tell it the id - the same id that $id displays
(animals.animal_id = "$id")' );
// that gives me no result, no error
echo "<table border='1'>";
echo "<tr> <th>id</th> <th>name</th> <th>species</th> <th>bin</th> </tr>";
while($row = $modx->db->getRow( $result )) {
echo "<tr><td>";
echo $row['animal_id'];
echo "</td><td>";
echo $row['aname'];
echo "</td><td>";
echo $row['species'];
echo "<br/>";
echo $row['subspecies'];
echo "</td><td>";
echo $row['bin'];
echo "</td></tr>";
}
echo "</table>";
?>$id = $modx->documentObject['id'];

$id = $modx->documentObject['id'];
Resource id #17
$id = $modx->documentIdentifier; $sql= 'SELECT * FROM animals left join species on animals.species = species.species_idx WHERE animals.animal_id =' . $id;
<?php
$sql= 'SELECT
master_ev.ev_date,
animals.aname,
species.species,
species.subspecies,
events_ref.ev_name,
master_ev.events_idx,
notes.note,
weight.weight,
foodinv.food_type
FROM
master_ev
INNER JOIN animals ON (master_ev.animal_id=animals.animal_id)
INNER JOIN species ON (animals.species=species.species_idx)
INNER JOIN events_ref ON (master_ev.events_idx=events_ref.event_id)
LEFT OUTER JOIN notes ON (master_ev.ev_id=notes.ev_id)
LEFT OUTER JOIN weight ON (master_ev.ev_id=weight.ev_id)
LEFT OUTER JOIN length ON (master_ev.ev_id=length.ev_id)
LEFT OUTER JOIN feedings ON (master_ev.ev_id=feedings.ev_id)
LEFT OUTER JOIN foodinv ON (feedings.perm_id=foodinv.perm_id)
WHERE
(animals.animal_id =' . $id')';
// unexpected T_CONSTANT_ENCAPSED_STRING
$result = $modx->db->query($sql);
echo "<table border='1'>";
echo "<tr> <th>date</th> <th>animal</th> <th>species</th> <th>event</th> </tr>";
while($row = $modx->db->getRow( $result )) {
echo "<tr><td>";
echo $row['ev_date'];
echo "</td><td>";
echo $row['aname'];
echo "</td><td>";
echo $row['species'];
echo "</td><td>";
switch ( $row['events_idx'] ) {
case 8:
echo $row['note'];
break;
case 5:
echo "weight ",$row['weight'],"oz";
break;
case 6:
echo "length ",$row['length'],"in";
break;
case 1:
echo $row['food_type'];
break;
default:
echo $row['ev_name'];
}
echo "</td></tr>";
}
echo "</table>";
?>
