Viewed   86 times

Well, to build my menu my menu I use a db similar structure like this

  2  Services                  0
  3  Photo Gallery             0
  4  Home                      0
  5  Feedback                  0
  6  FAQs                      0
  7  News & Events             0
  8  Testimonials              0
 81  FACN                      0
 83  Organisation Structure   81
 84  Constitution             81
 85  Council                  81
 86  IFAWPCA                  81
 87  Services                 81
 88  Publications             81

To assign another submenu for existing submenu I simply assign its parent's id as its value of parent field. parent 0 means top menu

now there is not problem while creating submenu inside another submenu

now this is way I fetch the submenu for the top menu

<ul class="topmenu">
    <? $list = $obj -> childmenu($parentid); 
        //this list contains the array of submenu under $parendid
        foreach($list as $menu) {
            echo '<li><a href="#">'.$name.'</a></li>';

What I want to do is.

I want to check if a new menu has other child menu

and I want to keep on checking until it searches every child menu that is available

and I want to display its child menu inside its particular list item like this

       <li><a href="#">Home</a>
        <ul class="submenu">
           ........ <!-- Its sub menu -->



You need to use recursive functions for this. Technically, there's a few ways to do it, but recursion is really the best option here.

Here's the basic gist of how it would work:

function drawMenu ($listOfItems) {
    echo "<ul>";
    foreach ($listOfItems as $item) {
        echo "<li>" . $item->name;
        if ($item->hasChildren()) {
            drawMenu($item->getChildren()); // here is the recursion
        echo "</li>";
    echo "</ul>";

The properties and methods of $item are just examples, and I'll leave it up to you to implement these however you need to, but I think it gets the message across.

Monday, December 5, 2022

I would recommend building your own as then you will be able to build it to the way you like it. I would read some tutorials and then design on paper what you want to build and then build it. You will learn more skills this way and build a better application.

The other side of the coin is what nettuts says: Social media website with these 10 code techniques

The great part about the private messaging feature is that it’s already built-in to many CMS scripts. However, many sites don’t even turn on this feature. Take advantage of this (mostly) pre-built functionality and keep your visitors happy and chatting with each other

It depends on your desired outcomes, are you learning code? Building something you want to work but dont want to reuse the skills?

Wednesday, December 21, 2022

If you're going to store the time for when you last visited the site you only need to store one time.

So for your example:

$current_time          = time();
$last_visit_time       = $data->getTime($userId);
$since_last_visit_time = $current_time - $last_visit_time;
$six_hours_in_seconds  = 21600;

if($since_last_visit_time > $six_hours_in_seconds) {
    // not sure of the function call here so using yours
    // store new time as it's been over 6 hours
    $remaining_time = $six_hours_in_seconds;
} else {
    $remaining_time = $six_hours_in_seconds - $since_last_visit_time;

echo "Remaining Seconds: {$remaining_time}<br />";

Part 2 using JavaScript / Ajax you can use this to display the remaning time




var time_in_seconds = 21600; // this would be the $remaining_time PHP variable

setInterval(function() {
}, 1000);

function seconds2time(seconds) {
    var hours   = Math.floor(seconds / 3600);
    var minutes = Math.floor((seconds - (hours * 3600)) / 60);
    var seconds = seconds - (hours * 3600) - (minutes * 60);
    var time = "";

    if (hours != 0) {
      time = hours+":";
    if (minutes != 0 || time !== "") {
      minutes = (minutes < 10 && time !== "") ? "0"+minutes : String(minutes);
      time += minutes+":";
    if (time === "") {
      time = seconds+"s";
    else {
      time += (seconds < 10) ? "0"+seconds : String(seconds);
    return time;


<span id="countdown"></span>?
Sunday, September 4, 2022

This is specifically for two levels deep. Recommended approach should it be more is to use an optimized table structure for traversal, like (pointed out elsewhere) or to pull the data you need and push it into a dictionary (associative array) and query it that way.

    $query = <<<EOT
   as parent_name,
   as child_name,
            items child
        INNER JOIN
            items parent
            child.parent_id =
        ORDER BY

    $result = mysql_query($query) or die('Failure!');

    echo "<ul id="catmenu">";

    $last_parent = '';
    while($row = mysql_fetch_array($result)){
        // If this is a new category, start a new one
        if($last_parent != $row['parent_name']){
            // Unless this is the first item, close the last category
            if($last_parent != ''){
                echo "</ul></li>";
            $last_parent = $row['parent_name'];
            echo "<li class="menulist">{$row['parent_name']}<ul>";
        echo "<li>{$row['child_name']}</li>";

    // If we actually had items, close the "category"
    if($last_parent != ''){
        echo "</ul></li>";

    echo "</ul>";

Wednesday, October 5, 2022

From your question, I understand you're trying to come up with a query to group a number of elements by month and year. The following should do the trick:

    YEAR(dateField) AS YEAR, 
    MONTH(dateField) AS MONTH,
FROM table 

Obviously, "dateField" being the name of your datetime/timestamp column and "table" being the name of your table.

More information on the GROUP BY clause and aggregate functions (such as the COUNT(*) function used above) here.

Thursday, December 22, 2022
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :