One example about what we understand as a Looping is to take some results from a SQL query and print them, in this case the Icy Topic Ratings which are higher than 9 points (four stars and a half).
1. We select all post which are higher or equal to 9 points (all of PHP should be in the PHP file of the Icy Block we want to make)
$sql = "SELECT topic_title,topic_views,topic_rating
FROM `ip_topics`
WHERE `topic_rating` >= 9";
FROM `ip_topics`
WHERE `topic_rating` >= 9";
2. We execute the query:
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, 'Could not obtain information', '', __LINE__, __FILE__, $sql);
}
{
message_die(GENERAL_ERROR, 'Could not obtain information', '', __LINE__, __FILE__, $sql);
}
3. We store every topic in variables in order to use them on the template and we define TEST as the Looping name:
while($row = $db->sql_fetchrow($result))
{
$template->assign_block_vars('test', array(
'TOPIC_TITLE' => $row['topic_title'],
'TOPIC_VIEWS' => $row['topic_views'],
'TOPIC_RATING' => $row['topic_rating']
));
}
{
$template->assign_block_vars('test', array(
'TOPIC_TITLE' => $row['topic_title'],
'TOPIC_VIEWS' => $row['topic_views'],
'TOPIC_RATING' => $row['topic_rating']
));
}
4. With this, we've just got out array full with every topic which got a Rating higher than 9, so now we should to walk around all results in our template in order to print them on the screen, and we guess we should do it by this way:
<!-- BEGIN test -->
{test.TOPIC_TITLE}
{test.TOPIC_VIEWS}
{test.TOPIC_RATING}
<!-- END test -->
{test.TOPIC_TITLE}
{test.TOPIC_VIEWS}
{test.TOPIC_RATING}
<!-- END test -->
This is because we've seen several examples in Icy which they make this way, BUT... ours doesn't work! And we don't know why nor what part is failing. We just want to dominate the Looping in order to customize Icy a lot, adding new features to it, so we'll thank everyone who could help us and throw us a wire. Mighty Gorgon, save us, please!
Thanks for our attention in advance and Till nex time!