PHP - Problem With "sort By" Dropdown Menu?
Ok i'm trying to make a dropdown menu to sort content on my site.
The dropdown looks like this: Code: [Select] <select> <option selected="selected">Date</option> <option>Clicks</option> <option>Ratings</option> <option>Comments</option> </select> The content that the dropdown needs to sort are taken from my MySQL database and put on the site using these lines of code: (there is alot more code to do other stuff aswell, but that isn't importand for my problem) $sql = "SELECT * FROM links LIMIT $offset, $rowsperpage"; $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR); $dyn_table = '<table class="main_table">'; while ($row = mysql_fetch_assoc($result)) { etc... The dropdown and the php script that inserts the content on the page are (and needs to be) in two seperate files. So how can i make so that when a user selects "Sort by: Clicks" for example, the page refresh and maybe inserts "ORDER BY clicks ASC" into "$sql = "SELECT * FROM links LIMIT $offset, $rowsperpage";"or something?? I'm really open for ideas here, Javascript and jQuery is also welcome if it needs to be used! Similar TutorialsCan 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 have a registration form on my website and after Registration I want the user to activate first his account. I don't have problem on sending this email to the user. What I want to appear is like this.. GoodDay "username", Blah Blah! how can you actually do that? I know that you can do that through session variables but the thing is email's can't accept scripts on sending emails. how can I get the value from a session variable for example and convert it to plain html text so that i can OUTPUT it to the email.. HELP PLEASE! Hi, bit stuck on how to find and replace "<" and ">" with "<" and ">". I basically have a database record that outputs to screen and I need the code in the <code> tags to be rendered to the screen. I therefore need it to go through the whole array variable from the db and change the symbols just inside the code tags. Please be aware that the code tags might happen more than once here's an example below Code: [Select] <p>blah blah blah</p> <p>blah blah blah</p> <p>blah blah blah</p> <code> <h1>hello</h1> </code> <p>blah blah blah</p> <p>blah blah blah</p> <p>blah blah blah</p> <code> <h1>hello</h1> </code> the desired output would be: <p>blah blah blah</p> <p>blah blah blah</p> <p>blah blah blah</p> <code> <h1>hello</h1 </code> <p>blah blah blah</p> <p>blah blah blah</p> <p>blah blah blah</p> <code> <h1>hello</h1 </code> help on this would be great Cheers Rob I am trying to replicate a "Sort By" selection exactly like how Freelancer has it here https://www.freelancer.com/search/projects/ Sort by - Oldest - Newest - Lowest Price - Highest Price - Lowest Bid - Highest Bid So far I was only able to do the sort by oldest and newest. Here is my code. This shows my code for the page to retrieve records and use pagination to split them. My Tables: 1. Projects (project_id, title, description, min_budget, max_budget, posted_date, expired_date, status) 2. Bids (bid_id, project_id, details, posted_date, b_status) 3. Images (image_id, project_id, user_id, image_path, posted_date) 4. Currency (currency_id, currency_name) 5. Users (user_id, username)
As you can see the setup I have works only for sorting by DESC and ASC, which is used for Oldest and Newest. Now I would like to know how I can do the same thing for lowest price, highest price using the same query. Lowest and Highest Bid have a separate table. i was wondering if that could also be sorted in the same query as well? <div id="sort-by-wrap"> <select id="sort-select" onchange="if(this.value != '') document.location = 'explore-projects?p=3&c1=<?php echo $url_c1; ?>&category=<?php echo $url_category; ?>&name=<?php echo $url_name; ?>&sort_by=' + this.value"> <option value="DESC"<?php if(isset($_GET['sort_by']) && $_GET['sort_by'] == 'DESC') {echo 'selected="selected"';} ?>>Newest</option> <option value="ASC"<?php if(isset($_GET['sort_by']) && $_GET['sort_by'] == 'ASC') {echo 'selected="selected"';} ?>>Oldest</option> </select> <div id="sort-txt">Sort by:</div> </div> <?php $url_category = trim(!empty($_GET['category']) ? $_GET['category'] : null); $url_name = trim(!empty($_GET['name']) ? $_GET['name'] : null); $url_sort_by = trim(!empty($_GET['sort_by']) ? $_GET['sort_by'] : null); $url_c1 = trim(!empty($_GET['c1']) ? $_GET['c1'] : null); $url_page_no = trim(!empty($_GET['page_no']) ? $_GET['page_no'] : null); $page_url = basename($_SERVER['REQUEST_URI']); $get_page_url = preg_replace('/[?&]page_no=\d+/', '', $page_url); if(!empty($url_page_no)) { $page_no = $url_page_no; } else { $page_no = 1; } $total_records_per_page = 10; $offset = ($page_no - 1) * $total_records_per_page; $previous_page = $page_no - 1; $next_page = $page_no + 1; $count_records = $db->prepare("SELECT COUNT(*) FROM projects WHERE category_id = :category_id AND publish = :publish"); $count_records->bindParam(':category_id', $url_category); $count_records->bindValue(':publish', 1); $count_records->execute(); $total_records = $count_records->fetchColumn(); $total_no_of_pages = ceil($total_records / $total_records_per_page); $second_last = $total_no_of_pages - 1; // total page minus 1 $find_records = $db->prepare("SELECT images.image_id, currency.currency_name, users.username, users.user_id, projects.* FROM projects LEFT JOIN images ON projects.project_id = images.project_id LEFT JOIN currency ON projects.currency_id = currency.currency_id LEFT JOIN users ON projects.user_id = users.user_id WHERE projects.category_id = :category_id AND projects.publish = :publish ORDER BY projects.project_id $url_sort_by LIMIT $offset, $total_records_per_page"); $find_records->bindParam(':category_id', $url_category); $find_records->bindValue(':publish', 1); $find_records->execute(); $result_records = $find_records->fetchAll(PDO::FETCH_ASSOC); if(count($result_records) > 0) { foreach($result_records as $row) { $project_id = $row['project_id']; $title = $row['title']; $description = $row['description']; $min_budget = $row['min_budget']); $max_budget = $row['max_budget']); $posted_date = $row['posted_date']; $expired_date = $row['expired_date']; $status = $row['status']; $image_id = $row['image_id']; $currency_name = $row['currency_name']; $user_id = $row['user_id']; $username = $row['username']; // COUNT TOTAL BIDS FOR EACH PROJECT $count_bids = $db->prepare("SELECT COUNT(*) FROM bids WHERE project_id = :project_id"); $count_bids->bindParam(':project_id', $project_id); $count_bids->execute(); $total_bids = $count_bids->fetchColumn(); // HTML CODE TO OUTPUT EACH PROJECT RESULT include '../snippets/record-box-wrap.php'; } } else { ?> <div id="no-content"> <span>No projects</span> </div> <?php } ?> <div class="pagination-wrap"> <div class="inner-pagination"> <ul> <li <?php if($page_no <= 1){ echo "class='disabled'"; } ?>> <a <?php if($page_no > 1){ echo "href='$get_page_url&page_no=$previous_page'"; } ?>>Prev</a> </li> <?php if($page_no <= 6) { for($counter = 1; $counter < 6; $counter++) { if ($counter == $page_no) { echo "<li class='active'><a>$counter</a></li>"; } else { echo "<li><a href='$get_page_url&page_no=$counter'>$counter</a></li>"; } } } else { for($counter = $total_no_of_pages - 6; $counter <= $total_no_of_pages; $counter++) { if($counter == $page_no) { echo "<li class='active'><a>$counter</a></li>"; } else { echo "<li><a href='$get_page_url&page_no=$counter'>$counter</a></li>"; } } } ?> <li <?php if($page_no >= $total_no_of_pages){ echo "class='disabled'"; } ?>> <a <?php if($page_no < $total_no_of_pages) { echo "href='$get_page_url&page_no=$next_page'"; } ?>>Next</a> </li> <?php if($page_no < $total_no_of_pages) { echo "<li><a href='$get_page_url&page_no=$total_no_of_pages'>Last ››</a></li>"; } ?> </ul> </div> </div>
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 Hi guys I am a newbie with PHP and I have been trying to solve this problem for 3 days.. Ive set up a booking form on my website to be sent directly to my email once the client clicked on the send button.. The problem I am having while checking these pages on wamp is that the booking form is ok but when I click on the send button the following message error appears "Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\wamp\www\fluffy_paws\booking_form2.php on line 27" When I check online I have this message "500 - Internal server error. There is a problem with the resource you are looking for, and it cannot be displayed." Are my codes wrong??? My webhosting is Blacknight.com , Im on Windows Vista, my internet is a dongle with O2 ireland Thanks for your help! Hi guys I'm struggling a bit, I need to replace a word that occurs multiple times in text with an array("up","down","forward","backwards") of words. $find = "left"; $replace = array("up","down","forward","backwards"); $text = "left left left left"; echo str_replace($find,$replace,$text); The Output is: array array array array Did try this with a foreach statement as well, but no luck. Is there a better way of doing this? Thanks cant work out this mysql syntax error "operation":"medupdate","medid":"","name":"ibo","medyear":"5","medmonth":"21","medday":"1","recuser":1,"SuccFail":"fail","SuccFailMessage":"error occured You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '''WHERE med_id=' at line 2","ResultData":""} Code: [Select] $sql="update metodology set med_description='".$req['name']."', med_year='".$req['medyear']."', med_month='".$req['medmonth']."', med_day='".$req['medday']."', med_recorddate= now(), med_recorduserid= 1'"; $sql.= " WHERE med_id=".$req['medid']; I am getting the following error when using composer: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? Just started. I am pretty sure composer.json wasn't changed. journalctl doesn't show anything. Maybe Doctrine related, however, nothing seems to help.
Any ideas? [michael@devserver www]$ php -v PHP 7.3.4 (cli) (built: Apr 2 2019 13:48:50) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.3.4, Copyright (c) 1998-2018 Zend Technologies with DBG v9.1.9, (C) 2000,2018, by Dmitri Dmitrienko [michael@devserver www]$ composer -V Composer version 1.4.2 2017-05-17 08:17:52 [michael@devserver www]$ yum info composer Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: mirror.us.oneandone.net * epel: mirror.rnet.missouri.edu * extras: mirror.us.oneandone.net * remi-php73: mirror.bebout.net * remi-safe: mirror.bebout.net * updates: mirror.us.oneandone.net Installed Packages Name : composer Arch : noarch Version : 1.8.4 Release : 1.el7 Size : 1.8 M Repo : installed From repo : epel Summary : Dependency Manager for PHP URL : https://getcomposer.org/ License : MIT Description : Composer helps you declare, manage and install dependencies of PHP projects, : ensuring you have the right stack everywhere. : : Documentation: https://getcomposer.org/doc/ [michael@devserver www]$ composer update Loading composer repositories with package information Updating dependencies (including require-dev) [ErrorException] "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? update [--prefer-source] [--prefer-dist] [--dry-run] [--dev] [--no-dev] [--lock] [--no-custom-installers] [--no-autoloader] [--no-scripts] [--no-progress] [--no-suggest] [--with-dependencies] [-v|vv|vvv|--verbose] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--apcu-autoloader] [--ignore-platform-reqs] [--prefer-stable] [--prefer-lowest] [-i|--interactive] [--root-reqs] [--] [<packages>]... [michael@devserver www]$
This topic has been moved to Linux. http://www.phpfreaks.com/forums/index.php?topic=318175.0 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've searched but can't seem to find anything I can apply to this situation. Most of the resources are dedicated to dropdown menu's from the same table. I have two tables 'regions' and 'cities' and I am looking to create a menu that lists all the cities within a region then moves on to do the same for the rest of the regions in that state: State1 Region1 City1 City2 City3 Region2 City1 City2 City3 Region3 Etc My tables: States table: stateID, state Regions table: regionID, region, stateID Cities table: cityID, city, regionID I currently have two pages- select region, then select city... I'd like to consolidate to one step after choosing a state. I know I need a nested loop, (while?), and to count the results somehow to retrigger loop; also not sure how to handle two mySQL querries in the nested loop. I'm having trouble wrapping my mind around it. Thank you. Hi, I currently have an if, elseif, else program that starts off with Code: [Select] if( $v_name == "" || $v_msg == "" ) echo "something" how do I turn this into a switch? but the very next elseif I have Code: [Select] elseif( strcspn( $_REQUEST['msg'], '0123456789' ) == strlen( $_REQUEST['msg'] ) ) echo "something" is it possible to turn this into a switch with 2 different strings like that to evaluate? This topic has been moved to PHP Installation & Configuration. http://www.phpfreaks.com/forums/index.php?topic=347922.0 Hi, First of all, this is not a spam. Someone with the username Pikachu2000 removed it thinking it was a spam so now I have to post it again. I really need you help fixing this problem. Anyway, I'm building a site where I used a "php include once" for the navigation menu. I was able to show the active pages when they don't have sub pages but I can't seem to show the active sub pages. I've been trying for days and nothing I try seems to work! I'm sure some people have asked this before but I can't find any forums that describe how to do this with sub navs rather then just the main nav buttons. The coding is below along with a link to one of the sub pages in the site I'm working on. The problem is with the sub pages under "Our Coffee Farm". Thanks for reading my post. Website Link: http://vanessajohodesigns.com/sarpa/the_farm/plantation.php before DOCTYPE: <?php $thisPage="The Plantation"; ?> after body tag: <?php include_once("../includes/nav.php");?> nav.php include once file: <div class="arrowsidemenu"> <div<?php if ($thisPage=="Home") echo " class=\"active\""; ?>> <a href="../index.php">Home</a></span></div> <div class="menuheaders"><a>Our Coffee Farm</a></div> <ul class="menucontents"> <li<?php if ($thisPage=="The Plantation") echo " class=\"active\""; ?>><a href="plantation.php">The Plantation</a></li> <li<?php if ($thisPage=="Blooming & Harvest") echo " class=\"active\""; ?>><a href="bloom_harvest.php">Blooming & Harvest</a></li> <li<?php if ($thisPage=="Coffee Processing") echo " class=\"active\""; ?>><a href="processing.php">Coffee Processing</a></li> </ul> <div<?php if ($thisPage=="About Us") echo " class=\"active\""; ?>> <a href="../about_us.php">About Us</a></div> <div<?php if ($thisPage=="Rainforest Alliance") echo " class=\"active\""; ?>> <a href="../rainforest_alliance.php">Rainforest Alliance</a></div> <div<?php if ($thisPage=="Social Commitment") echo " class=\"active\""; ?>> <a href="../social_commitment.php">Social Commitment</a></div> <div<?php if ($thisPage=="News & Events") echo " class=\"active\""; ?>> <a href="../news_events.php">News & Events</a></div> <div<?php if ($thisPage=="Web Cameras") echo " class=\"active\""; ?>> <a href="../webcams.php">Web Cameras</a></div> <div<?php if ($thisPage=="Photo Gallery") echo " class=\"active\""; ?>> <a href="../gallery.php">Photo Gallery</a></div> <div<?php if ($thisPage=="Contact Us") echo " class=\"active\""; ?>> <a href="../contact_us.php">Contact Us</a></div> <!--end .arrowsidemenu --></div> Hi, I need a clue on how to do a form with a "List/Menu" that when I choose one value on the "List" the page will reload and show that "List/Menu" and other new one. There are exemples on how to do this? Best Regards, hello, I was wondering what is the point of writing for a dropdown: <?php if ($_POST[inputfieldID] == "value") { echo "selected"; } ?> or for a checkbox/ radio button: <?php if ($_POST['cb/radioID'] == "value") { echo "checked"; } ?> I guess it's for after submit, if there is any error, the values filled will still be echoed in the inputfield, or am i wrong? But then if that is true, i have a php search box where i use AJAX object to to send all the input they filled in after submit. But after pushing submit the inputted values remain. I guess when using AJAX to send the information i don't need <?php if ($_POST[inputfieldID] == "value") { echo "selected"; } ?> in my html forms? Little confused Can maybe somebody bring clearness Hi all, Using a form with check boxes divided into different categories, I collect data selected by the user. I now want to combine each choice in each category with each choice in the other categories and list the combinations to the user. If the user chooses one or more options in each category, it is relatively easy to nest foreach loops, since the number of categories will always be the same. For example, if the form contains three categories of options, the code will be: Code: [Select] foreach ($form['cat_1'] as $k1 => $val1) { foreach ($form['cat_2'] as $k2 => $val2) { foreach ($form['cat_3'] as $k3 => $val3) { echo $val1.' _ '.$val2.' _ '.$val3.'<br/>'; } } } Things get complicated if the user does not select options within a given category. More generally, I want to be able to generate the list regardless of the number of categories in which the user selects options. Thank you in advance for your advice. Hey guys! I have the following doubt: I have a php file that does the following alongside with other code not displayed he $fp = fopen("emails.txt", "w"); It opens a txt file called emails.txt that is in the same folder where the php is saved but how do I tell $fp = fopen("/folderbefore/emails.txt", "w"); ?? In other words, how do I write the path on the script that the emails.txt is located in a previous folder where the php file is located?? Thanks in advance for your help Cheers! the array is getting the values as he should get and from there i send them to $temp (string),but when i'm trying to print them i can't. the array and the string at the end of code saved the values that the code gave them,but i can print the values one by one, but i need the values in string and the array at the end and print $temp(string) in a row without white space. print_r is working but she's not build to this job can someone look at the code and the result of the code and tell me what seem to be the problem and how to fix that? the problem start with $txt when the array is getting the values. the output of this code:http://pastebin.com/0QkzjviW the code page is attach to this message as php file. |