08-11-2008, 05:53 PM
|
#1 (permalink)
|
|
The Frequenter
Join Date: Dec 2007
Location: In my basement
Posts: 386
Thanks: 47
|
Ugh, Query in a while statement
At first it hurt to put a query in a while statement, then it hurt to rely on my query for organization. Now it hurts because I realized it doesn't work. It works with one category, but when you add a different category it blows up Any category below the first one doesn't get the list items.
I figure it's an error in the HTML, but I still don't like the query in the while statement.
Can I get some help?
PHP Code:
try{ // Get the categories $query = " SELECT DISTINCT `category` FROM `aaron_eglast`.`egle_post` ORDER BY `category` ASC"; $sidePanelCategories = $my->query($query); if (mysql_num_rows($sidePanelCategories) == 0) throw new exception('Sorry, the side panel could not be brought up because it could not be found. (Error Code: 55302)'); // Get SP Pages $query = " SELECT `category`, `slug`, `title`, `order` FROM `aaron_eglast`.`egle_post` ORDER BY `category` ASC, `order` ASC"; $sidePanelPages = $my->query($query); if (mysql_num_rows($sidePanelPages) == 0) throw new exception('Sorry, the side panel could not be brought up because it could not be found. (Error Code: 55303)'); $b = ""; while ($a = mysql_fetch_array($sidePanelCategories)){ $b .= '<li class="topLevel"><h3>'.$a['category'].'</h3><ul>'; while ($c = mysql_fetch_array($sidePanelPages)){ if ($c['category'] == $a['category']){ $b .= '<li>'; if (MOD_REWRITE == true) $b .= '<a href="'. ROOT . '/' . strtolower($c['category']) . '/' . $c['slug'] . '.html' . '">'; else $b .= '<a href="'. ROOT . '/arch/' . strtolower($c['category']) . '/index.php' . '?page=' . $c['slug'] . '">'; $b .= $c['title']; $b .= '</a></li>'; } } $b .='</ul></li>'; } if ($b == false) throw new exception('There was an error generating the index of the local pages. I am sorry, but the pages are unable to be displayed at this moment.'); else $sp = $b; $smarty->assign('sp',$sp); } catch(exception $e){ $smarty->assign('error',$e->getMessage()); }
__________________
Signatures are nothing but incriminating.
Last edited by Aaron : 08-11-2008 at 06:15 PM.
|
|
|