PHP - Php/mysql 2 Dropdown Lists Filter & Display On Screen Result
Hello to all.
I'm new here and i am very glad to be a part of this community. I am new in PHP/mysql but i try to learn as much as i can in php & mysql. And here is the problem: Into a php or html page i want to display 2 dropdown list to act as a filter for displaying a table. I managed to display a table based on option select from first dropdown but i don'y know how to make or activate the second dropdown list to act as a filter, and when i press "result" to display on the same page the results. Thanks a lot. Similar Tutorialshello. i have an issue where the data stored with an image is not saving to a mysql table. the image data is ok, just not the selections from the dropdown lists. here is the code <?php include ('connect.php'); // Insert any new image into database if(isset($_POST['xsubmit']) && $_FILES['imagefile']['name'] != "") { $fileName = $_FILES['imagefile']['name']; $fileSize = $_FILES['imagefile']['size']; $fileType = $_FILES['imagefile']['type']; $content = addslashes (file_get_contents($_FILES['imagefile']['tmp_name'])); $jeweltype = $_POST['jeweltype']; $jewelsize = $_POST['jewelsize_in']; $jewelcolour = $_POST['jewelcolour_in']; $jewelmaterial = $_POST['jewelmaterial_in']; $jewelgender = $_POST['jewelgender_in']; if(!get_magic_quotes_gpc()) { $fileName = addslashes($fileName); } // Checking file size if ($fileSize < 150000) { mysql_query ("INSERT into jewel_images (name,size,type,content,jeweltype,jewelsize,jewelcolour,jewelmaterial,jewelgender) " . "values ('$fileName','$fileSize','$fileType','$content','$jeweltype','$jewelsize','$jewelcolour','$jewelmaterial','$jewelgender')"); } else { $err = "The Image file to too large!"; } } // Find out about latest image $gotten = mysql_query("select * from jewel_images order by row_id desc"); $row = mysql_fetch_assoc($gotten); $bytes = $row['content']; // If this is the image request, send out the image if ($_REQUEST['pic'] == 1) { header("Content-type: $row[type];"); print $bytes; } ?> <html> <head> <title>Upload an image to a database</title> </head> <body> <font color="#FF3333"><?php echo $err ?></font> <table> <form name="Upload" enctype="multipart/form-data" method="post"> <tr> <td>Upload <input type="file" name="imagefile"><br /> Jewelery Type: <select> <?php $sql="SELECT jeweltype FROM jeweltypes"; $result =mysql_query($sql); while ($data=mysql_fetch_assoc($result)){ ?> <option value ="jeweltype" ><?php echo $data['jeweltype'] ?></option> <?php } ?> </select> <br /> Jewelery Size: <select> <?php $sql="SELECT jewelsize FROM jewelsizes"; $result =mysql_query($sql); while ($data=mysql_fetch_assoc($result)){ ?> <option value ="jewelsize" ><?php echo $data['jewelsize'] ?></option> <?php } ?> </select> <br /> Jewelery Colour: <select> <?php $sql="SELECT jewelcolour FROM jewelcolours"; $result =mysql_query($sql); while ($data=mysql_fetch_assoc($result)){ ?> <option value ="jewelcolour_in" ><?php echo $data['jewelcolour'] ?></option> <?php } ?> </select> <br /> Jewelery Material: <select> <?php $sql="SELECT jewelmaterial FROM jewelmaterials"; $result =mysql_query($sql); while ($data=mysql_fetch_assoc($result)){ ?> <option value ="jewelmaterial_in" ><?php echo $data['jewelmaterial'] ?></option> <?php } ?> </select> <br /> Jewelery Gender: <select> <?php $sql="SELECT jewelgender FROM jewelgenders"; $result =mysql_query($sql); while ($data=mysql_fetch_assoc($result)){ ?> <option value ="jewelgender_in" ><?php echo $data['jewelgender'] ?></option> <?php } ?> </select> <br /> <input type="submit" name="xsubmit" value="Upload"> </td> </tr> <tr> <td>Latest Image</td> </tr> <tr> <td><img src="?pic=1"></td> </tr> </form> </table> </body> </html> ============================================== here is the query =============================================== <html> <head><title>Your Page Title</title></head> <body> <?php $database="josh_jewel"; mysql_connect ("localhost", "xxxxxxxxx", "yyyyyyyyyyyy"); @mysql_select_db($database) or die( "Unable to select database"); $result = mysql_query( "SELECT jewelcolour FROM jewel_images" ) or die("SELECT Error: ".mysql_error()); $num_rows = mysql_num_rows($result); print "There are $num_rows records.<P>"; print "<table width=400 border=1>\n"; while ($get_info = mysql_fetch_row($result)){ print "<tr>\n"; foreach ($get_info as $field) print "\t<td><font face=arial size=1/>$field</font></td>\n"; print "</tr>\n"; } print "</table>\n"; ?> </body> </html> I have found postings close, but not close enough to find my error. I am looking up data from a MySql table and putting it in a dropdown box on a form. I can select the item, but apparently not really. I am not able to echo it, or post it to a record. I'm sure I am missing something simple, but... Code attached if anyone can show me the errors of my ways. Thank you. I am seeking to learn more about the noted subject, how to use PHP to allow a user to enter search terms and search a database. I have experimented with this with little results save for errors. Please see code listed below: search.php <? //// filename = search.php <form method="post" action="result.php3"> <select name="metode" size="1"> <option value="row_name1">metode1</option> <option value="row_name2">metode2</option> </select> <input type="text" name="search" size="25"> <input type="submit" value="Begin Searching!!"> </form> ?> results.php //// filename = result.php3 <? $hostname = "mysql7.000webhost.com"; // Usually localhost. $username = "a4542527_root"; // If you have no username, leave this space empty. $password = "*******"; // The same applies here. $usertable = "people"; // This is the table you made. $dbName = "a4542527_test1"; // This is the main database you connect to. MYSQL_CONNECT($hostname, $username, $password) OR DIE("Unable to connect to database"); @mysql_select_db( "$dbName") or die( "Unable to select database"); ?> <? //error message (not found message) $XX = "No Record Found"; $query = mysql_query("SELECT * FROM $usertable WHERE $metode LIKE '%$search%' LIMIT 0, 30 "); while ($row = mysql_fetch_array($query)) { $variable1=$row["row_name1"]; $variable2=$row["row_name2"]; $variable3=$row["row_name3"]; print ("this is for $variable1, and this print the variable2 end so on..."); } //below this is the function for no record!! if (!$variable1) { print ("$XX"); } //end ?> Upon viewing search.php I receive the error message: Parse error: syntax error, unexpected '<' in /home/a4542527/public_html/search.php on line 3 I believe I may be missing something and am a bit lost. Thank-you in in advance for any help or suggestions. ~Matty Hi, I have come up with the following code, I need it to get the details of several scattered products and echo the results, the trick is I don't want it to echo the results one after the other... I want to have the products scattered between unique text on the page but don't want to run the query several times for performance reasons. E.g.- PAGE to look like this: $Product_1 unique text/images $Product_2 $Product_3 unique text/images $Product_4 Current Code: Code: [Select] <? $result = mysql_query("SELECT * FROM products where Product_ID IN (475, 465, 234, 567, 845)"); while($row = mysql_fetch_array($result)) { $x = "1"; while ($x<=3) { echo $x; $Product = "Product_"; $Product = $Product.$x; echo $Product; $Product = $row['Product_ID']; echo $Product; $x++; echo $x; } } At the moment it returns the following results: Quote 1 Product_1 465 2 2 Product_2 465 3 3 Product_3 465 4 1 Product_1 475 2 2 Product_2 475 3 3 Product_3 475 4 A few problems... In Blue... it duplicates for product 465 In Red... It repeats again for 475 Also.... it starts with 465, but I want it to go in order as how it appears - $result = mysql_query("SELECT * FROM products where Product_ID IN (475, 465, 234, 567, 845)"); so should start with 475 I want to get the following result: Quote 1 Product_1 475 2 2 Product_2 465 3 3 Product_3 234 4 4 Product_4 567 4 (and so on.....) If anyone could provide me assistance with my troubled 'while loop' statement that would be much appreciated! Hi every body I get label of forms from db to customize for different languages. My problem is when i get result how i could find label of each row. I could select for each row of form but it is not logical. In .Net i could fill array and use items.find property of array to find title of each row for example label of "first name" in English or Germany. Thanks for any guides. Regards Ali Hey all,
maybe someone can help me with this problem:
I am using PHP and i want to extract the red text including the orange text but only between the blue text.
i tried a lot, but i cant find the solution.
This is what i tried: $repattern = '/<td class="program_date">(\s+\S+.+)\s+.+(\s\S.+)<\/a>/i';
The final result should look like this:
Array with following Data inside:
Mo, 09.06.2014
13:45
16:15
Di, 10.06.2014
13:45
Mi, 11.06.2014
13:45
16:15
and so on..
Thanks in advance.
Here is a part from source:
<td class="program_time"> <span class="program_head">Vorstellungen:</span><br /> <table> <tr> <td class="program_date"> Mo, 09.06.2014 </td> <td><a href='http://fmzimst.kinokartenreservierung.at/reservierung.php?id=74380' target="_top">13:45</a> </td> <td><a href='http://fmzimst.kinokartenreservierung.at/reservierung.php?id=74381' target="_top">16:15</a> </td> </tr> <tr> <td class="program_date"> Di, 10.06.2014 </td> <td><a href='http://fmzimst.kinokartenreservierung.at/reservierung.php?id=74384' target="_top">13:45</a> </td> </tr> <tr> <td class="program_date"> Mi, 11.06.2014 </td> <td><a href='http://fmzimst.kinokartenreservierung.at/reservierung.php?id=74388' target="_top">13:45</a> </td> <td><a href='http://fmzimst.kinokartenreservierung.at/reservierung.php?id=74389' target="_top">16:15</a> </td> </tr> <tr> <td class="program_date"> Do, 12.06.2014 </td> <td><a href='http://fmzimst.kinokartenreservierung.at/reservierung.php?id=74392' target="_top">13:45</a> </td> <td><a href='http://fmzimst.kinokartenreservierung.at/reservierung.php?id=74393' target="_top">16:15</a> </td> </tr> </table> </td> Edited by spaxi, 09 June 2014 - 07:24 AM. Hi guys I'm having problem on how to display my php mysql result like this.. Digitalpoint, phpfreaks, adsense here's my code Code: [Select] $result = mysql_query ("SELECT dateline, dateline_from, eventid, title FROM vb_event WHERE calendarid = 1 AND dateline_from >= '$day_before' ORDER BY dateline_from LIMIT 2"); while($row = mysql_fetch_array( $result )) { echo "<a href='/forum/calendar.php?do=getinfo&e=" . $row['eventid'] . "&c=1' title='". $row['title'] . "' style='font-size:12px;'>" . $row['title'] . "</a> " ; } the result is Digitalpoint, phpfreaks, adsense, how to remove the "," in the end? it should be like this.. Digitalpoint, phpfreaks, adsense with no , comma in the end.. Thank you.. Hello,
I'm new to php, I don't really have much experience, just have used it in combination with dreamweaver. I'm tackling a new problem now.
Basically, it's about a dropdown menu with pre-defined values. There are multiple dropdowns, having different value choices. People are supposed to be able to select more than one option and then search for the results. these should then be generated according to the selected values, or if no value is selected, ALL is shown.
When the user clicks on search, the values create a msql query that will then be executed and the results shown on the page.
I've been searching high and low for code ideas, but see different stuff everywhere I look, and none of the code seems to be what i want. Some people are using Javascript, some Ajax, or PHP. ideally, I want to use just php and sql
Can someone point me in the right direction on how to tackle this problem, or maybe someone has some code ideas?
Thanks in advance.
Mio
I have set up a dynamic dropdown to filter records on a page but it is not working and I feel it is down to the way I am using the GET. My guess is that you cannot use dates as a filter in this way but I cannot find any evidence of that through searching, mainly as I do not know what to search for! The url generated is 'games.php?date=2005-09-03&submit=Filter' so it is passing the data from the dropdown correctly but I am clearly missing something as it just returns that no records have been found. I am probably missing something simple and am sure that someone on here will spot it within seconds but I am lost. The actual testing page for this, in case you want to have a look at it not working, is http://www.margate-fc.com/content/test/games.php. As always, any advice would be greatly appreciated! Steve The Query Part // The 'WHERE' bit if (isset($_GET['date'])) { if ($_GET['date'] == "") { $filter = ""; } else { $filter = "WHERE date = {$_GET['date']}"; } } // Main Query $limit = 5; $all_games = mysql_query("SELECT *, HT.team_name as HomeTeam, VT.team_name as AwayTeam, COMP.comp_short_name as CP FROM all_games JOIN teams as HT ON all_games.home_team = HT.team_id JOIN teams as VT ON all_games.away_team = VT.team_id JOIN competitions as COMP ON all_games.comp = COMP.comp_id $filter ORDER BY all_games_id ASC "); if (!$all_games) { die("Query to show fields from table failed"); } // Filter query $dates = mysql_query("SELECT DISTINCT date FROM all_games ORDER BY date ASC "); The form Code: [Select] <!--Filter Form--> <form method='get' enctype='text/plain'> <select size='1' name='date'> <?php while ($row_dates = mysql_fetch_assoc($dates)){ echo "<option value='".$row_dates['date']."'>".$row_dates['date']."</a></option>"; } ?> </select> <input type='submit' name='submit' value='Filter'> </form> The table part (excluding header row) Code: [Select] <?php if(!mysql_num_rows($all_games)) { echo "<tr><td style=\"text-align:left\" COLSPAN=\"8\">No records returned</td></tr>"; } else { while ($row_all_games = mysql_fetch_assoc($all_games)){ echo '<tr> <td style="text-align:left" width="10PX">'.$row_all_games['all_games_id'].'</td>'; if ($row_all_games['date']=="") echo '<td>TBA</td>'; else echo '<td style="text-align:left" width="100PX">'.date('d M y',strtotime($row_all_games['date'])).'</td> <td style="text-align:left">'.$row_all_games['CP'].'</td> <td style="text-align:left"> '.$row_all_games['HomeTeam'].'</td> <td style="text-align:left"> '.$row_all_games['home_goals']. '</td> <td style="text-align:left"> '.$row_all_games['AwayTeam']. '</td> <td style="text-align:left"> '.$row_all_games['away_goals']. '</td> <td style="text-align:left"> '.$row_all_games['attendance']. '</td> </tr>'; }} ?> Hi everyone, I've read through the FAQs for Dynamic Dropdown Menus on this site, as well as others, and I can't figure out why my code won't work. I have two dropdown boxes that need to be populated with data from a mysql table; one menu for route types, and one for route numbers. When I choose the route from the 'Route' menu, the 'Number' menu automatically populates with all of the possible numbers, rather than only those that correspond with the route type. I can tell that the problem has something to do with the value of 'Route' not being recognized, but I don't know why. I'm a beginner when it comes to PHP, so any suggestions or help would be much appreciated! Thanks! The code is as follows: Code: [Select] <html> <body> <basefont face='calibri' color='#7E2217'> <?php // set variables $mileTable = $_GET['mileTable']; $routeType = isset($_POST['Roadtype'])? $_POST['Roadtype']: 0; include 'opendbMile.php'; include 'error.php'; // Connect to the MySQL DBMS if (!($connection = @ mysql_connect($hostName, $username, $password))) die("Could not connect"); if (!mysql_select_db($databaseName, $connection)) showerror( ); // Start a query... $query = "SELECT ID, Roadtype FROM Alabama GROUP BY Roadtype"; // execute the SQL statement $result = mysql_query($query, $connection) or die(mysql_error()); echo '<form name="mileform" method="post" action="MileQuery.php">'; echo '<p>Route: <select name="routeType" id="routeType" onchange="this.form.submit();"> <option value="0"'.($routeType == 0? ' SELECTED': '').'>Route</option>'; while($row = mysql_fetch_array($result)){ echo ' <option value="'.$row[0].'"'.(($routeType == $row[0])? ' SELECTED': '').'>'.$row[1].'</option>'; } echo ' </select> </p>'; // create the SQL statement $query2 = "SELECT ID, Roadnumber FROM Alabama GROUP BY Roadnumber"; if($mnucategory != 0){ // Filter road numbers $query2 .= " WHERE Roadtype='".$routeType."'"; } // execute the SQL statement $result2 = mysql_query($query2, $connection) or die(mysql_error()); echo '<p>Number: <select name="routeNumber" id="routeNumber" onchange="this.form.submit();"> <option value="0"'.($routeNumber == 0? ' SELECTED': '').'>Number</option>'; while($row2 = mysql_fetch_array($result2)){ echo ' <option value="', $row2[0].'"'.(($routeNumber == $row2[0])? ' SELECTED': '').'>'. $row2[1], '</option>'; } echo ' </select> </p>'; // Close the DBMS connection mysql_close($connection); ?> </form> </body> </html> Code: [Select] for ($i = 1; $i<$rows+1; $i++) { $Choicequery ="SELECT PersonA, PersonB FROM modules WHERE GroupID = '$UpdateNumber'"; $Choiceresult = mysql_query($Choicequery); $ChoiceRows = mysql_fetch_array($Choiceresult); $PersonQuery = "SELECT FirstName, LastName FROM Persons p, modules m, users e, group t WHERE m.modID = $ChoiceRows[0] AND e.UserID = m.PersonA AND p.PersonID = e.PersonID"; $PersonResult = mysql_query($PersonQuery); $PersonRows = mysql_fetch_array($PersonResult); $Person2Query = "SELECT FirstName, LastName FROM Persons p, modules m, users e, group t WHERE m.modID = $ChoiceRows[0] AND e.UserID = m.PersonB AND p.PersonID = e.PersonID"; $Person2Result = mysql_query($Person2Query); $Person2Rows = mysql_fetch_array($Person2Result); echo "<Option value = \"$i\">$PersonRows[0] $PersonRows[1] and $Person2Rows[0] $Person2Rows[1] </Option>"; } How do I get it to show the next result when $i increases? All the options are the first people A and B $i number of times. Not sure how to use a loop here to go though the results. Whats the best way? ie $PersonRows[0] $PersonRows[1] are the same for every option Hi guys, I would like to display data from MySQL in the format of 5 lists (of one column each) one next to each other on a webpage I am quite good with SQL, but I lack knowledge about php and displaying data. SQL version: 5.1 Does anyone have any good website that would show how to do such a thing? friend the code display all the managers name
<?phpand the variable below displays the result $Manager= $row['Manager'] ; but how do i do it on the above dropdown list the it shows which result is in the $Manager variable? This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=331067.0 Here is my HTML code: Code: [Select] <html> <head> <title>Simple Search Form</title> </head> <body> <form name="searchform" method="get" action="/search.php"> Select Gender: <select name="gender"> <option value="Male">Male</option> <option value="Female">Female</option> </select> Select City: <select name="gender"> <option value="all">All Cities</option> <option value="newyork">New York</option> <option value="toronto">Toronto</option> <option value="london">London</option> <option value="paris">Paris</option> </select> <form> </body> </html> Here is my PHP code: <?php // get the data from the search form # get the gender (male or female) $gender = $_GET['gender']; # get the city $city = $_GET['city']; // connect to mysql and select db mysql_connect('localhost', 'root', 'pass') or die(mysql_error()); mysql_select_db($test_db); // send query $query = mysql_query("SELECT * FROM `visitors_location` WHERE gender='$gender' AND city='$city'"); $count = mysql_num_rows($query); // display data while ( $show = mysql_fetch_assoc($query) ) { echo $gender . " " . $city; } ?> My script basically shows # of males or females in a specific city. How can I show all males in all cities? In other words, let's say I want to show # of Females from all those 4 cities combined. I don't know how to do that. Can someone please help me? Hello Friends!.... here is the big idea. I am trying to make a form in which there will be 2 drop down lists which will be populating directly from MySQL DB .... Actually i am developing a student management system as my first PHP project... here i want to have 2 drop down lists first is roll number and second is student name. i want that when some one select the roll number in the first drop down the student name against it is automatically populated in the next drop down. please help me friends i am new to php and dont know soo much.! any help PLZZZZZZZZZZ Hi i got a search form and when im searhing for result i get nothing. i got 5 search fields : 1. Erea 2. category 3. subcategory 4. from price 5. to price if im not specifieing from price and to price i get blank result ,if i do specify the from price to price ,then i get the results. this is the code im using to get the results. Code: [Select] $sql=mysql_query("select * from posts where erea = '$erea' and category = '$category' and sub_category = '$subcategory' and price >= '$fromprice' and price <= '$toprice'"); what i want is to get the result even if i didnt specify the price from, to . thanx i have two tables, and i want to display data from the most recent entry of the two(i.e. display just one entry). i'm joining together 2 tables so that i can get this entry.Both tables contain the date, so i'm ordering the results of the query so that the most recent comes first. My tables a TOPIC topic_id topic _name section_sub_id date POST post_id post_name section_sub_id date I'm using the following code to get the last result, but nothing is being echoed $join =mysql_query("SELECT topic.*, post.* FROM topic LEFT JOIN post ON topic.section_sub_id=post.section_sub_id WHERE post.section_sub_id = " .$row2['section_sub_id']. " ORDER BY topic.date") or die("Select Error :" . mysql_error()); $latest= mysql_fetch_row($join); echo $latest['post.date']; i'm not sure if there is something wrong with the sql, or with the php. ANy help would be great Hi, I would like to ask, how to display the while loop result 3 per row with the following code below: $startDate = strtotime($datefrom); Hi there (I'm new at PHP/mysql) I am busy with a project - I maneged to load info into the mysql database and display the results BUT - now I need some Help I can display the result - now I want to have the ability to click on the result and it must open a new page with only the selected result information? |