PHP - Dropdown Concatenation?
I am currently learning Zend/PHP on the fly. I've gone from 0 to 40 in about 2 months, as far as savviness is concerned. I am working on a form that I want to display array information of two things (shortname and fullname) in a drop-down list. I am thinking I need to do some sort of concatenation to achieve this, or would I do an array within an array? The array is defined in a value object and that draws the id, shortname and fullname. Shortname is the defined label in that file. In the form page, i have the LO ['full_name'] => LO ['label']... this inputs the right information into the database, but shows the full name. I want the drop-down to show it as following: Shortname|Fullname. This will be used in a couple of places once I get on the right track on how to accomplish this. I would be accepting of any help, as well as any resourced that could answer my question and help me finish this form.
Cheers, ESK Similar TutorialsHow do I add a space in my concatenation? What I have down below doesn't work. $result[0] .$result[1] I have a table (applicants) which has a number of fields including 5 for potential 'parties' - these are party1, party2, party3, party4 and party5. Any particular applicant will always have two parties but could have any number up to 5. I need to export a pdf (which I can do) but I need it to include data drawn from the applicants table in the format: party1, party2 and party3 OR party1 and party2 etc that is, each party has a comma after it except the last but one, which has no comma but an 'and'. (I hope this is clear enough!) I can't work out how to do this for a varying number of 'parties'. Any suggestions/answers gratefully received. problem is when i select unpaid in drop down box it not show the expected result. I dont know wats wrong here I doubt $reg .=" AND status=0 "; find wats wrong Thanks a lot Code: [Select] <?php include("connection.php"); $reg=""; if(isset($_POST['filter'])) { if($_POST['sel'] == "0") { $reg .=" AND status=0 "; } elseif($_POST['sel'] == "1") { $reg .=" AND status=1 "; } elseif($_POST['sel'] == "3") { $reg .=" AND (status=0 OR status=1) "; // echo "<a href='vudetails.php?regno=".$qry2['reg_no']."'>".$qry2['name']."</a>"; } $filter=mysql_query("SELECT * FROM stu_details WHERE dept LIKE '%".$_POST['dept']."%' OR course LIKE '%".$_POST['cors']."%' OR YEAR LIKE '%".$_POST['year']."%' OR room_no LIKE '%".$_POST['dept']."%' OR reg_no LIKE '%".$_POST['dept']."%' OR doj BETWEEN '".$_POST['dept']."' AND '".$_POST['dept']."'".$reg); while($f2=mysql_fetch_array($filter)) { echo "<a href='vudetails.php?regno=".$f2['reg_no']."' >".$f2['name']."</a> <br />"; } } ?> <html><head><title>Filter</title></head> <script type="text/javascript" src="datetimepicker.js"> </script> <script type="text/javascript"> function validate() { var a=document.forms['form']['dept'].value; if (a==null || a=="") { alert("Please enter a search."); return false; } /*else { return true; }*/ } </script> <form name="form" action="" method="post"> <table border="0"> <tr><td> <select name="sel"> <option value="3">All </option> <option value="0">Unpaid </option> <option value="1">Paid </option> </select> <tr><td> Department: <input type="text" name="dept"> <tr><td> Course: <input type="text" name="cors"> <tr><td> Year: <input type="text" name="year"> <tr><td> Room No: <input type="text" name="roomno"> <tr><td> Register No: <input type="text" name="regno"> <tr><td> Date of Join: <input type="text" name="doj" id="from"> <a href="javascript:NewCal('from','ddmmyyyy')"> <img src="cal.gif" width="16" height="16" border="0" alt="Pick a date"></a> To: <input type="text" name="datto" id="todat"> <!--<tr><td>Date: <input text="text" id="dp" name="dp" size="25">--> <a href="javascript:NewCal('todat','ddmmyyyy')"> <img src="cal.gif" width="16" height="16" border="0" alt="Pick a date"></a> <tr><td> <!--<input type="submit" name="filter" value="Filter" onclick="return validate()">--> <input type="submit" name="filter" value="Filter" onclick="validate()"> </table> </form> </html> I am using the code posted here to do something with a third party software
http://www.interwork...trusted-tickets
however its utterly frutrating that something as simple as
$fullUrl = "http://{$server}/trusted/{$ticket}/{$url}";
returns me the following
moOaH6BAKFMGGszd_IQHTvpAhttp://<server>/trusted/1/views/<dashboard>?format=png
instead of
http://<server>/trusted/moOaH6BAKFMGGszd_IQHTvpA/views/<dashboard>?format=png
completely beats me. Any idea why ? Is it something to do with the variable $ticket which has the value of moOaH6BAKFMGGszd_IQHTvpA in this case ?
Is there a subtle difference between Thank you. I can successfully concatenate strings and vars to assemble a php var using an echo statement like this: Code: [Select] echo "<input type='radio' id='radio_btn_" . $Row['question_number'] . "_0' name='question[question_" . $Row['question_number'] . "]' value='0' checked='checked' />"; However, when attempting to reference the same var in an IF statement, I can't seem to get the syntax right. I know this syntax is wrong, but I list it for reference to describe the issue I am trying to solve. Code: [Select] if ($_POST['radio_btn_' . $Row['question_number'] . '_0'] == '0'){ I also tried curly braces but can't arrive at a solution. Any advise would be appreciated. I am trying to figure out how to have an if statement in the middle of strings I am trying to concatenate. I have a from that has a address1 and address2, where address2 often does not exist. So I want to only add that line if there is actually content. I was trying something like the following, but that is giving me an error. I am pretty new to php, so I can't seem figure it out. Any help would be greatly appreciated. Code: [Select] "<p><strong>Address 1: </strong><br>" . $address1 . "<br>" if ( isset($address2) ) { echo . $address2 . "<br>" } . $city . ", " . $state . " " . $zip . "</p>" i want to do it with cURL-Multi since this is the most pretty way to do it! Well i am not sure bout the string concatenation. How to do it - Note i want to fetch several hundred pages: see the some details for this target-server sites - /(i have to create a loop over several hundred sites) siteone_dot_com?show_subsite=9009 siteone_dot_com?show_subsite=9742 siteone_dot_com?show_subsite=9871 and so on and so fort how to appy this loop into the array of the curl-multi <?php /************************************\ * Multi interface in PHP with curl * * Requires PHP 5.0, Apache 2.0 and * * Curl * ************************************* * Writen By Cyborg 19671897 * * Bugfixed by Jeremy Ellman * \***********************************/ $urls = array( "siteone", "sitetwo ", "sitethree" ); $mh = curl_multi_init(); foreach ($urls as $i => $url) { $conn[$i]=curl_init($url); curl_setopt($conn[$i],CURLOPT_RETURNTRANSFER,1);//return data as string curl_setopt($conn[$i],CURLOPT_FOLLOWLOCATION,1);//follow redirects curl_setopt($conn[$i],CURLOPT_MAXREDIRS,2);//maximum redirects curl_setopt($conn[$i],CURLOPT_CONNECTTIMEOUT,10);//timeout curl_multi_add_handle ($mh,$conn[$i]); } do { $n=curl_multi_exec($mh,$active); } while ($active); foreach ($urls as $i => $url) { $res[$i]=curl_multi_getcontent($conn[$i]); curl_multi_remove_handle($mh,$conn[$i]); curl_close($conn[$i]); } curl_multi_close($mh); print_r($res); ?> I'm wondering if this is at all possible:- Code: [Select] $i = 7; $row_item['comment$i_name'] = "john"; with the $i in $row_item['item$i_id'] being replaced with whatever $i is set as sort of like this:- $row_item['comment.'$i'._name'] Is this sort of concatenation possible inside array element names as I can't seem to get it to work? Hi - good evening! thanks for the answer and all the help so far Oncemore the "Fetching-part" for a little parser-script: Here we go - new target urls: see the overview: http://dms-schule.bildung.hessen.de/index.html http://dms-schule.bildung.hessen.de/suchen/suche_schul_db.html Search by pressing the button "type" and then choose all schools with the mouse! Results 2400 schools: Here i can provide some "more help for getting the target!" - btw: see some details for this target-server: http://dms-schule.bildung.hessen.de/suchen/suche_schul_db.html?show_school=9009 http://dms-schule.bildung.hessen.de/suchen/suche_schul_db.html?show_school=9742 http://dms-schule.bildung.hessen.de/suchen/suche_schul_db.html?show_school=9871 well - you see i have to iterate over the sites - with a function /(a loop) http://dms-schule.bildung.hessen.de/suchen/suche_schul_db.html?show_school=1000 to 10000 BTW - after fetching the page i have to see which one are empty - those ones do not need to be parsed! Well - i want to do this with curl-multi since this is the most advanced way to do this: I see i have an array that can be filled I have to try it out...!! Well, I'm not pretty sure - but judging by the low level of PHP i have: I think that i may need a double array to define the URLs like: Can i do like so?: $urls = array( "siteone" => "suche_schul_db.html?show_school=%i", "sitetwo" => "suche_schul_db.html?show_school=%i", "sitethree" =>"suche_schul_db.html?show_school=%i" ); $params = array ( for ($i = 1; $i <= 10000; $i++) { // body of loop } // well i have to define the variables in a open form like abvove nand not below: // better than doing it like so: "siteone" => array(9009, 9742, 9871), ); then pass them to curl-multi as: foreach ($urls as $id => $url) { foreach ($params[$id] as => $param) { $i = $id . $param; $finalurl = sprintf($url, $param); $conn[$i] = curl_init($finalurl); I don't know if that's fits the needs tip that i am looking for but I hope so ;-) Can i do like so [see above]? What do yu think. i send you many greetings martin Hello dear folks i am currently workin on a little parser with cURL - and i have some questions he How to do the String concatenation with PHP ; note i wanna do it with curl! the target URL: http://www.schulministerium.nrw.de/BP/SchuleSuchen?action=572.8745475728288 click all checkbuttons Results: approx 6400 results Here i can provide some "more help for getting the target!" - btw see three detail page: http://www.schulministerium.nrw.de/BP/SchuleSuchen?action=261.2855969084779&SchulAdresseMapDO=116191 http://www.schulministerium.nrw.de/BP/SchuleSuchen?action=261.2855969084779&SchulAdresseMapDO=116270 http://www.schulministerium.nrw.de/BP/SchuleSuchen?action=261.2855969084779&SchulAdresseMapDO=188268 btw: we can loop over the results - with a iteration - especially i wanna know: how to do the String concatenation with PHP ; note i wanna do it with curl! function get_page_data($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $output = curl_exec($ch); if($output!=false && $_POST['dt']=='No') return $output; curl_close($ch); } for($i=1;$i<=$match[1];$i++) { $url = "http://www.example.com/page?page={$i}"; $data = get_page_data($url); if($data) { $cleaned = string_between('onload="check();">', '</body>', $data); return = stip_tags($cleaned, '<table><tr><td><div>'); } } any and all help will be greatly appreciated love to hear from you best regards 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) Hi guys; I've managed to find my way into something of a maze. <td> <a href="'Details/21/index.php'"?id= . $id .'>" . $row['id'] . "</a> </td> I'm looking at this line in the code. I realise it's currently in the wrong syntax but I'm just trying multiple different variations. At the moment I'm actually just trying to make it go to a static link but my real goal is to - get it to pick up the id number, of the id row I click, and concatenate that with the rest of my address string. Then use that as the href. Something like this: - "'Details/' + $id + '/index.php'" It's really confusing me though inside this loop and for some reason the id number is being picked up as an int, by the looks of things. It's getting above my level of understanding. Any chance one of you masters would through a n00b a lifeline?
This is my code below
<!DOCTYPE html> <html> <head> <title>LifeSaver DB</title> <h1> LifeSaver Database </h1> </head> <body> <table> <tr> <th>Id</th> <th>Location</th> <th>Initials</th> <th>TimeStamp</th> <th>Notes</th> </tr> <?php $conn = mysqli_connect("localhost", "meh", "pas", "DB"); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $sql = "SELECT * FROM LifeSaver1 ORDER BY id DESC"; $result = $conn->query($sql); if ($result->num_rows > 0) { // output data of each row while($row = $result->fetch_assoc()) { //for href row $id = $row['id']; $Footage = ['Footage']; echo "<tr> <td> <a href="'Details/21/index.php'"?id= . $id .'>" . $row['id'] . "</a> </td> <td>" . $row["Location"] . "</td> <td>" . $row["Initials"]. "</td> <td>" . $row["TimeStamp"]. "</td> <td>" . $row["Notes"] . "</td> </tr>";} //show table echo "</table>"; } else { echo "0 results"; } $conn->close(); ?> </table> </body> <style> table, td, th { border: 1px solid black; margin: auto; } table { border-collapse: collapse; color: #000; <!--font colour --> font-family: monospace; font-size: 18px; text-align: center;} th { background-color: #337AFF; color: white; font-weight: bold; } tr:nth-child(odd) {background-color: #add8e6} </style> </html> Edited February 8, 2020 by JonnyDriller 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 /////
Hi all. I kinda need some from a more advanced PHP expert. I have a table that displays time slots that are available to be booked. As you can see I have a table with two columns, The 1st column displays the times and the 2nd column has a link that says 'Available'. I want to be able to put all this in a select dropdown box to save space, but how can I do this?
<?php $doc = JFactory::getDocument(); $doc->addStyleSheet(JURI::root(false)."components/com_pbbooking/user_view.css"); ?> <style> table#pbbooking td, table#pbbooking th {padding: 0em;} </style> <h1><?php echo JText::_('COM_PBBOOKING_DAY_VIEW_HEADING').' '.Jhtml::_('date',$this->dateparam->format(DATE_ATOM),JText::_('COM_PBBOOKING_DAY_VIEW_DATE_FORMAT'));?></h1> <table id="pbbooking"> <!-- Draw header row showing calendars across the top....--> <tr> <th></th> <!-- first column left blank to display time slots --> <?php foreach ($this->cals as $cal) :?> <th><?php echo $cal->name;?></th> <?php endforeach;?> </tr> <!-- draw table data rows --> <?php while ($this->day_dt_start <= $this->dt_last_slot) :?> <?php $slot_end = date_create($this->day_dt_start->format(DATE_ATOM),new DateTimezone(PBBOOKING_TIMEZONE));?> <?php $slot_end->modify('+ '.$this->config->time_increment.' minutes');?> <tr> <th><?php echo Jhtml::_('date',$this->day_dt_start->format(DATE_ATOM),JText::_('COM_PBBOOKING_SUCCESS_TIME_FORMAT'));?></th> <?php foreach ($this->cals as $cal) :?> <td class="pbbooking-<?php echo (!$cal->is_free_from_to($this->day_dt_start,$slot_end)) ? 'free' : 'busy';?>-cell"> <?php if ($this->day_dt_start>date_create("now",new DateTimeZone(PBBOOKING_TIMEZONE)) && !$cal->is_free_from_to($this->day_dt_start,$slot_end)) :?> <a href="<?php echo JRoute::_('index.php?option=com_pbbooking&task=create&dtstart='.$this->day_dt_start->format('YmdHi').'&cal_id='.$cal->cal_id);?>"> <?php echo (!$cal->is_free_from_to($this->day_dt_start,$slot_end)) ? JText::_('COM_PBBOOKING_FREE') : JText::_('COM_PBBOOKING_BUSY');?> </a> <?php else :?> <?php echo JText::_('COM_PBBOOKING_BUSY');?> <?php endif;?> </td> <?php endforeach;?> </tr> <?php $this->day_dt_start->modify('+ '.$this->config->time_increment.' minutes');?> <?php endwhile;?> <!-- end draw table data rows--> </table> I currently have a web page which the user selects the value from the drop menu. I then want that value to go into another form in the same page inside a hidden field. Which will then be submitted to the processing php. The second option is the user selects the drop menu then the processing php would have to grab the value without a submit button because I am using a save button on the same page in the other form. Any help I'm trying to have it shows the data from my array as each option will have a value of the user's id and the text for the option will be their name. As of right now it only shows the last person. Code: [Select] <?php echo form_label('Recipient', 'recipient'); ?> <?php $data = array( 'name' => 'to', 'class' => 'required' ); <?php echo form_label('Recipient', 'recipient'); ?> <?php $data = array( 'name' => 'to', 'class' => 'required' ); $options = array(); foreach($users AS $user) { $options = array ( $user->user_id => $user->first_name.' '.$user->last_name ); } ?> <?php echo form_dropdown($data, $options); ?> Hi, I'm wondering how i would go about making a drop down menu in php to insert the option into users > Maint of my database, if anyone has any tutorials or examples it would be great, Thanks a lot. |