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

Edited by bravo14
Link to comment
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.

Edited by Jessica
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.