PHP - Select Default
I have a few dropdown forums and would like it to select the current values that are requested.
Code: [Select] global $filename,$fileid,$filetype,$filedir,$fileby; global $months,$pg; echo "<h2>Search Files</h2>"; echo "<p>"; echo "<form name = 'File_Search' action = '#' method = 'POST'>"; echo "<table border=\"0\" width=\"100%\"><tr>"; echo "<td>File Name<br><input type = 'text' name = 'name'></td><td>File Type<br><select name = 'type'> <option value = '0'>All Types</option> <option value = 'o'>Official Files</option> <option value = '1'>Quests</option> <option value = '2'>Graphic/Spritesheets</option> <option value = '3'>Entity/Scripts</option> <option value = '4'>Sound/Music</option> <option value = '5'>QuestPack/Programs</option> <option value = '6'>Miscellaneous</option> </select></td>"; echo "<td>Order By<br><select name = 'order'> <option value = '0'>Last Updated</option> <option value = '1'>ID</option> <option value = '2'>Name</option> <option value = '3'>Downloads</option> <option value = '4'>Rating</option> <option value = '5'>Points</option> <option value = '6'>Random</option> </select></td>"; echo "<td>Acending?<br><select name = 'dir'><option value = '0'>False</option><option selected value = '1'>True</option></select></td>"; echo "</tr><tr><td rowspan = '4'><input type = 'submit' name = 'search' value = 'search'></td></tr></table></form>"; echo "</p>"; So if the $filetype equals 2 I want the dropdown box to show "Graphic/Spritesheets" by default. BTW Official Files is not actually a type so that's why I chose to give it a small letter o and will work the same way as All Types but run a different function. $fileby is used for the OrderBy field. $filedir is for the Acending field. The other data is for the other parts of the script. If you like you can give advice on the name's default because you may have a better method then what I have in my head. Similar TutorialsI created a drop-down menu using a MySQL statement in php for a form. My drop down menu works fine, but I want to assign a default value to it (normal text) the value will never change, thus I do not need to extract the default value from the table, I already know the value. Here is the basic snippet from the script: <?php include("../includes/xxx.php"); $cxn = mysqli_connect($host,$user,$password,$dbname); $query = "SELECT DISTINCT `plant_id` FROM `plant` ORDER BY `plant_id`"; $result = mysqli_query($cxn,$query); while($row = mysqli_fetch_assoc($result)) { extract($row); echo "<option value='$plant_id'>$plant_id</option>\n"; } ?> Hey guys. Me again... Essentially what i am doing is pulling data from a MySQL database about the number of thumbnails on a page. The user can then change this using a <select> dropdown menu. How ever, i want the <select> to default to the amount already specified by the Database. I know i can do this by inserting a Selected attribute to one of the <options> but what is the best way of doing this? Heres my code.. $NumberOfThumbnails = mysql_result($data, 0,"NumberOfThumbnails"); <select name="numberofthumbnails"> <option value="0">None</option> <option value="2">2</option> <option value="4">4</option> <option value="6">6</option> <option value="8">8</option> <option value="10">10</option> <option value="12">12</option> <option value="14">14</option> <option value="16">16</option> <option value="18">18</option> <option value="20">20</option> <option value="22">22</option> <option value="24">24</option> <option value="25">25</option> <option value="26">26</option> <option value="27">27</option> <option value="28">28</option> </select> Thanks - Danny Hi, I need to call to this text to add a all with value "blank/empty" or "0" to the dropdownlist code below.. it should be inserted int the first position in the dropdownlist and have a value blank and call to this text from the language files: $searchAll = gettext('_LANGUAGE_SEARCH_ALL',_LANGUAGE_SEARCH_ALL,false,false); example is: ratestitle=>0 gettext('_LANGUAGE_SEARCH_ALL',_LANGUAGE_SEARCH_ALL,false,false); the words it calls is "ALL" when the user selects or leaves the "ALL" in the list the value remains empty this allows the search to search everything.. basically im stuck how to get it in the dropdown list as the first default position: can anyone help? here is my code://this is a search function which calls to the field rate_title the text from the select box is matched to the database table and the search pages shows the search option is the search is successful.. I have 5 of these types of searches but cant give a broader search option to my users as the values must be selected to search--- i need the option "ALL" to have a "EMPTY" value or no value.... if (in_array("ratestitle",$searchOptions)&& $showSearchOptions ) { if (empty($sch->filter['ratestitle']) ) $selectOption=$output['LANGUAGE_SEARCH_RATESTITLE']; else $selectOption=$sch->filter['ratestitle']; $showButton=true; $query = "SELECT DISTINCT rate_title FROM #__rates_table ORDER BY rate_title ASC"; $dropDownList ="<select class=\"inputbox\" name=\"ratestitle\">"; $ratesitles =doSelectSql($query); foreach ($ratesitles as $ratetitle) { $selected=""; $rate_title=$ratetitle->rate_title; if ($ratetitle==".$sch->filter['ratestitle'].") $selected="selected"; $dropDownList .= "<option ".$selected." value=\"".$rate_title."\">".$rate_title."</option>"; } $dropDownList.="</select>"; $output['RATESTITLE']=$dropDownList; } hirealimo.com.au/code1.php this works as i want it: Quote SELECT * FROM price INNER JOIN vehicle USING (vehicleID) WHERE vehicle.passengers >= 1 AND price.townID = 1 AND price.eventID = 1 but apparelty selecting * is not a good thing???? but if I do this: Quote SELECT priceID, price FROM price INNER JOIN vehicle....etc it works but i lose the info from the vehicle table. but how do i make this work: Quote SELECT priceID, price, type, description, passengers FROM price INNER JOIN vehicle....etc so that i am specifiying which colums from which tables to query?? thanks Hi guys and gals , got a minor problem. I have a table in which i want the "photo" column to have a default value of "noimage.jpg". I set the default value to "noimage.jpg" and put "as defined" too. but when i fill the form in and leave the upload field blank it doesnt show the noimage.jpg as it should and in the mysql table it leaves it blank and not with default value. Here is the inserts.php which adds the data to the mysql table. Can you help please. <CENTER><B>Vehicle Added</B></CENTER> <BR> <?php mysql_connect("localhost", "wormste1_barry", "barry") or die(mysql_error()); mysql_select_db("wormste1_barry") or die(mysql_error()); $CarName = mysql_real_escape_string(trim($_POST['CarName'])); $CarTitle = mysql_real_escape_string(trim($_POST['CarTitle'])); $CarPrice = mysql_real_escape_string(trim($_POST['CarPrice'])); $CarMiles = mysql_real_escape_string(trim($_POST['CarMiles'])); $CarDescription = mysql_real_escape_string(trim($_POST['CarDescription'])); $pic = mysql_real_escape_string(trim($_FILES['uploadedfile']['name'])); $target_path = "images/"; $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; echo "<br />"; } else{ echo "There was an error uploading the file, please try again!"; } mysql_query("INSERT INTO cars (CarName, CarTitle, CarPrice, CarMiles, CarDescription, photo) VALUES('$CarName', '$CarTitle', '$CarPrice', '$CarMiles', '$CarDescription', '$pic' ) ") or die(mysql_error()); echo "The vehicle data has been added!"; ?> How to define default folder. For example I have folder images and in that folder specific image. In the root directory I have index.php with Code: [Select] <?php require_once("public/includes/header.php"); ?>and in index.php there are links which goes to different folder: Code: [Select] <a href="public/sajt/kategorija.php?id=<?php echo $id; ?>">which also have header.php, but there is no image. How to make default folder for image, or some similar solution? How do I set the date format so that it's always going by the UTC date? I've used: Code: [Select] date_default_timezone_set('UTC'); but, when I change my date on my computer, the date changes on the website. This is really confusing me, googled different ways for like 10/20 minutes and can't find anything. If anyone can help it'd be great, Thanks, Andy. Hi. I have drop down boxes for date and time that work. The year is a problem because I am using variables instead of fixed values. Code: [Select] <select name="Year" style="width:60px"> <option value="2010" >Test <option value="<?=$ThisYear?>" <? if ($Year == "<?=$ThisYear?>"){?> SELECTED <?}?> ><?=$ThisYear?> <option value="<?=$NextYear?>" <? if ($Year == "<?=$NextYear?>"){?> SELECTED <?}?> ><?=$NextYear?> </select> <select name="Hour" style="width:50px"> <option value="10" <? if ($_SESSION["Hour"] == "10"){?> SELECTED <?}?> >10 <option value="11" <? if ($_SESSION["Hour"] == "11"){?> SELECTED <?}?> >11 <option value="12" <? if ($_SESSION["Hour"] == "12"){?> SELECTED <?}?> >12 <option value="13" <? if ($_SESSION["Hour"] == "13"){?> SELECTED <?}?> >13 <option value="14" <? if ($_SESSION["Hour"] == "14"){?> SELECTED <?}?> >14 <option value="15" <? if ($_SESSION["Hour"] == "15"){?> SELECTED <?}?> >15 <option value="16" <? if ($_SESSION["Hour"] == "16"){?> SELECTED <?}?> >16 <option value="17" <? if ($_SESSION["Hour"] == "17"){?> SELECTED <?}?> >17 <option value="18" <? if ($_SESSION["Hour"] == "18"){?> SELECTED <?}?> >18 <option value="19" <? if ($_SESSION["Hour"] == "19"){?> SELECTED <?}?> >19 <option value="20" <? if ($_SESSION["Hour"] == "20"){?> SELECTED <?}?> >20 </select> however this works Code: [Select] <select name="Year" style="width:60px"> <option value="2010" >Test <option value="<?=$ThisYear?>" <? if ($Year == "2011"){?> SELECTED <?}?> ><?=$ThisYear?> <option value="<?=$NextYear?>" <? if ($Year == "2012"){?> SELECTED <?}?> ><?=$NextYear?> </select> Can anyone help with this please TIA Desmond. Hi, I am trying to get the date and time that a particular table was last updated, which the code below does, but it doesn't seem to be putting it in the correct timezone, it is 5 hours behind, anyone know why this is? or how i can fix it? Thanks Code: [Select] <?php date_default_timezone_set('Europe/London'); $query = "SELECT UPDATE_TIME FROM information_schema.tables WHERE TABLE_SCHEMA = 'tffdb' AND TABLE_NAME = 'test_team_points'"; $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_assoc($result); echo $row['UPDATE_TIME']; ?> In a Switch statement, can you give the Default: a specific name, maybe like this... switch ($resultsCode){ // Missing Primary Key. case 'COMMENT_MISSING_KEYS_2050': echo '<h1>System Error</h1>'; echo '<p>A Fatal Error has occurred. Please contact the System Administrator. (2050)</p>'; break; default 'DEFAULT_CATCHALL_ERROR_CODE_9999': echo '<p>You have reached the catch-all error code... (9999)</p>'; break; Debbie I am loading a link with ajax. When the link pops on the screen and I click it, I get redirected to my 404 page and my lightbox doesn't load. If the link pops in and I refresh my browser, then I click the link my lightbox will show up. How can I do a prevent default on the <a href> in pure JS? No frameworks please. I have this code, for an Upload Form, that works successfully renaming and moving an uploaded file to the upload/ folder. I am using this php code <?php echo $_GET['CiFrame']; ?> to check the url for the variable CiFrame, this allows me to link to a page through my page containing the iframe. Here is my iframe code. <iframe name="CiFrame" width="727" height="805" src="<?php echo $_GET['CiFrame']; ?>" scrolling="auto" frameborder="0"></iframe> The problem is that if the url does not contain a variable the iframe will not open a page. How can i set a default variable if one is not provided? Thank You ok this grabs mp3 from 4shared but the download link appears as preview.mp3 how could i get it to be renamed as the original reach name like here_without_you.p3 or something else? Code: [Select] <?php $file = file_get_contents("http://www.4shared.com/audio/PmMMpPFs/here_without_you.htm"); $body = preg_replace("/.*file[^=]*=|\&volume.*/si", "", $file); preg_match("/((ftp)|(http(s?))\:\/\/(([A-z0-9\?\-\:\=\;\.\@\/]+)))/is",$body, $result); $download_url = $result[1]; print_r($download_url); ?> having a problem figuring out how to change the default on a drop down box to equal the users current timezone. So when they view it the drop box default is showing what their setting is atm. The problem is the value is differant from whats displayed. Is it possible to some how say if users time offset is equal to a option value set selected=""> to yes. if not what is the idea behind this? Cant find a guide showing an example In other drop down boxes where the value is the same as whats displayed I just simply created another value field at the top of the list and echo it in. Code: [Select] <select name="gmt"> <option value="-28800">(GMT -0800) Pacific Time </option> <option value="-25200">(GMT -0700) Mountain Time </option> <option value="-21600">(GMT -0600) Central Time</option> <option value="-18000">(GMT -0500) Eastern Time </option> </select> In PHP when you post a form the default font is Times New Roman how do I changes the font to arial Ok, i can't understand whats wrong with the DATE field in MySQL and PHP. I have a form in PHP witch has 3 birth day dropdown menus that looks like this (YYYY-MM-DD). An in my database i have a birth_day colum with DATE as type and i've tried to set the default value to "None" and "0000-00-00" but nothing works. Everytime i try to input something (e.g. 1993-16-05) i get this error: Incorrect date value: '05' for column 'birth_day' at row 1 I've tried to set the value for the "Day" dropdown in the PHP form to both 5 and 05 but still nothing, what am i doing wrong? Hi guys, Before we go further, yes, I know I should use prepared statements. This is just a project that will probably never go live. If I do decide to go live, I will change to prepared statements. Anyways, I am populating a text box from the selection of an options dropdown and updating MySQL. This all works fine. However, what I want to do is have the newly inserted option display by default in the dropdown. Hope this makes sense. Here is the dropdown code with the select statement... <div class="row form-group"> <div class="col-6"> <div class="form-group"><label for="location" class=" form-control-label">location</label> <?php $sql = "SELECT location_name, location_phone FROM locations"; $result = $con->query($sql); ?> <select name="location" id="location" onchange="myFunction()" class="form-control"> <?php while($r = mysqli_fetch_row($result)) { echo "<option data-location_name='$r[1]' data-location_phone='$r[2]' value='$r[0]'> $r[0] </option>"; } ?> </select> <label>Phone</label><input type="text" class="form-control" name="location_phone" id="location_name" value = "<?php echo $row['location_phone']; ?>"/> I am grabbing the location name and phone number from locations. Then inserting them into tours. So after the form is submitted, I want the location name to stay in the dropdown. This is in the table "tours". How do I implement that in here? Thanks heaps. This topic has been moved to HTML Help. http://www.phpfreaks.com/forums/index.php?topic=356851.0 My 1st try practice uploading file to the server and it was successful. Now I wonder how can I set a default file name to the file that will be uploaded and overwrite the existing one. I have tried experimenting on the code but I can't get it to work. Here's my simple code.. edit_logo.php Code: [Select] <?php <form enctype="multipart/form-data" method="post" action="uploaded_logo.php"> <input type="hidden" name="MAX_FILE_SIZE" value="100000" /> <tr> <td>Choose a Logo to Upload: </td> <td><input name="uploaded_file" type="file" /></td> </tr> <tr> <td> </td> <td><input type="submit" value="Upload File" name="submit>"</td> </tr> </form> ?> uploaded_logo.php Code: [Select] <?php if($_FILES['uploaded_file']["type"] == "image/gif") { $target_path = "logo/"; $target_path = $target_path. basename($_FILES['uploaded_file']['name']); if(move_uploaded_file($_FILES['uploaded_file']['tmp_name'], $target_path)) { echo "<span class=\"error_validation\">The Logo has been successfully changed!<br></span>"; echo "<span class=\"error_validation\">Upload Logo Again? <a href=\"edit_logo.php\">Click Here</a><br></span>"; } else { echo "<span class=\"error_validation\">There was an error uploading the logo. Pls. try again.<br></span>"; echo "<span class=\"error_validation\">Upload Logo Again? <a href=\"edit_logo.php\">Click Here</a><br></span>"; } } else { echo "<span class=\"error_validation\">Invalid file format. We are only accepting image file. Pls. try again.<br></span>"; echo "<span class=\"error_validation\">Upload Logo Again? <a href=\"edit_logo.php\">Click Here</a><br></span>"; } ?> So what the code suppose to do is.. If I upload an image file as the new logo it should have the default logo name "my_logo.gif", then it will overwrite the existing one... Anyone? |