Jump to content

Recommended Posts

Hi there,

 

Im looking to create a drop down that's options display how a user will view the records by.

 

 

e.g. View By: Dropdown options (Price, date, ID)

 

So then the user can select how they would like to view the records via the drop down...instead of using exisiting hyperlinks.

 

Ultimately i would like to have just a single page for all View by options...so im thinking i will need to have some kind of IF ELSE staement to detemine how to view the record....

 

Im not really sure where to begin here (although i do pick it up quite quickly), if anybody could give me some advice and help that would be brilliant!!

 

Thank You :)

Link to comment
https://forums.phpfreaks.com/topic/91968-view-records-by-drop-down-options/
Share on other sites

HHmmm im not really sure i follow you....perhaps i dont pick it up that quick :)

 

i tried creating it with a submit button and got this far ......

 

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<form id="form1" name="form1" method="post" action="view.php?recordID_id=<?php echo $row_Animal['AnimalID']; ?>">
<p>View By:
<select name="Animal" id="AnimalID">
<option value="">select</option>
<?php
do {
?>
<option value="<?php echo $row_Animal['AnimalID']?>"><?php echo $row_Animal['AnimalType']?></option>
<?php
} while ($row_Animal = mysql_fetch_assoc($Animal));
$rows = mysql_num_rows($Animal);
if($rows > 0) {
mysql_data_seek($Animal, 0);
$row_Animal = mysql_fetch_assoc($Animal);
}
?>
</select>
</p>
<p>
<input type="submit" name="Submit2" value="Submit" />
</p>
</form>

<p></p>
</body>
</html>

 

 

This is suppose to be working....According to coder..so im little confused...

 

Thanks

Hmm im not entirely sure what your trying to do (the replies confused me) sooo here it goes....

 

Okay im thinking that your trying to make a select box from which the user can select different ways to view results...

 

heres my way....

 

<select name=orderby>
<option value="-">Select one...</option>
<option value="date" onclick="window.location='?orderby=date';">Date</option>
<option value="price" onclick="window.location='?orderby=price';">Price</option>
<option value="id" onclick="window.location='?orderby=id';">ID</option>
</select>

<?
if (isset($_GET['orderby']){ $orderby= $_GET['orderby']; }else{ $orderby="date"; }
//CHECKING TO SEE IF THE PERSON HAS CHOSEN TO ORDER BY A CERTAIN FIELD

$sql= mysql_query("SELECT * FROM table ORDER BY $orderby DESC");
//SQL QUERY CAN BE MODIFIED EVEN MORE

//WHATEVER ELSE YOU WANT
?>

 

Hope that helps. I tested on my own server it works.

Hello,

 

Ive tried the code and am wondering...Does it require a Submit button for it to work????

 

Becaus at present the options are listed the drop down but nothing happens when selecting an order by option.

 

If so, is it possiblle to do make the options in the drop down so they are hyperlinked???

 

Thanks :)

I think you might also look at using a switch statement.  With the switch statement you could set a default view.

 

switch ($view)
{
case 'view 1':
echo ' ....';
break;
case 'view 2':
echo ' ....';
break;
default:
echo 'default view';
}

 

but you will have to set the view variable first.

 

Hi,

 

I slightly added to the select query and to give me the following:

 

<?
if (isset($_GET['orderby']){ 
$orderby= $_GET['orderby']; 
}else{ $orderby="AnimalID"; }
//CHECKING TO SEE IF THE PERSON HAS CHOSEN TO ORDER BY A CERTAIN FIELD

$sql= mysql_query("SELECT * FROM animal ORDER BY $orderby DESC");
$sql = mysql_query($query_sql, $woodside) or die(mysql_error());
$row_sql = mysql_fetch_assoc($sql);
$totalRows_sql = mysql_num_rows($sql);

?>

 

At the moment when selecting a drop down option nothing happens...

 

i notice that in the browser it says "http://localhost/woodside/index.php?orderby=Name" So it kind of looks like it works...

 

It doesnt work in IE at all, but only in Firefox....I think it has something to do with the <?....should i be using <?php instead???

 

When i try to make this change i get an erro message saying : Parse error: syntax error, unexpected '{' in C:\wamp\www\Woodside\index.php on line 244

 

I have then tried to  echo the query to see if it works by:

<?php echo $row_sql['AnimalID']; ?>

 

No results are dislpayed at all??

 

If anybody can please please help me id be so happy :)

 

Thank You

Hi again :)

 

Trying to order the record by drop down options but it says: It says "the query is empty"....???

 

<head>
</head>

<body>
<?php
if (isset($_GET['orderby'])) { 
$orderby= $_GET['orderby']; 
}else{ $orderby="AnimalID"; }

?>
       <select name=orderby>
<option value="-">Select one...</option>
<option value="ID" onclick="window.location='?orderby=AnimalID';">ID</option>
<option value="name" onclick="window.location='test8.php?orderby=Name';">Name</option>
<option value="animaltype" onclick="window.location='test8.php?orderby=AnimalTypeID';">Animal Type</option>
</select>
<?php
$test= mysql_query("SELECT * FROM animal ORDER BY $orderby DESC");
$test = mysql_query($query_test, $woodside) or die(mysql_error());
$row_test = mysql_fetch_assoc($test);
$totalRows_test = mysql_num_rows($test);
?>
<?php echo $row_test['AnimalID']; ?>
</body>
</html>

 

 

 

 

Please anybody?? why is it not working? :(

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.