Jump to content

Jquery Tabs With Php & Mysql


bravo14

Recommended Posts

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


<?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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.