PHP - Best Way Of Organizing Dropdown Menus Please
Hi Everyone,
Someone is asking me a bit of help on a website, I know a bit php and HTML5, I would like to know what would be the best of doing this please:
1)I need to create 2 big buttons, according to the choice of the buttons a different dropbox menu with towns will showup.
2)When the user chooses one of the town, in any drop down, I would like to show a different DIV with content in it.
Here is a practical example:
BUTTON A BUTTON B
if Button A is pressed, show dropdown menu A
if BUTTON B is pressed, show dropdown menu B
If town 1 from dropdown menu A is chosen show DIV 1
If town 2 from dropdown menu A is chosen show DIV 1
If town 3 from dropdown menu A is chosen show DIV 2
If town 4 from dropdown menu A is chosen show DIV 3
If town 5 from dropdown menu A is chosen show DIV 1
If town 1 from dropdown menu B is chosen show DIV 6
If town 2 from dropdown menu B is chosen show DIV 5
If town 3 from dropdown menu B is chosen show DIV 5
If town 4 from dropdown menu B is chosen show DIV 6
If town 5 from dropdown menu B is chosen show DIV 4
How to do this without reloading the page please?
Thank you,
Bambinou
Similar TutorialsI have 3 dropdown menus which have the same name <select name="dropdown">, how to get the value from 3 of them by using php for loop and array? I did try to put array on them before, but seem it can't work. My codes : <?php for ( $counter = 1; $counter <= 3; $counter ++) { if (isset($_POST['submit'])) { //Form has been submitted. $dropvalue = $_POST['dropdown[$counter]']; echo $dropvalue; } } ?> <form action="test8.php" name="frmtest8" method='post'> <select name="dropdown[1]"> <option value="1st">first</option> <option value="2nd">second</option> <option value="3rd">third</option> </select> <select name="dropdown[2]"> <option value="1st">first</option> <option value="2nd">second</option> <option value="3rd">third</option> </select> <select name="dropdown[3]"> <option value="1st">first</option> <option value="2nd">second</option> <option value="3rd">third</option> </select> <input type="submit" name="submit" value="Send" /> </form> It gives error message Parse error: parse error in C:\wamp\www\plekz\test8.php on line 23 I guess the error is because of $_POST['dropdown[$counter]']; I cannot put the two symbols [] inside $_POST[' '] right? How to call the array if cannot put the two symbols? This is actually a page to edit the drama details. Database- 3 tables 1. drama dramaID drama_title 1 friends 2. drama_genre drama_genreID dramaID genreID 1 1 2 2 1 1 3 1 3 3. genre genreID genre 1 comedy 2 romance 3 family 4 suspense 5 war 6 horror <?php $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = ''; $dbname = 'drama'; $link = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname) or trigger_error('Error connecting to mysql'); $id = $_GET['dramaID']; $link2 = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname) or trigger_error('Error connecting to mysql'); $sql2 = "SELECT * from drama , drama_genre , genre WHERE drama.dramaID='".$id."' AND drama_genre.dramaID='".$id."' AND drama.dramaID = drama_genre.dramaID AND drama_genre.genreID = genre.genreID"; $status2 = mysqli_query($link2,$sql2) or die (mysqli_error($link2)); $link3 = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname) or trigger_error('Error connecting to mysql'); $sql3 = "SELECT * from genre "; $status3 = mysqli_query($link3,$sql3) or die (mysqli_error($link3)); <form method='Post' action='doUpdate.php' enctype="multipart/form-data"> <?php while ($row2 = mysqli_fetch_assoc($status2)) { ?> <td height="1"></td> <td><select name="gdrop"> <option value="<?php echo $row2['genreID'];?>"><?php echo $row2['genre'];?></option> <?php while ($row3 = mysqli_fetch_assoc($status3)) { ?> <option value="<?php echo $row3['genreID'];?>"><?php echo $row3['genre'];?></option> <?php } mysqli_close($link3); ?> <input type='hidden' id='drama_genreID' name='drama_genreID' value = "<?php echo $row2['drama_genreID']; ?>"/> </select> <input type="hidden" id="dramaID" name="dramaID" value = "<?php echo $row['dramaID'];?>"/> <input type="submit" Value="Update"/> The result was there were 3 dropdown menus but only the first dropdown menu has all 6 genres from my database and also the genre that belongs to the drama. I'm also wondering how I can bring all the drama_genreIDs to my save(doupdate.php) page and update all 3 of them because it seems like only the last dropdown menu's data is saved. And also how can I display only 6 genres instead of 7 with the genre that belongs to the drama , being set as the default selection. so is it impossible if I have a users folder and a messaging folder located in the same folder. To have a script in the users folder reading from the messaging folder from a script in the messaging folder i thought i could just do this to read the users folder but apparently not Code: [Select] <? require("users/menu.php"); ?> I have two related websites which utilize the same database: Main website for public use. Admin website for administration purposes.Currently, I have both located in /var/www/combined-app which is a single git repository and contains the following: /var/www/combined-app/ public/ public-admin/ src/ main/ admin/ vendor/ composer.json bootstrap.php Alternatively, I could have done the following: /var/www/combined-app/ main/ public/ src/ vendor/ composer.json bootstrap.php admin/ public/ src/ vendor/ composer.json bootstrap.php Or maybe something else all together? Is one approach typically better than the other? If so, please provide reasons why. If my second example, would you recommend separate git repositories for main and admin? Thanks So I'm calling in data from a DB where each record is associated with a (column) 'start_time', 'no_shows', 'cancelled', and 'attended' I want to go through the results of this SELECT and count the number of no shows, cancellations and attended on a WEEKLY basis (based on the start_time). How can I achieve this?
The user will provide a date range and the DB will select the records based on that date range. Now this date range will then have to be split by weeks and then get the count. I'm totally stuck on the counting by weeks part. This is what I have so far: // Multidimensional Array with [boolean][week #] $no_shows_weekly = [ 'no_show' => [], 'week' => [] ]; $cancelled_weekly = [ 'cancelled' => [], 'week' => [] ]; $attended_weekly = [ 'attended' => [], 'week' => [] ]; foreach($result as $r) { $start_time = new DateTime($r['start_time']); if($r['is_no_show'] == 0 && $r['is_cancelled'] == 0) { array_push($attended_weekly['attended'], 1); array_push($attended_weekly['week'], date_format($start_time, "W")); } else { array_push($attended_weekly['attended'], 0); array_push($attended_weekly['week'], date_format($start_time, "W")); } array_push($no_shows_weekly['no_show'], $r['is_no_show']); array_push($no_shows_weekly['week'], date_format($start_time, "W")); array_push($cancelled_weekly['cancelled'], $r['is_cancelled']); array_push($cancelled_weekly['week'], date_format($start_time, "W")); } echo json_encode(array( 'success'=> 1, 'msg'=> array( 'No Shows' => $no_shows_weekly, 'Cancellations' => $cancelled_weekly, 'Attendend' => $attended_weekly ) )); Any suggestions or help is greatly appreciated! I have a test database set up that I am working on. Right now, just some names like so firstName lastName companyName I have used phpmyadmin to insert names in the database. Right now just three names are inserted. One first and last name, one first name and one company name I am getting the results back in an associative array. How can I echo out the information with the break tag, or one field at a time? if I use a break tag, then the loop adds in extra blank lines when it gets to the first name and it's null. Can I test for null values and do it that way? I am a beginner so I have no idea what I am doing. Code: [Select] $result = $mysql->query("select * from names") or die($mysql->error); if($result){ while($row = $result->fetch_assoc()){ $name = $row['firstName']; $lastName = $row['lastName']; $company = $row['companyName']; echo $name . " "; echo $lastName . " "; echo $company . " "; } } hello dear php-experts, well today i have a question regarding the organizing photos in flickr -favs how to do that ? i have 1500 favorites. now i want to organize them into certain " subfolders " or directories question: is this possible? any ideas - i look forward note: i have seen that i am able to download all favs automatically _ great thing but that is another story. I have a file upload script that will eventually process a ton of files. I would like to upload them into sub-directories according to what year, month, and day they are uploaded.
A typical tree should look like this:
attachments/
--/2014
-----/January
--------/01
--------/02
--------/03 , etc.
-----/February
--------/01
--------/04
--------/09
--------/18
--------/20, etc
-----/March, etc
--/2015, etc.
So a file called image.jpg uploaded on 10/31/2014 would have a URL of attachments/2014/October/31/image.jpg. I understand that every time a file is uploaded, the script would have to detect through FTP whether or not folders for the year, month, and day exist, and if they don't create them. My problem is that I have no idea what the logic of this script would be. What order should I do things in? Is there a way to use maybe foreach to detect/create the folders? Any input would be appreciated.
I am refactoring entire collective scattered SQL from my legacy codebase, and into separate classes, and looking for some structure to put it into. Right now I have folders effectively called `DataFromDB` - contains classes that accepts whatever parameters are given, and returns pure data back to the user `DAO` - Data Access Object, which takes that raw data from DB and makes sense out of it and prepares it for consumption by the model/business logic layer objects. That is: - src (folder) |- DAO (folder) | - ProductADAO (classes - take data in, return consumable objects out) | - ProductBDAO | - ... | - ProductZDAO |- DataFromDB (folder) | - ProductAData (classes - contain methods to query pure result sets from DB) | - ProductBData | - ... | - ProductZDataWhenever I need to make a new SQL or refactor an old one I do this: What is this SQL doing? Is it operating on `SomeObjectX`? If yes, find/create class called `ObjectX`, and add a method to it, extracting pure data from DB, put it into `DataFromDB` folder. Write the `DAO` object if needed to transform data into a consumable object. Use the object as is in my code. Does this look like a good strategy? Is there a better one? My problem with this one is that before (now) all the SQL is tightly coupled and is included into the multiple business classes. Using the above strategy will mean I am to be creating many many classes, a lot of classes, most likely one for every few SQL statements. The pros is that it seems like I will achieve a level of code modularity that I wanted. 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 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) I am not a developer but I can modify code to work for me. The following code works on my test machine (Windows 10, IIS, PHP 7.4) but doesn't work on my website (cPanel, Some version of Linux, PHP 7.4). The two dropdowns are for State and City. You are supposed to be able to select the state and then select a city from that state then bring up a report for craft breweries in the city. When selecting State from the first dropdown, the page refreshes, the URL is correct with the reports.php?cat=<STATE> so $cat is being set, but the first dropdown no longer has the state selected and the second dropdown is populated with All cities and not just one ones from the selected state. Any ides why this is working fine on one machine and not the other? Selected code from reports.php
<?php
?>
/////// for second drop down list we will check if State is selected else we will display all the cities/////
echo "<form method=post action='brewerylistbycity.php'>";
}
////////// Starting of second drop downlist /////////
//// End Form /////
Right now I'm feeling like a little baby novice asking a ridiculiously simple question but I just can't find a solution to it! So here it goes.... please don't laugh!!! How do I create a menu which doesn't have to be changed on every existing page whenever I need to add a new page? See... novice stuff and I know it can be done in Dreamweaver. I have Dreamweaver software (old version) but how would I write the code to do so ? Thank you everyone. So I have the following code, which is supposed to get the value selected by the user, then on submitting, will use that value in the URL. Code: [Select] $durations = array("1", "2", "3", "4", "5", "7", "10", "10000000"); echo "Choose Duration: ";?><form method="post" action=""><select name="duration_chosen"> <? foreach($durations as $duration){ ?><option name="duration_len" value="<?php echo $duration;?>"> <? if ($duration == "10000000") { echo "Forever"; } else { echo "$duration day(s)"; } ?></option><? } ?> </select></form><? $hrs = $_GET['duration_len'] * 24; $duration_chosen = $_POST['duration_chosen']; ?> <form method="get" action="index.php"> <input type="hidden" name="duration" value="<? echo $duration_chosen; ?>"> <input type="submit" value="Accept"></form> For some reason, though, it doesn't work. Can anyone help me? Thanks, Mark Hi I was just wondering if someone could send me a good tutorial on pulling several fields from a table and displaying them all in one drop down menu for people to select one of them. I dont know what this is called to I dont know what to research online. I want to create 2 select menus - one static (Menu 1) and the other (Menu 2) populated according to the selection made in Menu 1. Data will will be pulled from a CSV file. Menu 2 will not have any values in it until an option from Menu 1 has been selected. Then, the options available will be limited based on the Item 1 selection. PHP must be used to read the CSV file and to capture the data (using arrays) I met this problem before and my approach then was to call a function using the onChange event for Menu1 ... <script type = "text/javascript">function update_select(obj){ window.location.href="./call_stats_main.php?choice=" + obj.value;} </script> onchange="update_select(this) This would reload the page passing a parameter to the URL (?choice=) I could then use $_GET['choice'] to capture the selected value and dynamically populate Menu 2 according to this value. It is the onchange event that triggers the population of menu 2. I would like to know IF THERE IS A BETTER WAY, other than using ajax ? Steven M I got some help here about 6 months ago with drop down menus & I need a little more. I'm working on a form that has about 20 drop down menus, each populated from a mysql database table with about 50 entries each. I need to keep the selected menu option on the form after the form is submitted but each time the form is submitted the selected menu option reverts back to the first item in the database table. Is there any practical way to fix this problem other than using javascript to finish up? Hi all, I'm new to PHP and just looking for any advice anyone might have on the following problem I'm having. I have created a database and tables for registering and logging in users. Each record has three different User Types (or roles): 1, 2 and 3. Once the session has started, I would like to make certain menu items available to certain User Types. I suppose it is some sort of if...elseif statement such as: <?php if($UserType==1) echo {"<p>Menu1</p>"} elseif($UserType==2) echo {"<p>Menu2</p>"} elseif($UserType==3) echo {"<p>Menu3</p>"}; ?> Would anybody be able to point me in the right direction? I'd really appreciate any help at all. This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=347324.0 |