SimplePortal

Customization => Blocks and Modifications => Block Requests => Topic started by: MUSTAFAINE on June 03, 2009, 08:39:44 AM

Title: Latest quiz
Post by: MUSTAFAINE on June 03, 2009, 08:39:44 AM
u can see the block in smfmodding (http://www.smfmodding.com/index.php?action=forum) site, can anyone wrote it..
Title: Re: Latest quiz
Post by: ccbtimewiz on June 03, 2009, 01:28:13 PM
Your wish is granted.

Code: [Select]
global $scripturl, $smcFunc, $sourcedir;

// Making this a "smart" block.
if (!file_exists($sourcedir . '/SMFQuizDb.php'))
{
      echo 'Unable to reach the quiz database!';
      return;
}

// Include the SMF2 specific database file
require_once($sourcedir . '/SMFQuizDb.php');

// Make sure they're allowed to view.
isAllowedTo('quiz_view');

// Load the language file
loadLanguage('SMFQuiz');

// Parameters.
// How many quizzes should be shown?
$limit = 10;

// Do you want to only show 'certain' types of quizes? If so, fill out the common title between them. If not, leave this empty.
//$search_material = '';

// Doing the real work.
$result = $smcFunc['db_query']('', '
SELECT Q.id_quiz, Q.title, Q.image
FROM {db_prefix}quiz as Q
        WHERE Q.enabled = 1
LIMIT {int:limit},
array(
//'quiz' => $search_material,
'limit' => $limit,
)
);

$quizzes = array();
while ($quiz = $smcFunc['db_fetch_assoc']($result))
{
$quizzes[] = array(
'title' => $quiz['title'],
'id' => $quiz['id_quiz'],
'image' => $quiz['image'],
'url' => $scripturl . '?action=SMFQuiz;sa=categories;id_quiz=' . $quiz['id_quiz']
);
}
$smcFunc['db_free_result']($result);

// No quizzes found?
if (empty($quizzes))
{
      echo 'There are no quizzes at this time';
      return;
}

// The template work.
echo
'<table border="0" width="100%">';

foreach ($quizzes as $quiz)
echo '
<tr>
<td>', (!empty($quiz['image']) ? $quiz['image'] : ''), '<a href="', $quiz['url'], '">', $quiz['title'], '</td>
</tr>';

// All done.
echo
'</table>';

unset($quizzes);
Title: Re: Latest quiz
Post by: MUSTAFAINE on June 04, 2009, 04:56:52 AM
sorry but it is not working how can it be!!! its look like very logical..
Title: Re: Latest quiz
Post by: ccbtimewiz on June 04, 2009, 11:20:59 AM
What version of SMF are you running? 2.0, right?

Are you putting the code into a custom PHP block?
Title: Re: Latest quiz
Post by: MUSTAFAINE on June 05, 2009, 02:38:23 AM
using smf 2.0 rc 1-1 and ofcourse i put in a php block, but have an empty block
Title: Re: Latest quiz
Post by: MUSTAFAINE on June 08, 2009, 08:46:27 AM
this is an important block for me friends can anyone interest it?

---

now i found something for this block

Code: [Select]
global $smcFunc, $settings, $scripturl;

$result = $smcFunc['db_query']('', '
      SELECT       Q.id_quiz,
               Q.title,
               Q.image,
               Q.updated
      FROM       {db_prefix}quiz Q
      WHERE      Q.enabled = 1
      ORDER BY   Q.updated DESC
      LIMIT      0, 8'
   );
echo '<table border="0">';
while ($row = $smcFunc['db_fetch_assoc']($result)) {
   echo '<tr><td><img width="15" height="15" src="' , !empty($row['image']) ? $settings["default_images_url"] . '/quiz_images/Quizes/' . $row['image'] : $settings["default_images_url"] . '/quiz_images/Quizes/Default-64.png' , '"/></td><td><a href="' , $scripturl , '?action=SMFQuiz;sa=categories;id_quiz=' , $row['id_quiz'] , '">' , $smcFunc['db_unescape_string']($row['title']) , '</a></td></tr>';
}
echo '</table>';
   
$smcFunc['db_free_result']($result);

if you make a new one i want to take it... thanks..
SimplePortal 2.3.8 © 2008-2024, SimplePortal