You get a bonus - 1 coin for daily activity. Now you have 1 coin

Selecting a Random Record from MySQL with PHP and Smarty

Practice




can you tell me where the error is in the script for cross-linking (cross-references) of news items?


// find out how many news items there are total ::haha.gif::
$q = db_query ('SELECT COUNT(*) FROM '.NEWS_TABLE.';') or die (db_error());
$row_count = db_fetch_row($q);
$query = array();

//max 10, let's build the selection
while (count($query) < 10)
{
$query []= ' (SELECT title, text, date, brief, Pict, enable, meta_title, meta_keywords, meta_desc, hurl, canonical FROM '.
NEWS_TABLE.' LIMIT '.rand( 0,$row_count[0]).', 1) ';
}


$query = implode(' UNION ', $query);

//echo "
---------------".$query ."
";
$q = db_query ($query) or die (db_error());


//read the result
$sinonim_news=array(); $i=0;
while ($res=mysql_fetch_row($q))
{
$sinonim_news[$i] = $res;
$i++;
}
//pass it to the template
$smarty->assign("sinonim_news", $res);




nothing works in the smarty template and nothing gets output !!


{section name=j loop=$sinonim_news}
{$sinonim_news[j][0]}

{/section}

Comments

To leave a comment

If you have any suggestion, idea, thanks or comment, feel free to write. We really value feedback and are glad to hear your opinion.
To reply

Lectures and tutorial on "Databases - MySql (Maria DB)"

Terms: Databases - MySql (Maria DB)