bravo14 Posted October 25, 2012 Share Posted October 25, 2012 I am trying to build some jQuery tabs using PHP & MySQL so it has the following layout <div id="tabs"> <ul> <li><a href="#tabs-1">Tab 1</a></li> <li><a href="#tabs-2">Tab 2</a></li> <li><a href="#tabs-3">Tab 3</a></li> </ul> <div id="tabs-1"> tab 3 content </div> <div id="tabs-2"> tab2 content </div> <div id="tabs-3"> tab3 content </div> </div> I can get the tabs, I just can't figure out the content <?php //get menu options from database $menus_sql=mysql_query("SELECT * FROM `tbl_menus`"); if(mysql_num_rows($menus_sql)>0){ echo('<ul>'); while($menus_row=(mysql_fetch_assoc($menus_sql)){ echo('<li><a href="#tabs-'.$menus_row['id'].'">'.$menus_row['menu_title'].'</a></li>'); } echo('</ul>'); } ?> Any idea how I can create the content The table has the following layout id menu_title menu_content Link to comment https://forums.phpfreaks.com/topic/269883-jquery-tabs-with-php-mysql/ Share on other sites More sharing options...
Jessica Posted October 25, 2012 Share Posted October 25, 2012 Where you previously wrote the word content? You'll put the content in there. Rather than echo'ing in your loop, assign the information to various variables you can echo later. Link to comment https://forums.phpfreaks.com/topic/269883-jquery-tabs-with-php-mysql/#findComment-1387751 Share on other sites More sharing options...
bravo14 Posted October 25, 2012 Author Share Posted October 25, 2012 Don't want to sound stupid, how do you mean? Link to comment https://forums.phpfreaks.com/topic/269883-jquery-tabs-with-php-mysql/#findComment-1387757 Share on other sites More sharing options...
Jessica Posted October 25, 2012 Share Posted October 25, 2012 <?php $menu = '<ul>'; $content = ''; $menus_sql=mysql_query("SELECT * FROM `tbl_menus`"); if(mysql_num_rows($menus_sql)>0){ $menu .= '<ul>'; while($menus_row=(mysql_fetch_assoc($menus_sql)){ $menu .= '<li><a href="#tabs-'.$menus_row['id'].'">'.$menus_row['menu_title'].'</a></li>'; $content .= ' <div id="tabs-'.$menus_row['id'].'">'.$menus_row['menu_content'].'</div>'; } $menu .= '</ul>'; } echo "<div id="tabs">$menu $content</div>"; ?> not tested. Link to comment https://forums.phpfreaks.com/topic/269883-jquery-tabs-with-php-mysql/#findComment-1387758 Share on other sites More sharing options...
bravo14 Posted October 25, 2012 Author Share Posted October 25, 2012 Thanks, took a bit tweaking, but all done Link to comment https://forums.phpfreaks.com/topic/269883-jquery-tabs-with-php-mysql/#findComment-1387768 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.