Results 1 to 14 of 14

Thread: Show/Hide links though a custom CMS (using PHP)

  1. #1
    Flak Monkey! Dorza's Avatar
    Join Date
    Jul 2003
    Location
    UK - South Wales
    Posts
    1,762
    Thanks
    34
    Thanked
    17 times in 15 posts
    • Dorza's system
      • Motherboard:
      • Asus P5B Deluxe - WiFi
      • CPU:
      • Q6600 @ 3.06Ghz
      • Memory:
      • 2GB Crucial
      • Storage:
      • 500GB Samsung SpinPoint
      • Graphics card(s):
      • Geforce 9600GT
      • PSU:
      • Cosair HX520W
      • Case:
      • LianLi something something or other
      • Monitor(s):
      • Eizo FlexScan S1910 (1280*1024)
      • Internet:
      • 2mb Virgin (when they want to give me that: else 1mb)

    Show/Hide links though a custom CMS (using PHP)

    I’ve stumbled upon a problem which i just can't get my head around, after searching google and finding nothing that does exactly what i want i thought id asked the cleaver folks at hexus. My problem:

    I have this:

    navbar on each page of my website which can be edited from a custom CMS of mine. The CMS has a section/page called "menu manager" (MM for short). This page handles the editing, adding and deleting of menu items to the navbar. What I'd like to add to this section are links to my navbar items which will show/hide the affected links on the public side of the website ie on the navbar (above). Any one whos used mamboCMS may know what I’m on about. For example in the below picture of my MM page all the "Live" links are displayed on the site but if for example i clicked on "Live" the page would reload, "Live" would change to "hidden" and the affected link would be hidden from the main navbar:

    Menu_Manager - CMS Page



    I just can't get my head around idea of hiding something, which is still visible in the database (All the navbar items including where they link to are held in a database).

    I’ve found some code which does a similar thing to what i want but they all use JavaScript which I don’t want to use. Id much rather use PHP if possible, plus as well the hide/show codes I’ve found don’t work if the client has JS turned off. If any one has any ideas or tutorials they know of I'd appreciate their input and or help.


    EDIT: one more thing now that ive rememberd about it.....When i post a news item the date of posting is in the format yyyy-mm-dd, this date is pulled from a field in the database. How can i change it so that it reads like this: 31-Jul-05. ive tried messing around with various settings but nothing works. Do i need to change some sort of config file within Mysql or PHP?
    Last edited by Dorza; 28-07-2005 at 12:26 AM.

  2. #2
    Large Member
    Join Date
    Apr 2004
    Posts
    3,720
    Thanks
    47
    Thanked
    99 times in 64 posts
    The link could move the stored menu bar data to another table, and move it back when you need it, simple.
    To err is human. To really foul things up ... you need a computer.

  3. #3
    HEXUS.net Webmaster
    Join Date
    Jul 2003
    Location
    UK
    Posts
    3,108
    Thanks
    1
    Thanked
    0 times in 0 posts
    Use the date() function in PHP to convert the date.

    Best bet to hide the menu links is to cheat and apply a style sheet. So add a variable to the page where you want the link to hide e.g. on the page(s) which appear under Home put a variable in called
    Code:
     $currentMenuOption = 'home';
    Then modify the menu code to say
    PHP Code:
    if ($currentMenuOption == $name)
    {
    echo 
    '<div class="hideOption">Home</div>';
    } else {
    echo 
    'Home';

    and have an option in your style sheets of

    Code:
    .hideOption: display: hidden;
    That way the style sheet will hide the menu option. Obviously you need to change $name to match whatever variable the code looks at and you may have to change the <div> to be a <td> or <li> depending on the HTML used to build the menu. They key thing is you won't be doing too much coding and you won't have to modify the database which makes upgrades to your CMS a lot easier

  4. #4
    Flak Monkey! Dorza's Avatar
    Join Date
    Jul 2003
    Location
    UK - South Wales
    Posts
    1,762
    Thanks
    34
    Thanked
    17 times in 15 posts
    • Dorza's system
      • Motherboard:
      • Asus P5B Deluxe - WiFi
      • CPU:
      • Q6600 @ 3.06Ghz
      • Memory:
      • 2GB Crucial
      • Storage:
      • 500GB Samsung SpinPoint
      • Graphics card(s):
      • Geforce 9600GT
      • PSU:
      • Cosair HX520W
      • Case:
      • LianLi something something or other
      • Monitor(s):
      • Eizo FlexScan S1910 (1280*1024)
      • Internet:
      • 2mb Virgin (when they want to give me that: else 1mb)
    Thanks for your help guys. Got the main problem sorted. I took your idea (Iain) a step further by adding a "shown" field to the database table with a type of Enum. I gave it values of 'Y','N' and told the If statement you provided above to look for N. If it finds N in the table then the link wont be displayed. This way i am able to edit the Y or N value with a tick box on the Edit page for each link. Thanks again.

    I still havent sorted the date bit out though, my fault i didnt make things clear before in regards to that.....

    On the table where my posted data is stored theres a field called "Date" with a field type of "Date" the default is set by auto to 0000-00-00. Then on the page i wish to display the date i do the following:

    PHP Code:
    /*PHP START*/

    //All the below is just an except of the fuller code.
    //Ive only included whats relevent to displaying the date 
    //of the posted data

    $datalist = @mysql_query("SELECT date FROM content");
        
    }

    while (
    $data mysql_fetch_array($datalist)) {

      
    $date $data['date'];

      
    //Displays date:

      
    echo "<div class='post'>Posted on: $date by </div>";
    }

    /*PHP CLOSE*/ 
    Im not sure how to do things using date()
    Last edited by Dorza; 28-07-2005 at 10:16 PM.

  5. #5
    HEXUS.net Webmaster
    Join Date
    Jul 2003
    Location
    UK
    Posts
    3,108
    Thanks
    1
    Thanked
    0 times in 0 posts

  6. #6
    Flak Monkey! Dorza's Avatar
    Join Date
    Jul 2003
    Location
    UK - South Wales
    Posts
    1,762
    Thanks
    34
    Thanked
    17 times in 15 posts
    • Dorza's system
      • Motherboard:
      • Asus P5B Deluxe - WiFi
      • CPU:
      • Q6600 @ 3.06Ghz
      • Memory:
      • 2GB Crucial
      • Storage:
      • 500GB Samsung SpinPoint
      • Graphics card(s):
      • Geforce 9600GT
      • PSU:
      • Cosair HX520W
      • Case:
      • LianLi something something or other
      • Monitor(s):
      • Eizo FlexScan S1910 (1280*1024)
      • Internet:
      • 2mb Virgin (when they want to give me that: else 1mb)
    Thanks. That give me new words/ideas to use in google. I eventually found the solution to the date problem Here, should anyone have the same problem i had. Thanks for the help

  7. #7
    HEXUS.net Webmaster
    Join Date
    Jul 2003
    Location
    UK
    Posts
    3,108
    Thanks
    1
    Thanked
    0 times in 0 posts
    if you're doing the conversion in the SQL query I recommend you don't for performance reason. Best to get the raw format from the database and deal with it in PHP, it's more flexible and more performant.

  8. #8
    Flak Monkey! Dorza's Avatar
    Join Date
    Jul 2003
    Location
    UK - South Wales
    Posts
    1,762
    Thanks
    34
    Thanked
    17 times in 15 posts
    • Dorza's system
      • Motherboard:
      • Asus P5B Deluxe - WiFi
      • CPU:
      • Q6600 @ 3.06Ghz
      • Memory:
      • 2GB Crucial
      • Storage:
      • 500GB Samsung SpinPoint
      • Graphics card(s):
      • Geforce 9600GT
      • PSU:
      • Cosair HX520W
      • Case:
      • LianLi something something or other
      • Monitor(s):
      • Eizo FlexScan S1910 (1280*1024)
      • Internet:
      • 2mb Virgin (when they want to give me that: else 1mb)
    I appreciate you pointing out a better solution most would have left it at the original solution so thanks.

    After reading the php.net/date page and many other sites im still not 100% sure about what you mean or how to do it . When you say get the raw format is that what ive done in the code ive posted in my 2nd post? Do i need to use date_format() when im converting the date using PHP? Im still pretty new to PHP/MySql so theres a lot im not sure about.

  9. #9
    HEXUS.net Webmaster
    Join Date
    Jul 2003
    Location
    UK
    Posts
    3,108
    Thanks
    1
    Thanked
    0 times in 0 posts
    get the date straight from the SQL query and then explode it out into its constituent parts, convert it to a timestamp and run the date function e.g.
    PHP Code:
    $query "SELECT date FROM content"// query for date
    $result mysql_query($query);
    // loop through results from query
    while ($row mysql_fetch_array($result))
    {
    // split SQL date into time and date
    $parts explode(' ',$row['date']);
    // split time and date into their constituent parts, namely year, month, day, hour minute, second
    $dateParts explode('-',$parts[0]);
    $timeParts explode(':',$parts[1]);
    // turn these parts into a UNIX timestamp i.e. number of seconds since January 1st 1970
    $timestamp mktime($timeParts[0],$timeParts[1],$timeParts[2],$dayParts[1],$dayParts[0],$dayParts[2]);
    // format the timestamp into a nice textual date
    $niceDate date('l jS F, Y',$timestamp);
    echo 
    $niceDate;

    I've just written this here without testing it so there may be some bugs but give it a go. Your date will need to be in the datetime format in your database which I assume it is. One last thing, I advise you not to call your database fields any name which may represent a function e.g. date. Best to call it content_date or something more unique

  10. #10
    Flak Monkey! Dorza's Avatar
    Join Date
    Jul 2003
    Location
    UK - South Wales
    Posts
    1,762
    Thanks
    34
    Thanked
    17 times in 15 posts
    • Dorza's system
      • Motherboard:
      • Asus P5B Deluxe - WiFi
      • CPU:
      • Q6600 @ 3.06Ghz
      • Memory:
      • 2GB Crucial
      • Storage:
      • 500GB Samsung SpinPoint
      • Graphics card(s):
      • Geforce 9600GT
      • PSU:
      • Cosair HX520W
      • Case:
      • LianLi something something or other
      • Monitor(s):
      • Eizo FlexScan S1910 (1280*1024)
      • Internet:
      • 2mb Virgin (when they want to give me that: else 1mb)
    Thanks for typing that up. I put it into my page, but when i run it i get that error message saying windows cannot handle dates before midnight (00:00:00), January 1, 1970.

    By the way my date field was of type "Date" I have since changed this to "DateTime". As for my field names they all begin with "cont_" followed by date for example. Im using the sitepoin (PHP/Mysql one) book so im following somthing similar to what they done in there.

  11. #11
    HEXUS.net Webmaster
    Join Date
    Jul 2003
    Location
    UK
    Posts
    3,108
    Thanks
    1
    Thanked
    0 times in 0 posts
    What's the value of the date in the database then ?

  12. #12
    Flak Monkey! Dorza's Avatar
    Join Date
    Jul 2003
    Location
    UK - South Wales
    Posts
    1,762
    Thanks
    34
    Thanked
    17 times in 15 posts
    • Dorza's system
      • Motherboard:
      • Asus P5B Deluxe - WiFi
      • CPU:
      • Q6600 @ 3.06Ghz
      • Memory:
      • 2GB Crucial
      • Storage:
      • 500GB Samsung SpinPoint
      • Graphics card(s):
      • Geforce 9600GT
      • PSU:
      • Cosair HX520W
      • Case:
      • LianLi something something or other
      • Monitor(s):
      • Eizo FlexScan S1910 (1280*1024)
      • Internet:
      • 2mb Virgin (when they want to give me that: else 1mb)
    This is what the date field looks like when i go to edit it in phpMyadmin:

    Field - contdate
    Type - DateTime
    Null - Not Null
    Default** - 0000-00-00 00:00:00

    All other attributes are emtpy. Do i need length/value filled in?

  13. #13
    HEXUS.net Webmaster
    Join Date
    Jul 2003
    Location
    UK
    Posts
    3,108
    Thanks
    1
    Thanked
    0 times in 0 posts
    I mean what are the values of the rows in the database, if they are all set to 0000-00-00 00:00:00 then obviously you're not going to get a date as there isn't one so you need to put an if statement in to trap if the date is set to that.

  14. #14
    Flak Monkey! Dorza's Avatar
    Join Date
    Jul 2003
    Location
    UK - South Wales
    Posts
    1,762
    Thanks
    34
    Thanked
    17 times in 15 posts
    • Dorza's system
      • Motherboard:
      • Asus P5B Deluxe - WiFi
      • CPU:
      • Q6600 @ 3.06Ghz
      • Memory:
      • 2GB Crucial
      • Storage:
      • 500GB Samsung SpinPoint
      • Graphics card(s):
      • Geforce 9600GT
      • PSU:
      • Cosair HX520W
      • Case:
      • LianLi something something or other
      • Monitor(s):
      • Eizo FlexScan S1910 (1280*1024)
      • Internet:
      • 2mb Virgin (when they want to give me that: else 1mb)
    Ah right. This is whats entered when a new row is made (the date does change when the day changes): 2005-07-30 00:00:00 . None of the times have an entry for some reason.



    UPDATE: Ive now sorted the problems i had with the date out. Changed the date field to int(10) generated a unix time with time() in the form that enters the data then converted the time to a useful one using
    PHP Code:
    "$contdate = date("jS-M-y" ,$data['contdate']); 
    " in the page i wish to display the date.
    Last edited by Dorza; 05-08-2005 at 09:06 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. PHP Questions and a book recommendation
    By Dorza in forum Software
    Replies: 2
    Last Post: 02-09-2004, 01:26 PM
  2. Usefull Links
    By bloo_fish in forum Software
    Replies: 2
    Last Post: 17-08-2003, 03:39 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •