Jump to content

Selecting a query


brown2005

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.