$sql = 'SELECT `images` FROM `modx_site_content` WHERE `id` = YOUR_FILTERED_ID';
$c = new xPDOCriteria($modx,$sql); // connect to the MODX DB
$html = '';
if ($c->stmt && $c->stmt->execute())
{
$order_data = $c->stmt->fetch(PDO::FETCH_ASSOC);
$images_string = explode('|', $order_data['images']); // Some string manipulations
foreach($images_string as $image)
{
if(!empty($image))
{
$html .= "<li><img src=$image /></li>";
}
}
return $html;
}Here is my snippet that should be helpful to you. It fetches data from a custom column, but you can edit it to do it from a custom table.
$sql = 'SELECT `images` FROM `modx_site_content` WHERE `id` = YOUR_FILTERED_ID'; $c = new xPDOCriteria($modx,$sql); // connect to the MODX DB $html = ''; if ($c->stmt && $c->stmt->execute()) { $order_data = $c->stmt->fetch(PDO::FETCH_ASSOC); $images_string = explode('|', $order_data['images']); // Some string manipulations foreach($images_string as $image) { if(!empty($image)) { $html .= "<li><img src="$image"></li>"; } } return $html; }
This one fetches URLs separated with a "|" sign and then explodes them. However you can implement any string manipulation that is appropriate.
Please note that you should filter any user input of the query. This one is just an example to point you to the right direction.
$sql = 'SELECT * FROM `organizer_directory` ';
$c = new xPDOCriteria($modx,$sql); // connect to the MODX DB
$rows = array();
if ($c->stmt && $c->stmt->execute())
{
while ($row = $c->stmt->fetch(PDO::FETCH_ASSOC))
{
$rows[] = $row;
}
}
print_r($rows);
The code I gave above was only to illustrate an example of using xPDO
$sql = 'SELECT * FROM `organizer_directory` '; $c = new xPDOCriteria($modx,$sql); // connect to the MODX DB $rows = array(); if ($c->stmt && $c->stmt->execute()) { while ($row = $c->stmt->fetch(PDO::FETCH_ASSOC)) { $rows[] = $row; } } print_r($rows);
This one should help. It will probably spit out some errors since I do not know the internal organization of the DB, but you should be able to easily fix them.
The code I gave above was only to illustrate an example of using xPDO
$sql = 'SELECT * FROM `organizer_directory` '; $c = new xPDOCriteria($modx,$sql); // connect to the MODX DB $rows = array(); if ($c->stmt && $c->stmt->execute()) { while ($row = $c->stmt->fetch(PDO::FETCH_ASSOC)) { $rows[] = $row; } } print_r($rows);
This one should help. It will probably spit out some errors since I do not know the internal organization of the DB, but you should be able to easily fix them.
I think MODX ships with xPDO.
Remember to post the error you get when you are testing a snippet and it doesn't work.
$class = 'className'; // class of your organizer_directory object.
$output = "<br><pre>\n";
$c = $modx->newQuery($class);
/*
$c->limit(5);
$c->where(
array(
'someField' => 'someValue',
'someOtherfield' => 'someOtherValue',
);
$c->sortby('someField', 'ASC/DESC');
*/
/* Get all rows */
$objects = $modx->getCollection($class, $c);
if (empty($objects)) {
$output .= 'Query failed';
}
/* Iterate through rows */
foreach ($objects as $object) {
/* get the fields of the object as an associative array */
$fields = $object->toArray();
$output .= print_r($fields, true);
}
$output .= "\n</pre><br>";
return $output;