php - while loop does not increment -
there weird problem while loop not incrementing displaying first category not rest this:
class temp { var $file; function new_list($forum_list) { foreach($forum_list $key => $value) { $this->file = str_replace('{'.$key.'}', $value, $this->file); } return $this->file; } function display() { echo $this->file; } } $temp = new temp(); // mysql query while ($row_cat = mysql_fetch_array($cat)){ $temp->new_list(array( 'cat_title' => $row_cat['title'], 'cat_description' => $row_cat['description'] )); $cid = $row_cat['id']; // mysql query while ($row_forum = mysql_fetch_array($forum)){ $temp->new_list(array( 'forum_title' => $row_forum['title'], 'forum_description' => $row_forum['description'] )); } } $temp->display(); now have made template engine , uses array usual displays category description , subcategory , description once first entry why have made wrong?
edit: have added template engine code catches file , use file_get_contents method , converts keys values , when use without engine works fine engine shows first column.
try simplify find error. dont see problem youve posted suspect theres error in logic of code havent posted. try this:
<-- mysql query --> while ($row_cat = mysql_fetch_array($cat)){ echo $row_cat['title']."<br/>"; $cid = $row_cat['id']; <-- mysql query --> while ($row_forum = mysql_fetch_array($forum)){ "-".$row_forum['title']."<br/>"; } } update:
yup: heres problem: $this->file = ... overwriting $file each iteration. need concat result (add strings . ) this:
$this->file = $this->file . str_replace('{'.$key.'}', $value, $this->file);
Comments
Post a Comment