brown2005 Posted December 4, 2006 Share Posted December 4, 2006 Hi,I want a dropdown box<select> <option>All</option> <option>Random</option></select>if they select All then i want a query like$sql = "SELECT * FROM members";but if they select Random then...$sql = "SELECT RAND(*) FROM members"; or what ever... basically i want a dropdown to change a query automatically without refreshing..neideas please? Link to comment https://forums.phpfreaks.com/topic/29382-selecting-a-query/ Share on other sites More sharing options...
chiprivers Posted December 4, 2006 Share Posted December 4, 2006 The query is not going to run until on your next script so the query does not need to be built until you get to the next script. I would suggest you make the value of the options in the drop down equal to the variable part of the $sql query and you can then extract it from the the form results on the next script to build the full query.i.e.on form page:[code]<select name="search"><option value="*">All</option><option value="RAND(*)">Random</option></select[/code]on the next script you can do something like:[code]<?php$sql = "SELECT ".$_POST['search']." FROM members";?>[/code] Link to comment https://forums.phpfreaks.com/topic/29382-selecting-a-query/#findComment-134752 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.