PHP - Php Set Current Page "active"
I have a menu on my site on each page, I want to put it in it's own menu.php file but i'm not sure how to set the class="active" for whatever page i'm on.
Here is my code:<?php if ($url == $curpage) { $class = "active"; } else { $class = "in-active"; } ?> <ul id="top-navigation"> <li><a href="./" class="<? echo $class ?>">Homepage</a></li> <li><a href="?p=MM" class="<? echo $class ?>">Maintenance Mode</a></li> <li><a href="?p=UCP" class="<? echo $class ?>">User CP</a></li> <li><a href="?p=LYRICS" class="<? echo $class ?>">Lyrics</a></li> <li><a href="?p=SB1" class="<? echo $class ?>">Sidebar 1</a></li> <li><a href="?p=SB2" class="<? echo $class ?>">Sidebar2</a></li> <li><a href="?p=SHP" class="<? echo $class ?>">Site HomePage</a></li> <li><a href="?p=EDTpst" class="<? echo $class ?>">post.php</a></li> <li><a href="?p=EDTUCP" class="<? echo $class ?>">UCP.php</a></li> <li><a href="?p=EDTtimer" class="<? echo $class ?>">timer.php</a></li> </ul> I want $curpage to be the only page I'm on not all of the pages. How would I do this would it be like $url = (isset($_GET['p']) ? $_GET['p'] : 'home'); $s1 = "main" ; $s2 = "MM" ; $s3 = "UCP" ; $s4 = "LYRICS" ; //cont. . . if ($url == $s1) { $class = "active"; } elseif ($url == $s2) { $class = "active"; } elseif ($url == $s3) { $class = "active"; } elseif ($url == $s4){ $class = "active"; } //cont. . . Similar TutorialsCan someone please help me with an array problem i can not figure out. I need the array to be numbered from 1 to how ever many fields that are needed in the form and have a mysql field name and the title of the field also in the array. 1, "mysql_field_name", "Title of form field" 2, "", "" and so on then the form will be shown based on the array. I have the following draft code which I am working with. any suggestions on how i may do this array ? Code: [Select] <?php $options = array( '1'=> array('fieldtext'=>'option1', 'mysqlfield'=>'option1'), '2'=> array('fieldtext'=>'option2', 'mysqlfield'=>'option2'), '3'=> array('fieldtext'=>'option3', 'mysqlfield'=>'option3'), '4'=> array('fieldtext'=>'option4', 'mysqlfield'=>'option4'), ); // $options = array(1 => "option1", "option2", "option3", "option4"); // the line above works but i want to include the name of the mysql field as well. $userid = 1; ?> <div style="align: center; margin: 12px; font-family:Tahoma;"> <br><br><?php if ($_POST['Update'] != "Update") { // check if form submitted yet, if not get data from mysql. $res = db_query("SELECT * FROM `users` WHERE `userid` = '" . $userid . "'"); foreach($options as $key => $value) { $_POST[$key] = mysql_result($res, 0, $value); } $ok_to_update = "no"; } elseif ($_POST['Update'] == "Update") { // check if form submitted yet, if so get POST data. // error checking // foreach($options as $key => $value) { // $_POST[$i] = ""; // } $ok_to_update = "yes"; } if ($_POST['Update'] == "Update" && $ok_to_update == "yes") { // $res = db_query("INSERT INTO `users` () VALUES ()"); // add user details to database. ?><p><br><br><br>Thank you for updating</p><?php } else { ?><form name="form1" method="post" action=""> <?php foreach($options as $key => $value) { ?><p><?php echo($value); ?>: <input type="text" name="<?php echo($key); ?>" value="<?php echo($_POST[$key]);?>"></p> <?php } ?> <input name="Update" type="submit" value="Update"> </form> <?php } ?> </div> I'm a very new PHP user (as in, I just started today) and need to make a set of navigation buttons which will take the user to "next" or "previous" pages. I assume that the $_GET function is involved, but I don't know how to do it. It needs to work like this: If the URL looks like "http://website.com/page1.php" I need the "next" button (a href image) to change it to "/page2.php", and while on page 2, for the "previous" button to take the user to "/page1.php" and so forth. How can I cause the page number to increment or decrease respective to the href image being clicked? Hi, bit stuck on how to find and replace "<" and ">" with "<" and ">". I basically have a database record that outputs to screen and I need the code in the <code> tags to be rendered to the screen. I therefore need it to go through the whole array variable from the db and change the symbols just inside the code tags. Please be aware that the code tags might happen more than once here's an example below Code: [Select] <p>blah blah blah</p> <p>blah blah blah</p> <p>blah blah blah</p> <code> <h1>hello</h1> </code> <p>blah blah blah</p> <p>blah blah blah</p> <p>blah blah blah</p> <code> <h1>hello</h1> </code> the desired output would be: <p>blah blah blah</p> <p>blah blah blah</p> <p>blah blah blah</p> <code> <h1>hello</h1 </code> <p>blah blah blah</p> <p>blah blah blah</p> <p>blah blah blah</p> <code> <h1>hello</h1 </code> help on this would be great Cheers Rob Hi, First of all, this is not a spam. Someone with the username Pikachu2000 removed it thinking it was a spam so now I have to post it again. I really need you help fixing this problem. Anyway, I'm building a site where I used a "php include once" for the navigation menu. I was able to show the active pages when they don't have sub pages but I can't seem to show the active sub pages. I've been trying for days and nothing I try seems to work! I'm sure some people have asked this before but I can't find any forums that describe how to do this with sub navs rather then just the main nav buttons. The coding is below along with a link to one of the sub pages in the site I'm working on. The problem is with the sub pages under "Our Coffee Farm". Thanks for reading my post. Website Link: http://vanessajohodesigns.com/sarpa/the_farm/plantation.php before DOCTYPE: <?php $thisPage="The Plantation"; ?> after body tag: <?php include_once("../includes/nav.php");?> nav.php include once file: <div class="arrowsidemenu"> <div<?php if ($thisPage=="Home") echo " class=\"active\""; ?>> <a href="../index.php">Home</a></span></div> <div class="menuheaders"><a>Our Coffee Farm</a></div> <ul class="menucontents"> <li<?php if ($thisPage=="The Plantation") echo " class=\"active\""; ?>><a href="plantation.php">The Plantation</a></li> <li<?php if ($thisPage=="Blooming & Harvest") echo " class=\"active\""; ?>><a href="bloom_harvest.php">Blooming & Harvest</a></li> <li<?php if ($thisPage=="Coffee Processing") echo " class=\"active\""; ?>><a href="processing.php">Coffee Processing</a></li> </ul> <div<?php if ($thisPage=="About Us") echo " class=\"active\""; ?>> <a href="../about_us.php">About Us</a></div> <div<?php if ($thisPage=="Rainforest Alliance") echo " class=\"active\""; ?>> <a href="../rainforest_alliance.php">Rainforest Alliance</a></div> <div<?php if ($thisPage=="Social Commitment") echo " class=\"active\""; ?>> <a href="../social_commitment.php">Social Commitment</a></div> <div<?php if ($thisPage=="News & Events") echo " class=\"active\""; ?>> <a href="../news_events.php">News & Events</a></div> <div<?php if ($thisPage=="Web Cameras") echo " class=\"active\""; ?>> <a href="../webcams.php">Web Cameras</a></div> <div<?php if ($thisPage=="Photo Gallery") echo " class=\"active\""; ?>> <a href="../gallery.php">Photo Gallery</a></div> <div<?php if ($thisPage=="Contact Us") echo " class=\"active\""; ?>> <a href="../contact_us.php">Contact Us</a></div> <!--end .arrowsidemenu --></div> Hello, I have 2 questions... 1. Do you know of any good and easy php breadcrumb solution? 2. I have recently learned how to use PHP to make a navigation Active based on what page I am on (see below). If I am on the "currentPage" "contact.php" it will show it active... But, what I also want to do is have the main nav active on a sub-nav page. Is it possible to have 2 or more page referenced? Something like ($currentPage == 'contact.php' AND 'contact_form.php') Where both pages would make the link appear active and highlighted. <ul> <li><a href="contact.php" <?php if ($currentPage == 'contact.php') {echo 'id="here"';} ?>>Contact</a></li> <li><a href="about.php" <?php if ($currentPage == 'about.php') {echo 'id="here"';} ?>>About Us</a></li> <li><a href="careers.php" <?php if ($currentPage == 'careers.php') {echo 'id="here"';} ?>>Careers</a></li> <li><a href="services.php" <?php if ($currentPage == 'services.php') {echo 'id="here"';} ?>>Services</a></li> <li><a href="index.php" <?php if ($currentPage == 'index.php') {echo 'id="here"';} ?>>Home</a></li> </ul> Thank you in advance for your help Hi guys I am a newbie with PHP and I have been trying to solve this problem for 3 days.. Ive set up a booking form on my website to be sent directly to my email once the client clicked on the send button.. The problem I am having while checking these pages on wamp is that the booking form is ok but when I click on the send button the following message error appears "Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\wamp\www\fluffy_paws\booking_form2.php on line 27" When I check online I have this message "500 - Internal server error. There is a problem with the resource you are looking for, and it cannot be displayed." Are my codes wrong??? My webhosting is Blacknight.com , Im on Windows Vista, my internet is a dongle with O2 ireland Thanks for your help! Hi guys I'm struggling a bit, I need to replace a word that occurs multiple times in text with an array("up","down","forward","backwards") of words. $find = "left"; $replace = array("up","down","forward","backwards"); $text = "left left left left"; echo str_replace($find,$replace,$text); The Output is: array array array array Did try this with a foreach statement as well, but no luck. Is there a better way of doing this? Thanks Hi all I am new here and looking for some help, I am also not a PHP coder and learning as I go. My problem is this I have a script and have a header.php and global_header.tpl amongst all the other files that come in the script, I have a tabed navigation in global_header.tpl that I want to set to class="active" depending on what page is being viewed. I have spent all last night and all of today going through google and yahoo trying all diferent bits of code but absolutly nothing works. At the moment I have a file I made from some code found on google that I placed in its own .hph file named activetabs.php,I have included this in header.php using Code: [Select] include 'activetabs.php'; In activetabs.php I have Code: [Select] <?php if ($_SERVER["REQUEST_URI"] != '/browse.php') { $tab1 = 'none'; } else { $tab1 = 'active'; } $template->assign_vars(array( 'TAB1' => $tab1, )); ?> testing only but againe it wont work. If I change the above code to Code: [Select] <?php if ($_SERVER["REQUEST_URI"] == '/browse.php') { $tab1 = 'none'; } else { $tab1 = 'active'; } $template->assign_vars(array( 'TAB1' => $tab1, )); ?> the tab becomes active but stays active. Could any of you either show me how to get that code working or kindly provide me some working code. Thanks in advance cant work out this mysql syntax error "operation":"medupdate","medid":"","name":"ibo","medyear":"5","medmonth":"21","medday":"1","recuser":1,"SuccFail":"fail","SuccFailMessage":"error occured You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '''WHERE med_id=' at line 2","ResultData":""} Code: [Select] $sql="update metodology set med_description='".$req['name']."', med_year='".$req['medyear']."', med_month='".$req['medmonth']."', med_day='".$req['medday']."', med_recorddate= now(), med_recorduserid= 1'"; $sql.= " WHERE med_id=".$req['medid']; I am getting the following error when using composer: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? Just started. I am pretty sure composer.json wasn't changed. journalctl doesn't show anything. Maybe Doctrine related, however, nothing seems to help.
Any ideas? [michael@devserver www]$ php -v PHP 7.3.4 (cli) (built: Apr 2 2019 13:48:50) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.3.4, Copyright (c) 1998-2018 Zend Technologies with DBG v9.1.9, (C) 2000,2018, by Dmitri Dmitrienko [michael@devserver www]$ composer -V Composer version 1.4.2 2017-05-17 08:17:52 [michael@devserver www]$ yum info composer Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: mirror.us.oneandone.net * epel: mirror.rnet.missouri.edu * extras: mirror.us.oneandone.net * remi-php73: mirror.bebout.net * remi-safe: mirror.bebout.net * updates: mirror.us.oneandone.net Installed Packages Name : composer Arch : noarch Version : 1.8.4 Release : 1.el7 Size : 1.8 M Repo : installed From repo : epel Summary : Dependency Manager for PHP URL : https://getcomposer.org/ License : MIT Description : Composer helps you declare, manage and install dependencies of PHP projects, : ensuring you have the right stack everywhere. : : Documentation: https://getcomposer.org/doc/ [michael@devserver www]$ composer update Loading composer repositories with package information Updating dependencies (including require-dev) [ErrorException] "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? update [--prefer-source] [--prefer-dist] [--dry-run] [--dev] [--no-dev] [--lock] [--no-custom-installers] [--no-autoloader] [--no-scripts] [--no-progress] [--no-suggest] [--with-dependencies] [-v|vv|vvv|--verbose] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--apcu-autoloader] [--ignore-platform-reqs] [--prefer-stable] [--prefer-lowest] [-i|--interactive] [--root-reqs] [--] [<packages>]... [michael@devserver www]$
This topic has been moved to Linux. http://www.phpfreaks.com/forums/index.php?topic=318175.0 Hi, I currently have an if, elseif, else program that starts off with Code: [Select] if( $v_name == "" || $v_msg == "" ) echo "something" how do I turn this into a switch? but the very next elseif I have Code: [Select] elseif( strcspn( $_REQUEST['msg'], '0123456789' ) == strlen( $_REQUEST['msg'] ) ) echo "something" is it possible to turn this into a switch with 2 different strings like that to evaluate? I have a registration form on my website and after Registration I want the user to activate first his account. I don't have problem on sending this email to the user. What I want to appear is like this.. GoodDay "username", Blah Blah! how can you actually do that? I know that you can do that through session variables but the thing is email's can't accept scripts on sending emails. how can I get the value from a session variable for example and convert it to plain html text so that i can OUTPUT it to the email.. HELP PLEASE! This topic has been moved to PHP Installation & Configuration. http://www.phpfreaks.com/forums/index.php?topic=347922.0 hello, I was wondering what is the point of writing for a dropdown: <?php if ($_POST[inputfieldID] == "value") { echo "selected"; } ?> or for a checkbox/ radio button: <?php if ($_POST['cb/radioID'] == "value") { echo "checked"; } ?> I guess it's for after submit, if there is any error, the values filled will still be echoed in the inputfield, or am i wrong? But then if that is true, i have a php search box where i use AJAX object to to send all the input they filled in after submit. But after pushing submit the inputted values remain. I guess when using AJAX to send the information i don't need <?php if ($_POST[inputfieldID] == "value") { echo "selected"; } ?> in my html forms? Little confused Can maybe somebody bring clearness Hi all, Using a form with check boxes divided into different categories, I collect data selected by the user. I now want to combine each choice in each category with each choice in the other categories and list the combinations to the user. If the user chooses one or more options in each category, it is relatively easy to nest foreach loops, since the number of categories will always be the same. For example, if the form contains three categories of options, the code will be: Code: [Select] foreach ($form['cat_1'] as $k1 => $val1) { foreach ($form['cat_2'] as $k2 => $val2) { foreach ($form['cat_3'] as $k3 => $val3) { echo $val1.' _ '.$val2.' _ '.$val3.'<br/>'; } } } Things get complicated if the user does not select options within a given category. More generally, I want to be able to generate the list regardless of the number of categories in which the user selects options. Thank you in advance for your advice. Hey guys! I have the following doubt: I have a php file that does the following alongside with other code not displayed he $fp = fopen("emails.txt", "w"); It opens a txt file called emails.txt that is in the same folder where the php is saved but how do I tell $fp = fopen("/folderbefore/emails.txt", "w"); ?? In other words, how do I write the path on the script that the emails.txt is located in a previous folder where the php file is located?? Thanks in advance for your help Cheers! This topic has been moved to Application Design. http://www.phpfreaks.com/forums/index.php?topic=317771.0 Hello. I hope one of the PHP/HTML gurus here can help me. I have a web page that has been altered a bit to add some Google Analytics stuff and I've moved it to a 2nd directory. The original one works fine, the 2nd one won't post the form when I click the submit button. 1st URL https://www.theneutralizer.info/neutralizer 2nd URL: https://www.theneutralizer.info/neutralizer2 I have changed the action property to the correct script, and it does exist. But the problem is when clicking the button nothing happens. Anyone have any ideas? I can send the PHP code if needed, but since it's HTML output, it should work the way it is displayed in the browser. David Hello! I am executing an external command from a PHP script, using the exec function. Since this program can take more than 1-2 minutes to run, I thought I should use a "Loading page...please wait". What I need is to be able to get the process id from the external program that is being run and, when this finishes, I'll start outputting the results. Is there a way to do this? |