PHP - Using Php To Set A Current Id For Nav Menu
Hi, I have some code that I think worked at one point, but now it doesn't. I have a side navigation menu which I have set as an include. I want to change CSS styling to a current state to whatever page you are current on. For instance the portfolio link would look like this.
Code: [Select] <li><a id="current" href="../Portfolio/" title="Visit my Portfolio">Portfolio</a></li> Both the page I am trying to set this on and my includes are in separate directories, so I am not sure if that is messing things up, but the id="current is not being set with what I currently have as my code. Here is my current code. <?php $menu = <<< MENU <div id="SideMenu"> <div id="button"> <img src="../images/NavButton.png" width="184" height="32" class="menu_class" /> <ul class="the_menu"> <li><a href="../index.php" title="take me home">Home</a></li> <li><a href="../Portfolio/" title="Visit my Portfolio">Portfolio</a></li> <li><a href="../blog/" title="See what I have to say">Blog</a></li> <li><a href="../Contact/" title="Get in Touch with me">Contact</a></li> </ul> </div><!--end button div--> </div><!--end SideMenu div--> MENU; $lines = split("\n", $menu); foreach ($lines as $line) { $current = false; preg_match('/href="([^"]+)"/', $line, $url); if (substr($_SERVER["REQUEST_URI"], 0, 5) == substr($url[1], 0, 5)) { $line = str_replace('<a h', '<a id="current" h', $line); } echo $line."\n"; } ?> any ideas? Similar TutorialsHello, I got this basic code from a website and it is supposed to highlight the current page on the menu, which it does very well. The problem is that I cannot stylize the font, color or size of the type in the current page menu display. No matter what I do, it always stays as the default font. The other buttons on the menu can be stylized but not the current page. Is there a way to do this? Code: [Select] ## SNIPPET 1 - THE PHP ## // To be saved in the 'includes' directory as "nav_include.php" <?php $menu=file_get_contents("includes/menu.html"); // get the navigation list of pages $base=basename($_SERVER['PHP_SELF']); // get the current page $menu=preg_replace("|<li><a href=\"".$base."\">(.*)</a></li>|U", "<li id=\"current\">$1</li>", $menu); // add an id of 'active' to the link and id of class to the list item for the current page echo $menu; // echo the HTML list with the current page highlighted ?> ## SNIPPET 2 - THE HTML LIST ## To be saved as menu.html <ul id="navlist"> <li><a href="index.php">Home</a></li> <li><a href="products.php">Products</a></li> <li><a href="services.php">Services</a></li> <li><a href="about.php">About Us</a></li> <li><a href="contact.php">Contact Us</a></li> </ul> ## CSS ## for the *.css file #navlist { margin: 0; padding: 30px 0 20px 10px; float: right; width: 60%; } #navlist ul, #navlist li { margin: 0; padding: 0; display: inline; list-style-type: none; } #navlist a:link, #navlist a:visited { float: left; line-height: 14px; font-weight: bold; margin: 0 10px 4px; text-decoration: none; color: #4F4F4F; width: auto; } /* link and visited link styles - the visited state can be styled separately if you wish */ #navlist a:link#current, #navlist a:visited#current, #navlist a:hover { border-bottom: 4px solid #66733f; padding-bottom: 2px; background: transparent; color: #4F4F4F; } /* this line's the style for the current page link */ #navlist a:hover { border-bottom: 4px solid #4F4F4F; color: #4F4F4F; } /* hover state for all the links */ ## TO DISPLAY ON THE PAGE ## <?php include("includes/nav_include.php"); ?> i get this error Warning: current() [function.current]: Passed variable is not an array or object.. for this Code: [Select] $lastblock = current( ${"s".$row} ); print_r($lastblock); when i change to this it works.. Code: [Select] $lastblock = current( $s0 ); print_r($lastblock); The problem is i won't know the $row seeing as it is in a while loop. Solution? Hello - I've come to an issue with something I'm working on and have searched around with no luck. When editing user accounts I want it to not be able to change the e-mail address into existing ones on other rows, but when submitting the form it takes into account that this particular rows email address is the same as the one which was sent via $_POST and throws up the error. The desired behaviour I want is for it to ignore the ID of the row which was posted, but take into account every other row. Here's the code as it stands at the moment: $email = $_POST['email']; $checkemail = mysql_query("SELECT email FROM users WHERE email='$email'"); } if (mysql_num_rows($checkemail) > 0) { return $this->error("The e-mail address you provided is already associated with an account."); } Hi, I'm wanting to find rows whose date is within the next week of the current month of the current year. The format of the date is, for example: 2010-10-28 Any ideas guys? Thanks lots! Hi i have this drop down list current the year is 2010 and downwards but i want to change the list to 2010 upwards u can notice on the 50-- so shows current year minus so current is 2010 to 61 how can i change 2010 to 2030 or sunfin?? echo '<select name="year_of_birth">',"\n"; $year = date("Y"); for ($i = $year;$i > $year-50;$i--) { if($i == $thisYear) { $s = ' selected'; } else { $s=''; } echo '<option value="' ,$i, '"',$s,'>' ,$i, '</option>',"\n"; } echo '</select>',"\n"; HI There, I am using this type of code to self load a submitted form <form name = "testform" method = "post" action = "<?=$_SERVER['PHP_SELF']?>" onsubmit = "return check_data()" > Apart from using $_SERVER['PHP_SELF'] is there another way of determining the current URL within a script ? regards, Steven Matthews Hey all, How can i get the current URL including any $_POST variables which arent visible? Thanks. Hi;
I would like to get the current timestamp but the question is that i want to get the real time which is the machine bios time that can't change by the server administrator and not the server time which can be modified to any value.
Thanks
$_SESSION[$c] is an array in a loop. How do i do an if statement that gets the current array key? Code: [Select] if($_SESSION[$c][]==$_SESSION[$c][1]) { } i tried the above but i get this error "Fatal error: Cannot use [] for reading in..." Hi, I am trying to write an SQL to XML converter, so so far I have all the records inputted into the db tables, and now I want to append a child, but I don't know how to compare current row's field value with the next row below it, specifically I want to check if a current row is parent of the next row. I have already got the XML to SQL function working (some bugs but for the most part it's working) So for eg: <?php $query=mysql_query("SELECT * FROM edge"); while($row=mysql_fetch_assoc($query) ) { if($row['target'] is parent of the next row), then append the next row as child of current row } ?> Table edge is one of the tables that hold target node/source(aka: parent) nodes. Any help much appreciated! Hello! Once again, I find myself in the need of help regarding PHP. What I have is a URL that looks like this: http://domain.com/gallery/?album=3&gallery=65 What I need is to extract the number that comes after "album=". In this case, it would be the number 3. I currently have this: <?php $url=getPageURL(); $var=explode('album=',$url); $var=explode('?',$var[1]); ?> My problem is that it doesn't result in anything. Can anyone lend a hand? :) It would be much appreciated. is this possibe with php? ok guys, i know you guys are awesome and I always get the help and I need some help in figuring the current city and the metropolitan area from an ip address. For example, if I am in Harlem, NY, I need to get the Harlem and New York. I have a code that is partially working but not accurate enough, please guys help, something like groupon will do. Code: [Select] function currentCity () { ( ( (float)phpversion() < 5.3 ) ) ? die ( 'There is something wrong!' ) : ''; $site = file_get_contents( "http://www.google.com/search?q=VBXMCBVFKJSHDKHDKF" ); $getLocationViaGoogle = function ( $html ){ $regex = "#<\w+\s\w+=\"tbos\">([^<]{3,})<\/\w+>#i"; preg_match_all( $regex, $html, $matches ); return $matches[1][0]; }; print $getLocationViaGoogle( $site ); } I am building a site that needs to update member accounts on a weekly basis. At the moment I have a cron job set for 12:01 am on Monday, that resets five database fields for all of my members. The first field is the current week, the second field is the previous week, the third field is from two weeks ago, the fourth field is from three weeks ago, and the fifth field is from four weeks ago. Obviously the cron job resets the first field to 0, and the data from this field is moved to field two (last week), and so on and so forth, and the data from the fifth field is just removed altogether. However, this is really not preferred, because if/when I get 1000+ users, the cron job will take up a crapload of CPU as many mysql queries need to be executed for each account. So, I am trying to implement a script that checks the last login date for a user, and if they have have not logged in since before the latest Monday, the Monday before that, the Monday before that, or the Monday before that, etc. I have never really worked with dates, so I don't even know how to begin. The last user login is stored as a DATA datatype in a mysql database, and is in the following format: YYYY-MM-DD. Thanks in advance! I'm looking to enter the current time and date into a mysql database using php. My current code looks like this: Code: [Select] $now = date("m/d/y",time()); I then insert $now into the table into a datetime column. This all works but the time when read from the column appears as 0000-00-00 00:00:00. Any ideas what I'm doing wrong? Thanks in advance. Hi, This may be something for JavaScript but I would like to know if and how it's possible to show who is currently active/viewing the page. Users are logged into the system with their own account. The purpose of this is for a CRM where more than one person may be editing the same record, so undesired overwrites might occur which is what I'd like to avoid with this "other user editing this record" notification. Why this code dont work :S <?php echo ' <ul> <li'; if ($_SERVER['PHP_SELF'] == "kategorije.php") { echo ' id="current"'; } echo '><a href="kategorije.php"><span>Kategorije</span></a></li> </ul>'; ?> Checking if PHP_SELF is "kategorije.php" do not work, why, and what is solution ? Hi all, I want to get the current page name as displayed in the URL, not neccesarily the name of the PHP script that is running. E.g. I have a PHP file 'home.php' that contains iframes that contain other PHP files such as 'frame1.php'. What I want is a script that can be run from frame1.php but that will return 'home.php' as the current page (as displayed in the URL in the browser). How do I do this? Thanks! Hi guys, I'll try to explain this. I'm doing a quoting system for a building contractor and I have a dynamic purchase order created for every quote that's confirmed and it spits out all the materials they will need for each supplier. The layout of the page is exactly what I need emailed to the supplier so they can ship out the materials listed, it's your basic purchase order. I'm going to put a button on the page that sends the email to the supplier but I need to attach the purchase order displayed on the page. Preferably in PDF but it just needs to be an attached file. I know I can have the user use PRINT.... to save it as PDF and then use Outlook to email it but I'd like to automate it. Thanks. I am trying to create a script that alters the navigation div depending on the page the user is on. How do I get the current page using PHP? |