PHP - Select "field Name' As Question
Can anybody clarify the usefulness of "AS" and elaborate on how it operates.
If I select a 'bananas' AS 'yeelow fruit' will it change the TITLE in the table? Or the table that is being viewed? If I dump a list of 'FRUITS' into and HTML table, will using AS rename each column for me, or is that handled by MY coing of the HTML table? Similar TutorialsHi. I have two select fields one called category and the other sub category. Both are in the format. <select name="category" value=" <?php $qGetCat = "SELECT * FROM club_category" ; $rGetCat = mysql_query($qGetCat); while ($Cat = mysql_fetch_assoc($rGetCat)) { ?>" /> <option value="<?php echo $Cat['categorys'];?>"><?php echo $Cat['categorys']; ?></option> <?php } ?> </select> <select name="sub_category" value=" <?php $qGetSubCat = "SELECT * FROM sub_categorys" ; $rGetSubCat = mysql_query($qGetSubCat); while ($SubCat = mysql_fetch_assoc($rGetSubCat)) { ?>" /> <option value="<?php echo $SubCat['sub_categorys'];?>"><?php echo $SubCat['sub_categorys']; ?></option> <?php } ?> </select> Now I want to make it so that when a particular category is chosen for example self defence. The sub category when clicked shows all the self defence stuff. If watersports was chosen sub category would show things like swimming. What do I need to look up to do this? At the minute there is no link the way I have coded these to fields. In the database its self there is a; category table with categoryID and category_name sub category table with sub_cat_name and categoryID I think this will work but I have never done this so its making my head hurt just thinking about it. Does anyone have any advice, tuts or scripts to do this? Thank you Hi - i need help with the fourth column named "jobnr" it has to be the highest number first and lowest at the bottum of the tabel. I tried different variation like "mysql_query("SELECT * FROM tabel ORDER BY jobnr DESC")" but with no success. I attached a picture og the working script output Code: [Select] <html> <head> <meta http-equiv="Content-type" content="text/html; charset=UTF-8"/> </head> <style type="text/css"> .myclass { font-size: 8pt; font-face: Verdana; } </style> <body> <?php // Define variables $host="host"; // Host name $username="user"; // Mysql username $password="password"; // Mysql password $db_name="database"; // Database name $tbl_name="tabel"; // Table name // Connect to server and select databse mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // saetter db udtraek til UTF-8 endcoding mysql_set_charset('utf8'); // henter db data fra tabllen: jobpositons $sql="SELECT * FROM $tbl_name"; $result=mysql_query($sql); // Define $color=1 $color="1"; echo '<table border=0" bordercolor="#f3f3f3" cellpadding="1" cellspacing="1">'; echo "<tr bgcolor='#00aeef'> <th>Jobtitel</th> <th>Sted</th> <th>Oprettet</th> <th>jobnr</th> </tr>"; // sortere sql db data og indsaetter i html tabel while($rows=mysql_fetch_array($result)) { // If $color==1 table row color = #ffffff if($color==1){ echo "<tr bgcolor='#ffffff'><td class='myclass'>".$rows['Jobtitel']."</td><td class='myclass'>".$rows['Sted']."</td><td class='myclass'>".$rows['oprettet']."</td><td class='myclass' align='right'>".$rows['jobnr']."</td> </tr>"; // Set $color==2, for switching to other color $color="2"; } // When $color not equal 1, use this table row color else { echo "<tr bgcolor='#f3f3f3'> <td class='myclass'>".$rows['Jobtitel']."</td><td class='myclass'>".$rows['Sted']."</td><td class='myclass'>".$rows['oprettet']."</td><td class='myclass' align='right'>".$rows['jobnr']."</td> </tr>"; // Set $color back to 1 $color="1"; } } echo '</table>'; mysql_close(); ?> </body> </html> Forgive me if I am using the word "globally" incorrectly... I want to reset the content of a particular field in all rows of a table to a specific value, I was thinking of nesting a query inside a query for the same table, but was not sure that this would work: ... $query = "SELECT * FROM music WHERE picked >'0'"; $result = mysql_query($query) or die ("Couldn't execute query."); /* reset the picked field to zero (0) */ while ($row = mysql_fetch_array($result)) { $picked = 0; $query= "UPDATE music SET picked='$picked' WHERE title='$title'"; $selectresult = mysql_query($query) or die ("Problem with the query: $query<br>" . mysql_error()); } ... Is this the correct approach or is there a better way of doing this? 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! Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/aci/docs/admin/hours.php on line 20 Code: [Select] <?php $user = $_SESSION['myusername']; $result = mysql_query("SELECT * hours WHERE member='$user'"); while ($row = mysql_fetch_array($result)){ echo $row['date'] . " " . $row['time'] . "<br />"; } ?> Code: [Select] CREATE TABLE `hours` ( `hoursID` int(5) NOT NULL auto_increment, `member` varchar(20) NOT NULL default '', `date` date NOT NULL default '0000-00-00', `time` time NOT NULL default '00:00:00', PRIMARY KEY (`hoursID`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=7 ; -- -- Dumping data for table `hours` -- INSERT INTO `hours` VALUES (4, 'aci', '2010-11-30', '14:31:39'); INSERT INTO `hours` VALUES (2, 'aci', '2010-11-30', '14:31:08'); INSERT INTO `hours` VALUES (3, 'aci', '2010-11-30', '14:31:23'); INSERT INTO `hours` VALUES (5, 'aci', '2010-11-30', '14:31:40'); 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; } I am trying to print the list of a table which I requested with "SELECT DISTINCT" as below Code: [Select] $db_connect = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); $sql_get = "SELECT DISTINCT category FROM con"; $sql_run = mysqli_query($db_connect, $sql_get) or mysqli_error($db_connect); $sql_assoc = mysqli_fetch_assoc($sql_run); What is now needed to print the list of the table data by this conditions? I tried the while loop, but I seem to approach wrong, and get endless loops or errors. I'm a very new PHP user (as in, I just started today) and need to make a set of navigation buttons which will take the user to "next" or "previous" pages. I assume that the $_GET function is involved, but I don't know how to do it. It needs to work like this: If the URL looks like "http://website.com/page1.php" I need the "next" button (a href image) to change it to "/page2.php", and while on page 2, for the "previous" button to take the user to "/page1.php" and so forth. How can I cause the page number to increment or decrease respective to the href image being clicked? When I put "hello" in a text field it disappears, when the html page is submitted it dont like "" for example <input name="FirstName" type="text" id="FirstName" value="<?php if (isset($_POST['FirstName'])) echo ($_POST['FirstName']); ?>" maxlength="20" /> I am trying to add another "required field" to my PHP form, but I'm not sure what I'm doing wrong. The form and "required fields" work fine, but I am now trying to make the "Select skill level which is an "input type="radio" as a required field, but it is not working. As you can see below, I just tried adding the new "required" field the same way as the other 4 were set up, but it is not working (I think I have to do something different because the new "required field" is a "radio" type and the rest are "text"). The relevant parts of the code are below. Any assistance would be appreciated Code: [Select] <script type="text/JavaScript"> function verify() { var Skill = document.indiv_reg.skill.value; var Fname = document.indiv_reg.name.value; var Hphn = document.indiv_reg.home_num.value; var Email = document.indiv_reg.email.value; var Tname = document.indiv_reg.tname.value; if ((Fname =="") || (Skill =="") || (Hphn =="") || (Email =="") || (Tname =="")) { alert('Please Fill Out ALL Required Fields'); } else { document.indiv_reg.submit(); } } </script> <?php $url = "https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=6Y76L7TX6FVRW"; $sport = $_GET['sport']; $league = $_GET['league']; $visitor = $_GET['name']; $skill = $_GET['skill']; $tname = $_GET['tname']; $tcap = $_GET['tcap']; $homephn = $_GET['home_num']; $cellphn = $_GET['cell_num']; <?php * Denotes a Required Field<br /> <br /> <form name="indiv_reg" method="GET" action="tourney_mailRedirect.php"> Sport:<br /> <input type="text" name="sport" value="'.$sport.'" readonly="readonly" /><br /> <br /> Tournament:<br /> <input type="text" size="90" name="league" value="'.$league.'" readonly="readonly" /><br /> <br /> * Please select preferred skill level:<br /> <input type="radio" name="skill" value="recreational" /> Recreational<br /> <input type="radio" name="skill" value="competitive" /> Competitive<br /> <br /> * Name:<br /> <input type="text" name="name" /><br /> <br /> * Team Name:<br /> <input type="text" name="tname" /><br /> <br /> Team Captain:<br /> <input type="text" name="tcap" /><br /> <br /> * Home Phone:<br /> <input type="text" name="home_num" /><br /> <br /> Cell Phone:<br /> <input type="text" name="cell_num" /><br /> <br /> * Email:<br /> <input type="text" name="email" /><br /> <br /> ?> I have a varchar field called date that looks like this "2/06/2011 TUE" or like this "10/05/2011 WED". When I do an Order BY date Desc in php it does Not sort properly. Thanks for your assistance Steve I have a form where people will be putting in specific info such as their names and other info. When the form is posted I need to add a "." between the fields on the output depending on if it is filled out or not if field is blank do not need a "." Example if they put in their name Bob Marley on the form I need it to appear on the output as Bob.Marley. Here is the code using currently which also excludes blank fields echo $_POST["First"]; if(isset($_POST["Middle"])){ echo $_POST["Middle"]; } echo $_POST["Last"]; I want to post some form identifyer when I hit submit, so that I can use this in an SQL query. Previously I used the below code and would retrieve either page1.php or page2.php etc from $_POST['subject']); Code: [Select] <td> <select name="subject" id="subject" onchange="gotourl(this.value)"> <option value="" >Please Select</option> <option value="page1.php" >page1</option> <option value="page2.php">page2</option> <option value="page3.php">page3</option> </select> </td> will this work? Code: [Select] <form id="form1" name="form1" value="tableName" method="post" action=""> $_POST['form1']) returns tableName...... Thanks I am attempting to use use two tables from the same database as described below. My db connection is made and is good. As part of a larger application I am creating a comments feature. Each row is a separate comment that was left by a user. I've no problem getting each row from the database and printing each out as I want formatted. The second table I am using contains all of the personal info of each member including their username, their displayed name, location and among other things the URL to an image they want associated with their account. Each row in the comments table contains the following id # of the comment, username of the person that left it, the date and of course the body of the message itself. Now I am trying to get the comment to show the image found at the URL in the second table (personal info). So for each row in the comments table I want it to pull the commentor's img_url from the second table. $result = mysql_query("SELECT * FROM page_comments WHERE page_id = '$id'"); if(mysql_num_rows($result)==0) { echo "There are currently no comments."; }else{ while($row = mysql_fetch_array($result)) { echo "<table>"; echo "<tr>"; echo "<td>"; echo "<img sro=\"$img_url\" width=50 height=50>"; echo "</td>"; echo "<td>"; echo "<a href=profile.php?member="; echo $row['commentor']; echo ">"; echo $row['commentor']; echo "</a>"; echo "</td>"; echo "<td>"; echo $row['date']; echo "</td>"; echo "</tr>"; echo "<tr>"; echo "<td cospan=3>"; echo $row['comment']; echo "</td>"; echo "</tr>"; echo "</table>"; echo "<br />"; } } As you can see I've thrown the "$img_url" in there as a placeholder for the time being. I've tried a couple of ideas and while none of them threw any errors it, of course, didn't return a value so the img was broken and the HTML source was just empty. Any and all ideas are greatly appreciated. Hi there, Does anyone know how to select from a mutlidimensional array, and put the results in a new array? I figured it out but it takes a long time. My array is huge (over 1000+ items) and this search is performed about 50 times before loading the page. My array is called $tasks and it looks like this Code: [Select] $tasks=Array( [0]=>array([id]=>"12"; [owner]=>"nancy"; [task]=>"clean the house"); [1]=>array([id]=>"23"; [owner]=>"toby"; [task]=>"do homework"); [2]=>array([id]=>"43"; [owner]=>"dan"; [task]=>"take out trash"); [3]=>array([id]=>"32"; [owner]=>"nancy"; [task]=>"cook dinner"); ) I want to be able to select from $tasks where owner="nancy", so i end up with this Code: [Select] $nancy_tasks=array( [0]=>array([id]=>"12"; [owner]=>"nancy"; [task]=>"clean the house"); [1]=>array([id]=>"32"; [owner]=>"nancy"; [task]=>"cook dinner");) )Thank you!!! Why is this not working? I can not seem to incorporate and into the statement $query = "SELECT * FROM Project_Registrations WHERE (First_Name = '$_POST[name_1]' AND Teacher = '$_POST[teacher]' AND School = '$_POST[school]') OR (Second_Name = '$_POST[name_1]' AND Teacher = '$_POST[teacher]' AND School = '$_POST[school]') OR (First_Name = '$_POST[name_2]' AND Teacher = '$_POST[teacher]' AND School = '$_POST[school]') OR (Second_Name = '$_POST[name_2]' AND Teacher = '$_POST[teacher]' AND School = '$_POST[school]') "; Thanks Ok, I am not sure if I can explain it correctly, but here it goes. I have a form where user is asked to enter up to three name. Let's say that the fields are called [name1], [name2] and [name3] and they are called the came in the table. Now I have a code which allows me to compare what names are in the database versus the name that was entered by the user. $query = "SELECT * FROM Project_Registrations WHERE name1= '$_POST[name1]' "; $result2 = mysql_query($query); if (mysql_numrows($result2) > 0) { while($row = mysql_fetch_array($result2)) {echo" ...error code... ";} } else { ...ok code... }; This works well for one name field but I have three in the form and three in the table. How do I define it so all three name fields in the form are compared to all three in the table and if just on matches I can give them the ...error code...? Oh, and they can enter up to three names in the form, but it could be two or one. Can I code it such: $query = "SELECT * FROM Project_Registrations WHERE name1= '$_POST[name1]' OR name1= '$_POST[name2] OR name1= '$_POST[name2]' OR ...'"; Thanks Can someone please help me with an array problem i can not figure out. I need the array to be numbered from 1 to how ever many fields that are needed in the form and have a mysql field name and the title of the field also in the array. 1, "mysql_field_name", "Title of form field" 2, "", "" and so on then the form will be shown based on the array. I have the following draft code which I am working with. any suggestions on how i may do this array ? Code: [Select] <?php $options = array( '1'=> array('fieldtext'=>'option1', 'mysqlfield'=>'option1'), '2'=> array('fieldtext'=>'option2', 'mysqlfield'=>'option2'), '3'=> array('fieldtext'=>'option3', 'mysqlfield'=>'option3'), '4'=> array('fieldtext'=>'option4', 'mysqlfield'=>'option4'), ); // $options = array(1 => "option1", "option2", "option3", "option4"); // the line above works but i want to include the name of the mysql field as well. $userid = 1; ?> <div style="align: center; margin: 12px; font-family:Tahoma;"> <br><br><?php if ($_POST['Update'] != "Update") { // check if form submitted yet, if not get data from mysql. $res = db_query("SELECT * FROM `users` WHERE `userid` = '" . $userid . "'"); foreach($options as $key => $value) { $_POST[$key] = mysql_result($res, 0, $value); } $ok_to_update = "no"; } elseif ($_POST['Update'] == "Update") { // check if form submitted yet, if so get POST data. // error checking // foreach($options as $key => $value) { // $_POST[$i] = ""; // } $ok_to_update = "yes"; } if ($_POST['Update'] == "Update" && $ok_to_update == "yes") { // $res = db_query("INSERT INTO `users` () VALUES ()"); // add user details to database. ?><p><br><br><br>Thank you for updating</p><?php } else { ?><form name="form1" method="post" action=""> <?php foreach($options as $key => $value) { ?><p><?php echo($value); ?>: <input type="text" name="<?php echo($key); ?>" value="<?php echo($_POST[$key]);?>"></p> <?php } ?> <input name="Update" type="submit" value="Update"> </form> <?php } ?> </div> I'm confused... how do you say check if the field in MYSQL is blank? it's not getting what I'm attempting to get. Please help. I want to do actionA... if either of these 3 conditions are true tf1=="RED" tf1=="" tf2=="" AND tf=="apple" if(tf1=="RED" or tf1=="" or tf2=="" AND tf=="apple") { do actionA... } Hi guys,i was trying to figure out how to work with <select> tag, remember/set the value that was being selected before. The values are fetched from the database..From other forums I've been, they said that $_SESSION will do the work but I'm having trouble where to put it inside my code.. Please take a look at this Code: [Select] <form name="form1" action="do_set.php"> <?php $sql="SELECT school_year FROM admin_sy ORDER BY school_year ASC" or die (mysql_error()); $result=mysql_query($sql); echo "Set schoolyear: <select name=SY value=''>"; while($row=mysql_fetch_array($result)) { echo "<option value=$row[school_year]>$row[school_year]</option>"; } echo "</select>"; ?> <br> Sem: <select name="sem"> <option value="1st">1st</option> <option value="2nd">2nd</option> <option value="Summer">Summer</option> </select> <input type="Submit" name="submit" value="Set"> </form> as you can see, 'school_year' are fetched from a database. now my problem is, when i select a specific year, the value should be "remembered" after i click set or refresh the page or go back from the previous page. this will be useful so the user will be able to know what school year has already been set. hope you guys can help.. thanks in advance. |