PHP - Populate 2nd Select Box With Jquery And Php Output Json?
hi, I was going through this tutorial: http://www.electrictoolbox.com/json-data-jquery-php-mysql/
here is my 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>Untitled Document</title> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script> <script language="javascript" type="text/javascript"> function populateFruitVariety() { $.getJSON('search-by.php', {fruitName:$('#fruitName').val()}, function(data) { var select = $('#fruitVariety'); var options = select.attr('options'); $('option', select).remove(); $.each(data, function(index, array) { options[options.length] = new Option(array['variety']); }); }); } $(document).ready(function() { populateFruitVariety(); $('#fruitName').change(function() { populateFruitVariety(); }); }); </script> </head> <body> <form> Search by: <select name="name" id="fruitName"> <option>Please Select</option> <option id="Town" value="Town">Town</option> <option id="County" value="County">County</option> </select> Variety: <select name="variety" id="fruitVariety"> </select> </form> </body> </html> here is my PHP Code: [Select] $dbhost = "xxx"; $dbname = "xxx"; $dblogin = "xxx"; $dbpass = "xxx"; function dbConnect() { global $dbhost; global $dbname; global $dblogin; global $dbpass; $db = mysql_connect($dbhost, $dblogin, $dbpass) or die("could not connect to database: ".mysql_error()); mysql_select_db($dbname) or die("could not select database"); return $db; } function dbClose($db) { mysql_close($db); } // basis code ^^ $db = dbConnect(); $rows = array(); if(isset($_GET['Town'])) { $query = "SELECT DISTINCT rsCounties FROM pubs"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo json_encode($rows); } } if(isset($_GET['County'])) { $stmt = $pdo->prepare("SELECT rsCounty FROM pubs"); $stmt->execute(array($_GET['rsCounty'])); $rows = $stmt->fetchAll(PDO::FETCH_ASSOC); } echo json_encode($rows); Can someone please help? I have the JQuery working but not the PHP?! here is a link to what I have at the moment: http://www.mypubspace.com/dashnew/index.html thanks Similar TutorialsHi there, Hoping some one can help. I am new to using PDO and i am trying to get data from my db to json I can get the data down to my $result so i know that part is working, my issue is with encoding it to json, if i pull a single record then it works if i pull all records then it doesn't, an i am not sure why $result = $page->read($_GET['pageid']); //check for data if ($result) { //page array $page_arr['pages'] = array(); while ($row =$result->fetch(PDO::FETCH_ASSOC)) { extract($row); $page_item = array( 'id'=> $id, 'title' => $title, 'pageid' => $pageid, 'pagecontent' =>html_entity_decode($pagecontent), 'mdkeywords' => $mdkeywords, 'description' =>$description, 'date_added' =>$date_added, 'hasAudio' => $hasAudio, 'excludeSearch' =>$excludeSearch ); //push to data array_push($page_arr['pages'], $page_item); } //print_r($page_arr['pages']); //If i enable this then i can see all the data //turn to json echo json_encode($page_arr['pages'], JSON_FORCE_OBJECT); //This is where my page is blank. } } else { echo json_encode(array('message'=>'nothing here!.')); }
I am returning the following through JSON: Code: [Select] $this->view->lead_query=$lead_query->fetchALL(); header('OK', true, 200); header('Content-type: application/json'); echo json_encode($this->view->lead_query); I am getting the results in this format: [{"client_name":"Steve Harris","state":"TX"}] Now if the above output was displayed without the square brackets [] I can populate the values in my form correctly. Is there a way i can return the output without the square brackets? Hi, I am working on a project to help me learn more about JSON and JQuery and how they interact. I am able to pull in my JSON data fine and it displays in an HTML table. What isn't working is I want the tables rows to be striped, and normally this works, but I didn't know if it isn't working b/c it is AJAX or if I have something wrong with my JQuery. Also, I was hoping to add a reference to an image path in the JSON file as well, but wasn't sure how that is done or if it could be done at the JSON level.
Here is my code that I am working on:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <title>JSON Presidents</title> <style type="text/css"> body{ font-family:arial, helvetica, sans-serif; text-align:center; width:100%; margin:200px 0 0 0; } #PresidentInfo{ width:75%; margin:0 auto; } table#data{ width:100%; } table#data th{ background:#333; color:#fff; text-align:center; text-shadow:1px 1px 1px rgba(0,0,0,1); padding:5px; } table#data td{ border:1px solid #333; border-collapse:collapse; padding:10px; margin:0 5px 0 5px; text-align:center; } .odd { background: #ccc; } </style> </head> <body> <div id="PresidentInfo"> </div> <script src="http://code.jquery.com/jquery-1.7.1.min.js"></script> <script> (function ($) { $(document).ready (function(){ $("tr:odd").addClass("odd"); }); }); })(jQuery); </script> <script> $.getJSON('data.json', function(data) { var output="<table id='data'><tr><th>First Name:</th><th>Last Name:</th><th>Month of Inauguration:</th><th>Year of Inauguration:</th></tr>"; for (var i in data.Presidents) { output+="<tr><td>" + data.Presidents[i].firstName + "</td><td>" + data.Presidents[i].lastName + "</td><td>" + data.Presidents[i].YearInauguratedPresident.month + "</td><td>" + data.Presidents[i].YearInauguratedPresident.year + "</td></tr>"; } output+="</tr></table>"; document.getElementById("PresidentInfo").innerHTML=output; }); </script> </body> </html> {"Presidents":[ { "firstName":"Barack", "lastName":"Obama", "YearInauguratedPresident": { "month":"January", "day":20, "year":2009 } }, { "firstName":"George W", "lastName":"Bush", "YearInauguratedPresident": { "month":"January", "day":20, "year":2001 } }, { "firstName":"Bill", "lastName":"Clinton", "YearInauguratedPresident": { "month":"January", "day":20, "year":1993 } }, { "firstName":"George", "lastName":"H.W Bush", "YearInauguratedPresident": { "month":"January", "day":20, "year":1989 } } ]} Hi there, i am relatively new to php, mysql, css etc but learning fast. My problem is such; i have a php file which is doing a SELECT mysql_query, WHILE results to strings, then ECHO the resulting rows to produce a list formatted using <table> and finally this <table> is inside a <form> which will POST the changes back to the specific database.tble.row. I wish to have a drop down menu within the <form><table> which will be populated from a separate database.table. I have accomplished the drop down menu outside the <?php ?> tags inside <form><table> which POSTS to a php file but my problem is to add the populating drop down menu inside <?php ?> an already ECHOing resulting rows from the sql query. i.e <?php blurb and stuff ?> <form><table><tr><td> <select name etc> <?php $result = mysql_query("SELECT * FROM tbl WHERE string = tble.rw ORDER BY column"); while($row=mysql_fetch_array($result)){ echo "<OPTION VALUE=".$row['column'].">".$row['column']."</OPTION>"; } ?> </select> WORKS!!!! but placing this inside <?php $x =mysql_query[select] while {strings = conditions; echo ("<form><table><tr><td> insert populated drop menu here </td> etc "); echo"";}?> doesnt work and just leaves the select drop menu blank Hoep you understand my problem. I do not think i can attached the population WHILE loop to a string and just insert the string to the form but maybe i am wrong. thanks in advance and if you go tthis far reading you must be on lots and lots of coffee zark I am having a helluva time trying to populate my state option box with a state array. I have the array set but now how does this get called into the foreach block where the select box is? I can populate it i guess with options manually but I want to get the array to display in the box instead. I tried everything with the minimal experience I have so I need a little help, I got the select box up and displaying where I want it but I cant populate it with an array call. See foreach block near the end of the code: Thanks a bunch! here is my include file code so far: <?php /* Program name: form_test_state.inc * Description: Defines a form that collects a user's * name and mailing address. */ $rows = array( "first_name" => "First Name", "last_name" => "Last Name", "phone" => "Phone Number", "city" => "City", "state" => "State", "address" => "Address", "zip_code" => "ZIP Code", "e_mail" => "E-Mail"); $states_list = array('AL'=>"Alabama",'AK'=>"Alaska",'AZ'=>"Arizona",'AR'=>"Arkansas",'CA'=>"California",'CO'=>"Colorado",'CT'=>"Connecticut",'DE'=>"Delaware",'DC'=>"District Of Columbia",'FL'=>"Florida",'GA'=>"Georgia",'HI'=>"Hawaii",'ID'=>"Idaho",'IL'=>"Illinois", 'IN'=>"Indiana", 'IA'=>"Iowa", 'KS'=>"Kansas",'KY'=>"Kentucky",'LA'=>"Louisiana",'ME'=>"Maine",'MD'=>"Maryland", 'MA'=>"Massachusetts",'MI'=>"Michigan",'MN'=>"Minnesota",'MS'=>"Mississippi",'MO'=>"Missouri",'MT'=>"Montana",'NE'=>"Nebraska",'NV'=>"Nevada",'NH'=>"New Hampshire",'NJ'=>"New Jersey",'NM'=>"New Mexico",'NY'=>"New York",'NC'=>"North Carolina",'ND'=>"North Dakota",'OH'=>"Ohio",'OK'=>"Oklahoma", 'OR'=>"Oregon",'PA'=>"Pennsylvania",'RI'=>"Rhode Island",'SC'=>"South Carolina",'SD'=>"South Dakota",'TN'=>"Tennessee",'TX'=>"Texas",'UT'=>"Utah",'VT'=>"Vermont",'VA'=>"Virginia",'WA'=>"Washington",'WV'=>"West Virginia",'WI'=>"Wisconsin",'WY'=>"Wyoming"); $submit = "Submit mailing information"; ?> <html> <head> <style type='text/css'> <!-- body { background: #42413C; color: #000; font-family: Tahoma, Geneva, sans-serif; font-size: 90%; } form { margin: 1em 2 2 2; padding: 1; width: 1100px; margin-left: 35%; } .field {padding-bottom: 1em; } label { font-weight: bold; float: left; width: 10%; margin-right: 1em; text-align: right; background-color: #9F6; padding-right: 5px; } select {margin-bottom: 1em;} #submit { margin-left: 15%; } h3 { width: 500px; margin-left: 35%; } --> </style> </head> <body> <h3>Please enter your mailing information below:</h3> <?php /* loop that displays the form */ echo "<form action='checkBlankOnly_latest.php' method='post'>"; foreach($rows as $field => $label) if($field == "state") { echo "<label for='$field'>$label</label> <select name='State'> <<<< Insert $states_list array here I am trying to figure out >>>> <option value='state'>Alabama </option> </select> "; } else { echo "<div class='field'><label for='$field'>$label</label> <input id='$field' name='$field' type='text' value='".@$$field."' size='25%' maxlength='65' /></div>\n"; } echo "<div id='submit'> <input type='submit' value='$submit'></div>"; ?> </form> </body> </html> I am using multiple levels of JSON data coming into php from a C# application, as in:
return new RootObject() { ID_Project = 4, Name_Project = "Test", Receiver_ID = 4, Receiver_Name = "ABCDE", UserID = 20, UserRole = new User_Role() { ID_User = 20, Role_User = "level 3", User_Role_Description = "U", UserGroup = new List<user_group>() { new User_Group() { ID_UserGroup = 30, Name_UserGroup = "usergroup8", UserID = 20 }, new User_Group() { ID_UserGroup = 31, Name_UserGroup = "usergroup9", UserID = 21 }, new User_Group() { ID_UserGroup = 32, Name_UserGroup = "usergroup10", UserID = 22 } } } }; i am having troubles accessing the second level: UserRole and 3rd level: User_Group in my php script. im currently trying like this: foreach ($phpArray as $key => $value) { echo "<h2>$key</h2>"; foreach ($value as $k => $v) { echo "$k | $v "; foreach ($v as $key1) { echo "$key1 "; } } } does anyone have an idea? Thanks, Revathy Ok I have a unique issue I have a decent sized database for a fix up and modify project I just landed. My problem is my client has a table with plain html, flash, javascript it in. Which generally speaking isn't to much a problem if I we're going the straight php route to get the data from the database. However I'm not so lucky. These people wish to have the element being built by me to use AJAX to give the site a "2.0" feel, which again to a point fine. So all this said and done, I am going using jQuery as my frame for the javascript. The landing page for the script is PHP it handles any potential user input checks before it works its way into the javascript variables to then use JSON through the javascript to another php file which in turn double checks the inputs just incase someone wants to go in to the source find the way to the file its gathering the data from an all else. Then based on the data forms its output. Which I don't know why Ive wasted my time explaining that, we all know how JSON works in concept at least. My issue with this all is, a single column or 2 but ill stick with just the one for now... with these people having stored plain html, javascript, and object tags for flash in the column without any htmlspecialchars or stripslash's or really any security per say in mind. In other words I can go into any column and just copy and paste the code and have it work in an HTML file as if it were typed out for use in HTML alone. So with that, my JSON requests are failing due to the extra quotes, double quotes, slashes, and all else. What I am trying to figure out is, what is my best method to phrase the output of the DB so its friendly for for the JSON request yet can be repieced back together via javascript/jquery. Any takers on that idea? I have a submit.php file that includes the following jQuery code: <script> [...] request.done(function( json ) { jQuery('input[name=thumbnail-url]').val(json.thumbnail_url); jQuery('input[name=job_title]').val(json.title); jQuery('textarea[name=htmlcode]').val(json.html); [...] </script> I need to remove jQuery('textarea[name=htmlcode]').val(json.html); and pass the "json.html" value into a PHP variable in another php file (functions.php). The code in the functions.php file is already there. The thing i need to do (and i am seriously struggling with it) is placing the value of json.html into a $phpvariable that i can then call from the function.php file. Do you need any more info for this issue? Thanks. 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 Hello all, I have yet again trouble finding a logical solution to my problem. I'm fetching an array which can hold 1 or more values. The problem is, I want these values to ouput in my json_encode function, but this also needs to happen dynamically depending on the amount of values. I can't explain it further, so here's the code so far: Code: (php) [Select] $files = mysql_fetch_array($get_files); $a = count($files); $i = 1; while ($files) { $variablename = 'fileName' . $i; $$variablename = $files['fileName']; $i++; } $output = array( OTHER VALUES , 'fileName1' => $fileName1, 'fileName2' => $fileName2, 'fileName3' => $fileName3, ............); // How do I add the fileNames dynamically depending on how many there are? This got me thinking, I also need to dynamically GET the values with jQuery. How would I do that, when the above eventually works? Thank you. I am currently creating a form and I want to populate a drop down selection menu with data from two fields in a form. For example, I want it to pull the first and last name fields from a database to populate names in a drop down menu in a form. I want the form to submit to the email address of the person selected in the drop down. Is this possible to do? The email is already a field in the record of the person in the database. Can anyone give me some pointers or advice on how I should go about setting up the "Select" box drop down? I am not sure how to code it to do what I am wanting. Any links to relevant help would be appreciated too. Thanks in advance! i have a php script: $sql5 = "select *,count(*) from rc_language_type_assoc_table group by language_type_id"; $result5 = mysql_query($sql5); //not correct $count5 = mysql_num_rows($result5); //not correct $myFile = "/home/rainbowcode/StatsFile.txt"; $fh = fopen($myFile, 'w') or die("can't open file"); fwrite($fh, $sql5."\n"); the above is not what i want, i want the actual result set of the select to print in my StatsFile how can i achieve this please??? hi people can vote 3 times with 3 select menus but i want them not to be able to choose 3x the same select option the options in the select menus come out of the database this is how i let them vote Code: [Select] <?php include("./includes/egl_inc.php"); $secure = new secure(); $secure->secureGlobals(); session_start(); if (isset ($_GET['match'])) { $matchid = (int)$_GET['match']; $_SESSION['matchid'] = $matchid; $matchmaps = mysql_fetch_array(mysql_query("SELECT maps,game FROM ffa_matches WHERE id=$matchid")); $matchmapschecker = $matchmaps[maps]; $matchgamechecker = $matchmaps[game]; $maps=mysql_query("SELECT id,map FROM ffa_maplists where gameid = $matchgamechecker"); while(list($id,$map)=mysql_fetch_row($maps)) { $maplist.="<option value='$id'>$map</option>\n"; } $out[body].="<table width='98%' border='0' cellspacing='0' cellpadding='0' style='border:1px solid black'> <tr style='color:#cccccc; background-color:black;'> <td valign='middle' background='$config[bg2]' align='center' colspan='10'> <br/>Choose Maps<br/> </td> </tr></table><table width='98%' border='0' cellspacing='0' cellpadding='0' style='border:1px solid black'> <tr style='background-color:black;'> <td> <form action='ffainsertmapvote.php' method='post'> <select name='map1'>$maplist</select> <select name='map2'>$maplist</select> <select name='map3'>$maplist</select> <input type='hidden' name='match' value='$matchid' /> <input type='submit' value='Vote' /> </form> </td> </tr></table>"; } include("$config[html]"); ?> do i need jquery to fix this? i dont want the user to be able to go to a next screen without having max 2 the same options selected thanks in advance ! Well I have a script that executes a scan on a system set to run infinitely, and I need it to echo out a message each time it loops through, but I don't want it to echo out the message with the next loop message below it, and the next one below that etc... I've tried using the flush(); function and been messing around with that with no luck. For security reasons I don't want to release any of the processing code, but here is the basic construction of the script: <?PHP ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** $RepeatIt = -1; for($g=1; $g!=$RepeatIt+1; $g++) { ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** $ScanMessage = ":.:.: SCANNING THE HITLIST FOR MOBSTER: ".$MobName." (SCAN #$g) :.:.:"."<br/><br/>"; echo $ScanMessage; ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** } ?> At the moment it's returning: :.:.: SCANNING THE HITLIST FOR MOBSTER: DEUS EX DESTROYER (SCAN #1) :.:.: :.:.: SCANNING THE HITLIST FOR MOBSTER: DEUS EX DESTROYER (SCAN #2) :.:.: :.:.: SCANNING THE HITLIST FOR MOBSTER: DEUS EX DESTROYER (SCAN #3) :.:.: :.:.: SCANNING THE HITLIST FOR MOBSTER: DEUS EX DESTROYER (SCAN #4) :.:.: So what I want it to do is just delete the scanning message and replace it with the next scan message so while running this script you would see just the number increment on the same line. Any suggestions? Thanks. Hello, I am running into a problem. I am trying to convert : Code: [Select] $queryyp = "SELECT YEAR(date) as year, MONTHNAME(date) as month, title FROM post ORDER BY date DESC"; // query to get the rows you want in the order that you want them, with the year and monthname specifically selected as well $resultyp = mysql_query($queryyp); $last_heading = null; // remember the last heading (initialize to null) while($rowyp = mysql_fetch_assoc($resultyp)){ $new_heading = $rowyp['year']; // get the column in the data that represents the heading $new_subheading = $rowyp['month']; // get the column in the data that represents the subheading if($last_heading != $new_heading){ // heading changed or is the first one $last_heading = $new_heading; // remember the new heading $last_subheading = null; // (re)initialize the subheading // start a new section, output the heading here... echo "{$rowyp['year']}<br />"; } // subheading under each heading if($last_subheading != $new_subheading){ // subheading changed or is the first one $last_subheading = $new_subheading; // remember the new subheading // start a new section, output the subheading here... echo " {$rowyp['month']}<br />"; } // output each piece of data under a heading here... echo " {$rowyp['title']}<br />"; } And be able to put it in a javascript tree with very little luck: Code: [Select] <ul id="yeartree" class="tree"> <li>{$rowyp['year']} <ul> <li>{$rowyp['month']} <ul> <li>{$rowyp['title']}</li> </ul> </li> </ul> </li> Yes I know the phpcode in the tree is not correct. That is just an example of what I am attempting to do. I can get the tree to display without the js but I need to add it to js due to the amount of entries and need to beable to collapse it. how do I populate the textbox values in form.html? Thanks in advance for any help you might offer. Code: [Select] //formfill.php <?php $hours="akj"; //split string characters to array $hours_array = str_split($hours); //iterate through the characters in the array foreach($hours_array as $char) { echo($char."<br />"); //somehow populate text boxes in form.html } ?> //form.html <html> <body> <form> <table> <tr> <td><input type="text" name="hour[0]" value="" /></td> <td><input type="text" name="hour[1]" value="" /></td> <td><input type="text" name="hour[2]" value="" /></td> </tr> </table> </form> </body> </html> Hey Guys I have the following table: (login) I need that table to be echoed he But it needs to filter it for the school they are logged in as. Help: When they login they have to select what school they are at so you can use that code. example: PHS = Poole High School Hey Guys, I know it may seem pretty simple, but im having trouble populating a drop down list. Here is my code at the moment, but what it's doing is displaying the names all in one value, where it should be in separate select values. *Note that i have only done it to the first one. See attachment. 'AntonMatt' are next to each other, they should be separate select values. Code: [Select] <? $id = $_GET['id']; $selectplayers="SELECT * FROM players WHERE club='$club' AND team='$team'"; $player=mysql_query($selectplayers); ?> <table class='lineups' width="560" cellpadding="5"> <tr> <td colspan="2">Starting Lineup</td> <td colspan="2">On the Bench</td> </tr> <tr> <td width="119"> </td> <td width="160"> </td> <td width="69"> </td> <td width="160"> </td> </tr> <tr> <td>Prop</td> <td><select name="secondary" style="width: 150px"> <option value='' selected="selected"><? while($rowplayer = mysql_fetch_array($player)) { echo $rowplayer['fname']; } ?></option> </select></td> <td>16.</td> <td><select name="secondary16" style="width: 150px"> <option value='' selected="selected">Secondary Position</option> </select></td> </tr> <tr> <td style="padding-top: 8px;">Hooker</td> <td style="padding-top: 8px;"><select name="secondary2" style="width: 150px"> <option value='' selected="selected">Secondary Position</option> </select></td> <td style="padding-top: 8px;">17.</td> <td style="padding-top: 8px;"><select name="secondary17" style="width: 150px"> <option value='' selected="selected">Secondary Position</option> </select></td> </tr> </table> </div> </div> Hi All,
I have a AmChart file, but unfortunately this data is static. I would like to make this data more dynamic by populating it from a PHP file. Please can someone direct me in doing this?
Here is the AmChart page Code:
<!DOCTYPE html> <html> <head> <title>Climate Survey Results</title> <!-- amCharts javascript sources --> <script type="text/javascript" src="http://cdn.amcharts.com/lib/3/amcharts.js"></script> <script type="text/javascript" src="http://cdn.amcharts.com/lib/3/serial.js"></script> <!-- amCharts javascript code --> <script type="text/javascript"> AmCharts.makeChart("chartdiv", { "type": "serial", "categoryField": "category", "angle": 45, "depth3D": 10, "startDuration": 0.5, "theme": "default", "categoryAxis": { "gridPosition": "start" }, "trendLines": [], "graphs": [ { "fillAlphas": 1, "fillColors": "#008000", "id": "very_satisfied", "lineColor": "#008000", "title": "Very Satisfied", "type": "column", "valueField": "Very Satisfied" }, { "fillAlphas": 1, "fillColors": "#0000FF", "id": "satisfied", "lineColor": "#0000FF", "title": "Satisfied", "type": "column", "valueField": "Satisfied" }, { "fillAlphas": 1, "fillColors": "#FF8000", "fontSize": 0, "id": "dissatisfied", "lineColor": "#FF8000", "title": "Dissatisfied", "type": "column", "valueField": "Dissatisfied" }, { "fillAlphas": 1, "fillColors": "#CC0000", "id": "very_dissatisfied", "lineColor": "#CC0000", "title": "Very Dissatisfied", "type": "column", "valueField": "Very Dissatisfied" } ], "guides": [], "valueAxes": [ { "id": "ValueAxis-1", "stackType": "100%", "title": "Percentage Scored (%)" } ], "allLabels": [], "balloon": {}, "legend": { "textClickEnabled": false, "useGraphSettings": false, "valueAlign": "centre" }, "titles": [ { "size": 20, "text": "Climate Survey Results" } ], "dataProvider": [ { "category": "1", "Very Satisfied": 4.69, "Satisfied": 65.63, "Dissatisfied": 23.43, "Very Dissatisfied": 6.25 }, { "category": "2", "Very Satisfied": 3.13, "Satisfied": 46.88, "Dissatisfied": 34.37, "Very Dissatisfied": 15.62 }, { "category": "3", "Very Satisfied": 1.56, "Satisfied": 56.25, "Dissatisfied": 32.81, "Very Dissatisfied": 9.38 }, { "category": "4", "Very Satisfied": 7.81, "Satisfied": 56.25, "Dissatisfied": 28.13, "Very Dissatisfied": 7.81 }, { "category": "5", "Very Satisfied": 7.81, "Satisfied": 35.94, "Dissatisfied": 43.75, "Very Dissatisfied": 12.5 }, { "category": "6", "Very Satisfied": 26.56, "Satisfied": 57.81, "Dissatisfied": 12.5, "Very Dissatisfied": 3.13 }, { "category": "7", "Very Satisfied": 10.94, "Satisfied": 43.75, "Dissatisfied": 28.13, "Very Dissatisfied": 17.19 }, { "category": "8", "Very Satisfied": 28.13, "Satisfied": 53.13, "Dissatisfied": 14.06, "Very Dissatisfied": 4.69 }, { "category": "9", "Very Satisfied": 26.56, "Satisfied": 64.06, "Dissatisfied": 7.81, "Very Dissatisfied": 1.56 }, { "category": "10", "Very Satisfied": 21.88, "Satisfied": 46.88, "Dissatisfied": 28.13, "Very Dissatisfied": 3.13 }, { "category": "11", "Very Satisfied": 1.56, "Satisfied": 43.75, "Dissatisfied": 45.31, "Very Dissatisfied": 9.38 }, { "category": "12", "Very Satisfied": 1.56, "Satisfied": 39.06, "Dissatisfied": 40.63, "Very Dissatisfied": 18.75 }, { "category": "13", "Very Satisfied": 3.13, "Satisfied": 43.75, "Dissatisfied": 31.25, "Very Dissatisfied": 21.87 }, { "category": "14", "Very Satisfied": 23.44, "Satisfied": 62.5, "Dissatisfied": 12.5, "Very Dissatisfied": 1.56 }, { "category": "15", "Very Satisfied": 9.38, "Satisfied": 53.12, "Dissatisfied": 35.94, "Very Dissatisfied": 1.56 } ] } ); </script> </head> <body> <div id="chartdiv" style="width: 50%; height: 400px; " ></div> </body> </html>My PHP returns the following: Array ( [0] => Array ( [Question] => 1. Overall how satisfied are you with your role / position at Altech Autopage? [Very Satisfied] => 4.6875 [Satisfied] => 65.6250 [Dissatified] => 23.4375 [Very Dissatisfied] => 6.2500 ) [1] => Array ( [Question] => 2. Employees are recognized as individuals. [Very Satisfied] => 3.1250 [Satisfied] => 46.8750 [Dissatified] => 34.3750 [Very Dissatisfied] => 15.6250 ) [2] => Array ( [Question] => 3. Employees are highly motivated to see the company succeed. [Very Satisfied] => 1.5625 [Satisfied] => 56.2500 [Dissatified] => 32.8125 [Very Dissatisfied] => 9.3750 ) [3] => Array ( [Question] => 4. Customer Operations clearly communicates its goals and strategies. [Very Satisfied] => 7.8125 [Satisfied] => 56.2500 [Dissatified] => 28.1250 [Very Dissatisfied] => 7.8125 ) [4] => Array ( [Question] => 5. Customer Operations offers clear opportunities for career advancement. [Very Satisfied] => 7.8125 [Satisfied] => 35.9375 [Dissatified] => 43.7500 [Very Dissatisfied] => 12.5000 ) [5] => Array ( [Question] => 6. My job responsibilities are clear. [Very Satisfied] => 26.5625 [Satisfied] => 57.8125 [Dissatified] => 12.5000 [Very Dissatisfied] => 3.1250 ) [6] => Array ( [Question] => 7. Management is sensitive to employee problems. [Very Satisfied] => 10.9375 [Satisfied] => 43.7500 [Dissatified] => 28.1250 [Very Dissatisfied] => 17.1875 ) [7] => Array ( [Question] => 8. My immediate supervisor provides a positive role model. [Very Satisfied] => 28.1250 [Satisfied] => 53.1250 [Dissatified] => 14.0625 [Very Dissatisfied] => 4.6875 ) [8] => Array ( [Question] => 9. Your own morale. [Very Satisfied] => 26.5625 [Satisfied] => 64.0625 [Dissatified] => 7.8125 [Very Dissatisfied] => 1.5625 ) [9] => Array ( [Question] => 10. The team spirit and level of cooperation among workers. [Very Satisfied] => 21.8750 [Satisfied] => 46.8750 [Dissatified] => 28.1250 [Very Dissatisfied] => 3.1250 ) [10] => Array ( [Question] => 11. The amount of recognition you receive for your work. [Very Satisfied] => 1.5625 [Satisfied] => 43.7500 [Dissatified] => 45.3125 [Very Dissatisfied] => 9.3750 ) [11] => Array ( [Question] => 12. The compensation you receive for your work. [Very Satisfied] => 1.5625 [Satisfied] => 39.0625 [Dissatified] => 40.6250 [Very Dissatisfied] => 18.7500 ) [12] => Array ( [Question] => 13. Your overall level of job security. [Very Satisfied] => 3.1250 [Satisfied] => 43.7500 [Dissatified] => 31.2500 [Very Dissatisfied] => 21.8750 ) [13] => Array ( [Question] => 14. The professionalism of your immediate supervisor. [Very Satisfied] => 23.4375 [Satisfied] => 62.5000 [Dissatified] => 12.5000 [Very Dissatisfied] => 1.5625 ) [14] => Array ( [Question] => 15. Overall, how would you rate Customer Operations as an area to work. [Very Satisfied] => 9.3750 [Satisfied] => 53.1250 [Dissatified] => 35.9375 [Very Dissatisfied] => 1.5625 ) ) Which is the same result as I am currently entering manually. |