That’s because the object returned from the query needs to be "unpacked" as it were.
The example given in the php documentation:
$result = mysql_query($query);
...
while ($row = mysql_fetch_assoc($result)) {
echo $row['firstname'];
echo $row['lastname'];
echo $row['address'];
echo $row['age'];
}
From the Wayfinder snippet:
$result = $modx->dbQuery($sql);
...
$numResults = @$modx->recordCount($result);
...
for($i=0;$i<$numResults;$i++) {
$tempDocInfo = $modx->fetchRow($result);
$resultIds[] = $tempDocInfo['id'];
...
-
- 164 Posts
Does this mean that I have to create a folder in the snippets directory and write a complete snippet for what I want to do?
When you get that "Array" business, that means that what you’re getting is an array, and it needs to be looped through. I will temporarily use a print_r block to get the whole array output so I can see what’s going on:
while($row=blah blah) {
echo "<pre>";
print_r($row);
echo "</pre>";
}
-
- 164 Posts
Thanks so much for your help!
Ok, I’m getting three lines now:
Array ( [id] => 90 [pagetitle] => Microsoft enters enterprise search market )
Array ( [id] => 89 [pagetitle] => Local Blackberry users without email )
Array ( [id] => 88 [pagetitle] => 2 million child porn images seized in QLD, nine arrested )
Do I strip the characters I don’t want and format the output?
Thanks again!
Sarah
It seems that this module doesn’t die correctly if you have your site turned off. When I visited my site that was disabled, I got a MySQL error printed to the page that came from this module.
-
- 53 Posts
I just love this. Every time you need something - you find it in the forums ;-)
THX for the snippet.
Anyhow - does someone know another way to display the most viewed documents, say, using ditto?