PHP - How To Make Dropdown Links Stay Visible When Active
Hello
I need help with making our dropdown links stay visible when active. Site: London tshirt .com Code: [Select] <dl id="nav"> <dt class="nav"><b>London Tshirts</b></dt> <dd> <ul> <li><a href="/Unisex">Unisex</a></li> <li><a href="/Slimfit">Slimfit</a></li> <li><a href="/Kids">Kids</a></li> </ul> </dd> <dt class="nav"><b>Alternative Tshirts</b></dt> <dd> <ul class="nav"> <li><a href="/England">England</a></li> <li><a href="/Humour">Humour</a></li> <li><a href="/Popular">Popular</a></li> </ul> </dd> <dt class="nav"><b>Magnets</b></dt> <dd> <ul class="nav"> <li><a href="/magnets-ceramic">Ceramic</a></li> <li><a href="/magnets-metal">Metal</a></li> <li><a href="/magents-plastic">Plastic</a></li> </ul> </dd> <dt class="nav"><b>Keyrings</b></dt> <dd> <ul class="nav"> <li class="current"><a href="/keyrings-ceramic">Ceramic</a></li> <li class="current"><a href="/keyrings-metal">Metal</a></li> <li><a href="/keyrings-plastic">Plastic</a></li> </ul> </dd> <dt class="nav"><b>Other gifts</b></dt> <dd> <ul class="nav"> <li><a href="/Hats">Hats</a></li> <li><a href="/Models">Models</a></li> <li><a href="/Bags">Bags</a></li> </ul> </dd> </dl> Thanks P.S. I typed my question, then went to verification, but could not read the letters so requested a new image, this refreshed the page and I lost my message?? Similar TutorialsThis topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=349338.0 I'm showcasing user avatars and nicknames on the page, the mistake I did was I used session variables for that which are being set after login, now obviously those will be deleted as soon as the session is over. So I thought of inserting the values into scalar variables instead of session variables. The problem I'm encountering is, how to make those variables available at the necessary spots on other pages? Let's say I fetch data off the database after login inside login.php and I put the data into scalar variables, what would be common practice to make those scalar variables accessible in index.php? Is this solution a good solution at all to make the avatar and nickname of the user permanent visible? What would be common practice? Hi Everyone, I'm semi-new to php and trying to create a site where I have only one includes file for my navigation (main_nav.inc) and 2-3 includes files (main_template.inc) that act as templates. I then call the the nav and the template in my index.php file. Everything was working fine until I decided I should use php have my links appear active depending on which page the user is on. Everything works totally fine if I insert the code for my nav (including both the html and php) into my main_template.inc file but when I make that code into it's own includes file (main_nav.inc), I get an error. I believe the issue is with using both single and double quotes in my code and wrapping that code in single quotes in my main_nav.inc file. Here is the code from my main_nav.inc file: <?php $main_nav = ' <div id="mainNav"><ul id="mainNav"> <li><a href="index.php" <?php if ($page=='index.php') { ?> class="active" <?php } ?>>Welcome</a></li> <li><a href="healthcare.php" <?php if ($page=='healthcare.php') { ?> class="active" <?php } ?>>Healthcare</a></li> </ul></div> '; // end main_nav ?> I think that since the code is wrapped in single quotes, I can only use double quotes in my code. This is the only difference I can figure out between inserting the code into the template directly (which works perfectly fine) and inserting it as a separate inc file. When I use the main_nav.inc file I get the following error: Parse error: syntax error, unexpected T_STRING in /home/content/k/a/l/kalilaks3/html/includes/main_nav.inc on line 11 I tried changing the quotes around ($page=='index.php') to ($page=="index.php") but that causes the browser to literally read the name of the link a class="active">Welcome I also tried variations of escaping quotes such as ($page==\"index.php\") and even escaping the other quotes and wrapping everything in double quotes as opposed to single quotes. Here is my code for my main_template.inc file <?php $page = basename($_SERVER['SCRIPT_NAME']); $page_title = "Welcome"; include_once ("includes/main_nav.inc"); // sets variable include_once ("home_template.inc"); // sets all variables ?> And here is my index.php file: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta content="healthcare" name="keywords"></meta> <meta content="healthcare" name="description"></meta> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title><?php echo $page_title; ?></title> <link rel = "stylesheet" href = "_css/layout.css"></link> <script type="text/javascript" src="scripts/script.js"></script> </head> <body> <div id = "header"><div id = "globalHeader"> <?php echo $main_nav; ?> </div></div> </body> </html> Any help or suggestions would be greatly appreciated!!! I would love to get this figured out so that I only have to create my navigation once for all my sites! I would like to know how to make my links show that it's active. For example if I click on a link that says overview then that link has to be highlighted. This is the code that I have: Code: [Select] <?php if (isset($this->_params['submenus']) && is_array($this->_params['submenus'])){ foreach ($this->_params['submenus'] as $submenu){ ?> <li class="active"><a href="<?php echo $this->get_uri("/{$submenu['controller']}/{$submenu['action']}") ?>" onclick="javascript:return setSubMenu(<?php echo $submenu['id'] ?>);"><?php echo strtoupper($submenu['name'])?></a></li> <?php } } ?> Unfortunately with this code all the links are selected as active. Hi, Sorry if this is in the wrong place. I really just need a search term to use for what i'm trying to do. I would like my buttons to appear pressed on each page. For example if you are on the home page the home button will appear pressed. If you are on the screenshots page the screenshots button will appear pressed. Pretty much i want my nav bar to display what page is being viewed. I'm using SMF forums and i've created an extension of my forum that i'm using on the root of my site. As far as i can tell i have the correct code added to the forum that should highlight the home button while on the home page. The part i'm missing is the code to add onto the home page. This is the code I have on the button. $buttons = array( 'overview' => array( 'title' => $txt['overview'], 'href' => 'http://www.wararmada.com', 'show' => true, 'sub_buttons' => array( 'alliance' => array( 'title' => $txt['alliance'], 'href' => $scripturl . '?action=overview;area=alliance', 'show' => true, ), This is the code i have in the language file. $txt['overview'] = 'overview'; I'm not sure what this is called. I don't know anything about php but so far i've been able to get by just using google but I don't really know how to search for this. Thanks for all the help! This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=317523.0 Using unordered list, <ul> Reading from XML file, Taking menu name from database, Is there other system to make dropdown navigation menu? Which is the best way to make dropdown navigation menu? I also want to show the sitemap of navigation.How can it be done? I'm trying to make my text and images into clickable links. The images and text are in a database so its getting really tricky for me since I'm new to PHP. I've tried many different ways without success. Here is a snippet of the code I'm working with. As you can see, I'm also working with an image re-sizer. I would really like to make those images and text clickable links(i.e. Title). Any help is appreciated! if ($res) { while ($newArray = mysqli_fetch_array($res, MYSQLI_ASSOC)) { $detail = $newArray['id']; $photo = $newArray['photo']; $id = $newArray['title']; $price = $newArray['price']; list($width) = getimagesize($photo); // set the maximum width of the image here $maxWidth = 100; if ($width > $maxWidth) echo "<p><img alt=\"Image\" width=\"$maxWidth\" src=\"$photo\" />"; echo "Title:".$id." Price:".$price."<br/"; Hello everyone, I have a general question that I really couldn't find a direct answer to on the web anywhere else. My question is this: If I have a page on my site that is strictly php code, such as an include file with database connection code, is that information visible to anyone else out there via the web, or would they actually need to have the php file on their computer and view it in a code editor? I know that if I use a browser to go to my db_connect.inc.php file, it is simply a blank page with no page source. Thanks for any help. I have a form with dropdown list that is populated with values from Sql Server table. Now i would like to use this selected item in SQL query. The results of this query should be shown in label or text field. So when a user selects item from dropdown menu, results from SQL query are shown at the same time. I have two dropdown list at the moment in my form. First one gets all values from a column in table in SQL Server. And the second one should get a value from the same table based on a selection in first dropdown list.
When i load ajax.php i get 2 error mesages: This is my code so far. I have tried to do it with this Ajax script. But i can only get first dropdown to work. The second dropdown(sub_machinery) does not show values, when first dropdown item is selected. The second dropdown should show values from databse table with this query( *$machineryID* is first dropdown selected item): SELECT MachineID FROM T013 WHERE Machinery=".$machineryID. Index.php <!doctype html> <?PHP $server = "server"; $options = array( "UID" => "user", "PWD" => "pass", "Database" => "database"); $conn2 = sqlsrv_connect($server, $options); if ($conn2 === false) die("<pre>".print_r(sqlsrv_errors(), true)); echo " "; ?> <html> <head> <meta charset="utf-8"> <title>Untitled Document</title> </head> <body> <section id="formaT2" class="formaT2 formContent"> <div class="row"> <div class="col-md-2 col-3 row-color remove-mob"></div> <div class="col-md-5 col-9 bg-img" style="padding-left: 0; padding-right: 0;"> <h1>Form</h1> <div class="rest-text"> <div class="contactFrm"> <p class="statusMsg <?php echo !empty($msgClass)?$msgClass:''; ?>"><?php echo $statusMsg; ?></p> <form action="connection.php" method="post"> <div>machinery</div> <select id="machinery"> <option value="0">--Please Select Machinery--</option> <?php // Fetch Department $sql = "SELECT Machinery FROM T013"; $machanery_data = sqlsrv_query($conn2,$sql); while($row = sqlsrv_fetch_array($machanery_data) ){ $id = $row['Id']; $machinery = $row['Machinery']; // Option echo "<option value='".$id."' >".$machinery."</option>"; } ?> </select> <div class="clear"></div> <div>Sub Machinery</div> <select id="sub_machinery"> <option value="0">- Select -</option> </select> <input type="submit" name="submit" id="submit" class="strelka-send" value="Insert"> <div class="clear"> </div> </form> </div> </div> </div> </div> </section> </script> <script type="text/javascript"> $(document).ready(function(){ $("#machinery").change(function(){ var machinery_id = $(this).val(); $.ajax({ url:'ajaxfile.php', type: 'post', data: {machinery:machinery_id}, dataType: 'json', success:function(response){ var len = response.length; $("#sub_machinery").empty(); for( var i = 0; i<len; i++){ var machinery_id = response[i]['machinery_id']; var machinery = response[i]['machinery']; $("#sub_machinery").append("<option value='"+machinery_id+"'>"+machinery+"</option>"); } } }); }); }); </script> </body> </html> Ajaxfile.php <?php $server = "server"; $options = array( "UID" => "user", "PWD" => "pass", "Database" => "database"); $conn2 = sqlsrv_connect($server, $options); if ($conn2 === false) die("<pre>".print_r(sqlsrv_errors(), true)); echo " "; $machineryID = $_POST['machinery']; // department id $sql = "SELECT MachineID FROM T013 WHERE Machinery=".$machineryID; $result = sqlsrv_query($conn2,$sql); $machinery_arr = array(); while( $row = sqlsrv_fetch_array($result) ){ $machinery_id = $row['ID']; $machinery = $row['MachineID']; $machinery_arr[] = array("ID" => $machinery_id, "MachineID" => $machinery); } // encoding array to json format echo json_encode($machinery_arr); ?>Edited May 6, 2019 by davidd Hi all. I've seen on facebook and on some other sites where content refreshes without complete page reloads. for example, right after posting a comment to a database, without any discernible page change, the comment appears somewhere on the page. Is it using php vars and some auto refresh function, (how does it, without reloading appear then?) I know that I am not very clear, but I need to know how to achieve this. If you like to help me, please look at the attachments. They depict the process which I dearly want to know of. Thank you for reading, and thanks in advance for trying to help. Thauwa. Sorry if this is in the incorrect section, but I suspect php activity here. Hi guys, I have some confusion here - I am trying to create a check box where when you tick the box but forget to fill in some other fields - How can you make sure the box stays ticked when we are taken back to the application page? Here is snippets of the code: .. $error = 0; $errormsg = ""; .. if( !isset($_POST['noemail']) && (empty($_POST['email1']) || !check_text($_POST['email1'])) ) { $error = 1; $errormsg .= "Please enter your requested email address 1<br>"; $errornum[3] = 1; } if( !isset($_POST['noemail']) && (empty($_POST['email2']) || !check_text($_POST['email2'])) ) { $error = 1; $errormsg .= "Please enter your requested email address 2<br>"; $errornum[3] = 1; }.. The Form Code: [Select] .. .. <tr> <td><input name="noemail" type="checkbox" value="noemail"> Do not want to get the E-mail address </td> </tr> <tr> <td nowrap>First Choice <input name="email1" type="text" <?php if ($_POST['action'] == "register") { echo 'value="'.$_POST['email1'].'"'; } ?>> </td> </tr> <tr> <td nowrap>Second Choice <input name="email2" type="text" <?php if ($_POST['action'] == "register") { echo 'value="'.$_POST['email2'].'"'; } ?>> </td> </tr> I tired used session e.g: <td><input name="noemail" type="checkbox" value="noemail"<?php echo ($_SESSION["noemail"]=='noemail' ? ' checked="checked"' : '');?>> but it is still did not work - can anyone please assist me what I need to edit or did wrong. Thanks. I don't get why these columns won't stay side by side vertically. I've tried playing around with the css. Please help. <body> <?php include_once "header_template.php"; ?> <div id="site_body" align="center"> <table width="735" border="0" height="1"> <tr> <td> </td> </tr> </table> <table width="749" height="150" border="1" align="center" bordercolor="" class="wrap"> <tr> <td width="240" height="100%" align="left" valign="top"><div id="spry_box" align="center"><?php include_once "spry_Collapsable_panal.php"; ?></div></td> <td width="255" align="center" valign="top"><div id="join_form_box" align="center"><?php include_once "join_form.php"; ?></div></td> <td width="240" align="right" valign="top"><div id="right_AD_box" align="center"><?php include_once "right_AD_template.php"; ?></div></td> </tr> </table> </div> <?php include_once "footer_template.php"; ?> </body> Hi freaks, I'm new to php first of all. I'm dynamically binding a dropdownlist with mysql database . After the user selects an item from it , I want to match that item with another table so as to populate another database. The code I'm using to populate dropdown: Code: [Select] <?php $con = mysql_connect("localhost","root",""); if(!$con) { die ('Can not connect to : '.mysql_error()); } mysql_select_db("ims",$con); $result=mysql_query("select cat_id,cat_name from category"); echo "<select name=cat>"; while($nt=mysql_fetch_array($result)) { echo "<option value=$nt[cat_id]> $nt[cat_name] </option>"; } echo "</select>"; mysql_close($con); ?> Now after the user selects any one of the item , I want to bind another dropdown on the same page using such query like $result=mysql_query("select subcategory.sc_id,subactegory.sc_name from subcategory,category where subcategory.sc_id=$nt[cat_id]"); Please anyone tell me the logic and code to do it. Also tell me do I need an intermediate page to post the 1st dropdown value and then continue with 2nd dropdown. I couldn't figure out the concept anyhow. Help on this will be highly appreiable . (Tell me if I'm not clear with my question) Hi, I've done some serious google'ing... I'm all googled out and it doesn't appear there is a solution to this the way I'm attempting it and it's probably more a case of my early ventures into development that I'm missing something that may or may not be a better and if not more obvious way to do this... Here's the principle, Customer Logs into webpage - greeted by profile page (all cushty so far) - Can choose to move to view 'audio files' which relate to the products they have purchased (this is where it gets silly...) The idea is that both the profile page and the audio page are controlled by a $_SESSION within PHP scripting so the pages are dynamic. I want to include all of the audio files for every product on the 'audio.php' page BUT I only want the ones that they have purchased to be visible... All the setup is fine because the following works fine: Code: [Select] if($info['halftimerock'] == 1) { echo "<p>Half Time Rock</p>";} Which essentially checks the db, finds a 1 in the appropriate product and displays the name of the product in a list, if no products then nothing in the list etc. What I want to do is control the visibility of some <div>'s using the same kind of idea, so: Code: [Select] if($info['halftimerock'] == 1) { CODE TO DISPLAY DIV IN HERE } I have a 'toggleelement' JS function available which works for mouse clicks but obviously php and js don't exactly go well together so that is probably not the way to go, I'm already running a lot of PHP at the top of the page before the HTML to stop session header errors. A couple of web searches have suggested I insert a <script> tag into the echo command but I can't get that to work and I guess it's a really messy way of trying to do things! So here's the question, any ideas about how to toggle <div> visibility within php or is that purely something for js to handle?... Is there a better/cleaner way of doing it all, perhaps redirecting users to different pages based on their entries in the DB (which could all be handled with headers but I'll end up with a million different pages and combinations eventually? I could always create a .htaccess/.htpasswd file system and handle the folders with audio content in manually so that all files are visible but only a valid username and password will be able to access the file but that's going to get annoying for people having to put in user/pass for every file and also for me updating the users for each individual file every time some1 buys something... Any ideas? Anybody done anything similar? Cheers HI there i am having trouble with some code hope someone can help, i have a webpage with in the page has 7 tabs, on the 7th tab is 3 button eavh one does something different, one will restart the server once pressed one turns it on and one off.
soo when i press the button it all works just i need it to be able to stay on that tab and not refresh the page back to the first tab
here is a sample of my code:
<form method="post" action="{$smarty.server.PHP_SELF}?action=productdetails"> <input type="hidden" name="id" value="{$id}" /> <input type="submit" name="turnoff" value="Power Off"> </form> </td> {php} if(isset($_POST['turnoff'])) { $customfield = $this->get_template_vars('customfield'); $RemoteReboot = explode(",", $customfield['value']); $mib = ".1.3.6.1.4.1.13742.4.1.2.2.1.3."; $mib = $mib.$RemoteReboot[1]; $community = "hjkuiouYUI23"; $result = snmpset($RemoteReboot[0], $community, $mib, i, "0"); #echo($result); } {/php} I have the website he http://bossexclusive.com/babyauction/index.php , and http://bossexclusive.com/babyauction/thanks.php . When you press submit on the index.php, it takes you to thanks.php. then, after 5s, it takes you back to index.php. My question is: How could I make it so when I press submit, the box submits the form, but instead of redirecting to thanks.php, it displays the same thank you message on the side, but stays on index.php? If that didn't make sense, let me know. My html and php are below (HTML) Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Baby Auction | Discounted Premium Brand Baby Products</title> <link rel="stylesheet" type="text/css" href="styles.css"/> </head> <body> <div id="main"> <div id="contact"> <h1>Sign up to recieve Auction notifications</h1> <form action="emailer.php" method="post"> <input type="text" name="email" id="email" placeholder="yourname@email.com" /> <input type="image" name="submit" src="images/submit.jpg" width="146px" height="20px" value="Submit"> </form> </div> </div> <div class="copyright"> <?php include 'footer.php'; ?> </div> </body> </html> and emailer.php: Code: [Select] <?php $email = trim(strip_tags($_POST['email'])); $subject = "Contact form submitted!"; $to = 'BlankingOutMyEmail@gmail.com'; $body = <<<HTML $message HTML; $headers = "From: $email\r\n"; $headers .= "Content-type: text/html\r\n"; mail($to, $subject, $body, $headers); header('Location: thanks.php'); ?> Hi, Ok so I have the youtube url input working and it shows the video fine have a look at Code: [Select] http://www.cyberhost.me/test But now what I need is for the script to display the embed code needed for the user. This is the script: Code: [Select] <?php $text = $_POST["text"]; if (!isset($_POST['submit'])) { // if page is not submitted to itself echo the form ?> <html> <head> <title>Youtube code generator</title> </head> <body> <p>Copy and paste this url for example: http://www.youtube.com/watch?v=YdDIsImNfBY&feature</p><br/><br/> <form method="post" action="<?php echo $PHP_SELF;?>"> Youtube URL:<input type="text" size="50" maxlength="50" name="text"><br /> <input type="submit" value="submit" name="submit"> </form> <?php } else { //space anything that would get included in a link, add the space $text = str_ireplace(array("<br />","\n","\r"),array(" <br /> "," \n "," \r "),$text); $text = str_replace(" ", " ", $text); //explode the text by spaces $text_explode = explode(" ",$text); //loop replacing youtube links with embed codes, if not youtube embed return text foreach($text_explode as $words){ if (preg_match('~(?:youtube\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})~i', $words, $match)) { $vidid = $match[1];//the id $link = "http://youtu.be/$vidid";//short link to video //grab the title $visit_url = "http://gdata.youtube.com/feeds/api/videos/".$vidid; $doc = new DOMDocument; @$doc->load($visit_url); $link_title = $doc->getElementsByTagName("title")->item(0)->nodeValue; if($link_title == ""){ $link_title = "Click to watch video."; } //display a link echo "<h3><a href='$link' TARGET='_blank'>$link_title</a></h3>"; //embed the video echo "<div>"; echo "<object style='height: 390px; width: 640px'> <param name='movie' value='http://www.youtube.com/v/$vidid&fs=1'> <param name='allowFullScreen' value='true'> <param name='allowScriptAccess' value='always'> <embed src='http://www.youtube.com/v/$vidid&fs=1' type='application/x-shockwave-flash' allowfullscreen='true' allowScriptAccess='always' width='640' height='390'></object>"; echo "</div><br />"; } else { //keep the original words echo " $words "; } } } ?> The code I need displayed below is Code: [Select] <p> <img height="350" width="425" class="fw_media_youtube fw-parse" alt="YouTube-CODE PLACED HERE" src="http://thumbs.webs.com/Platform/mediaPreview.jsp?type=YouTube&id=CODE PLACED HERE"/></p> Where you see "CODE PLACED HERE" is where i need the video id placed and then for it to be displayed. Any idea how I would do this? Thanks in advance Hello All,
New Year Greetings!!
I have integrated a script for TODO list in my website. Its working fine, but adding New task will be appear only after refreshing the page, whereas delete and save are happening as and when i click on them. I dont know where can i make it right.
Here is my code
Display
<div class="w-box-content todo-list"> <ul class="todoList"> <?php require "todo.class.php"; $query = mysql_query("SELECT * FROM `tz_todo` ORDER BY `position` ASC"); $todos = array(); while($row = mysql_fetch_assoc($query)){ $todos[] = new ToDo($row); } foreach($todos as $item){ echo $item; } ?> </ul> <a id="addButton" class="green-button" href="#">Add a ToDo</a> <div id="dialog-confirm" title="Delete TODO Item?">Are you sure you want to delete this TODO item?</div>I am including <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.0/themes/humanity/jquery-ui.css" type="text/css" media="all" /> <link rel="stylesheet" type="text/css" href="styles.css" /> <script type="text/javascript" src="script.js"></script>and in ajax.php require "connect.php"; require "todo.class.php"; $id = (int)$_GET['id']; try{ switch($_GET['action']) { case 'delete': ToDo::delete($id); break; case 'rearrange': ToDo::rearrange($_GET['positions']); break; case 'edit': ToDo::edit($id,$_GET['text']); break; case 'new': ToDo::createNew($_GET['text']); break; } } catch(Exception $e){ // echo $e->getMessage(); die("0"); } echo "1"; |