Topic: Abstraction layer messing with loops need some advice.
I recently started using an abstraction layer for my website and I had been using multiple queries as a link to get information together. It worked perfectly using the default MYSQL functions but now since I changed I can't do it any more.
Here is an example of a query and a fetch_array
function query($query){
$this->result = mysql_query($query);
$this->counter++;
return($this->result);
}
function fetch_array(){
$array = mysql_fetch_array($this->result);
return($array);
}
Here is an example of my old way of doing a multiple queries to get information.
$newsget = "SELECT * FROM ".$prefix['newsprefix']." ORDER BY id desc LIMIT $from, ".$vp_options['displaylimit'];
$query = $db->query($newsget) or $vp_e->F_ERROR('SELECT Error', $newsget, __LINE__, __FILE__);
while($r=$db->fetch_assoc($query))
{
$id = $r["id"];
$n_u_id = $r["n_u_id"];
$n_cat_id = $r["n_cat_id"];
$articlename = $r["articlename"];
$message = $r["message"];
$time = $r["time"];
$keywords = $r["keywords"];
$commentsget = "SELECT count(*) as NUM FROM ".$prefix['commentsprefix']." WHERE id='$id'";
$commentnum = $db->query($commentsget) or $vp_e->F_ERROR('SELECT Error', $commentsget, __LINE__, __FILE__);
while($r=$db->fetch_assoc($commentnum))
{
$addcommentlink = "<a href=\"index.php?comments=$id\">".$language['add_comment']."(".$r['NUM'].")</a>";
}
$categoryget = "SELECT * FROM ".$prefix['categoryprefix']." WHERE cat_id='$n_cat_id'";
$resultcatnews = $db->query($categoryget) or $vp_e->F_ERROR('SELECT Error', $categoryget, __LINE__, __FILE__);
while($r=$db->fetch_assoc($resultcatnews))
{
$cat_id=$r["cat_id"];
$cat_name=$r["cat_name"];
$cat_pic=$r["cat_pic"];
}
$cat_name2 = "<a href=\"index.php?newscat=$cat_id\">$cat_name</a>";
$cat_pic2 = "<a href=\"index.php?newscat=$cat_id\"><img border=\"0\" src=\"templates/$templatepath/newsicons/$cat_pic\" /></a>";
$newstitlelink = "<a href=\"index.php?comments=$id\">$articlename</a>";
$authorget = "SELECT * FROM ".$prefix['userprefix']." WHERE id='$n_u_id'";
$resultauthor = $db->query($authorget) or $vp_e->F_ERROR('SELECT Error', $authorget, __LINE__, __FILE__);
while($r=$db->fetch_assoc($resultauthor))
{
$id = $r["id"];
$username = $r["userid"];
$fullname = $r["fullname"];
$avatar = $r["avatar"];
$emailaddress = $r["emailaddress"];
}
Now this way of course not working any more I would like a simple an easy fix for this, but it may not be possible of course.
What do you suggest and how can I solve my problem?
Thanks for any help.