Jump to content

Query String Help / Ideas?


wmguk

Recommended Posts

Hey guys,

 

I need to do a search page, I am looking for a page with 3 drop downs.

 

1) Display all orders from account [All, account1, account2 etc etc]

2) During the months of [Jan, Feb, Mar etc]

3) During the year of [2004, 2005, 2006]

 

but I want the drop down value to only show the details already in the database, (for the account name)

 

any thoughts how I should do this, I was shown a query using MySQL yesterday, rather than PHP, which is much quicker however what way would you do it, and any thoughts on any code would be great. I have seen self generating drop downs before, but have googled and cannot find anything.

 

Cheers in advance

Link to comment
Share on other sites

Hey, ok so i found the distinct !! however now I cant pull out the month or year from the datestamp

 

any thoughts?

 

<?
include "../scripts/connection.php"; 
if (!$conn) 
{ 
  die( 'Could not connect: ' . mysql_error() ); 
   }
mysql_select_db($db, $conn); 

$sql="SELECT DISTINCT (loginid), albumname FROM orders";
$sql2="SELECT DISTINCT *, MONTH(orderdate) AS month FROM orders";
$sql3="SELECT DISTINCT *, YEAR(orderdate) AS year FROM orders"; 
$result=mysql_query($sql); 
$result2=mysql_query($sql2); 
$result3=mysql_query($sql3); 

//ALBUMS
$options="";
while ($row=mysql_fetch_array($result)) { 
    $id=$row["loginid"]; 
    $thing=$row["albumname"]; 
    $options.="<OPTION VALUE=\"$id\">".$thing.'</option>';
} 

//MONTHS
$options2=""; 
while ($row=mysql_fetch_array($result2)) { 
    $id2=$row["month"]; 
    $thing2=$row["month"]; 
    $options2.="<OPTION VALUE=\"$id2\">".$thing2.'</option>';
}

//YEARS
$options3=""; 
while ($row=mysql_fetch_array($result3)) { 
$id3=$row["year"]; 
    $thing3=$row["year"]; 
    $options3.="<OPTION VALUE=\"$id3\">".$thing3.'</option>';
}
?> 
<form action="" class="main" name="searchtype">

<SELECT NAME="album" id="album" class="main">
  <option value="All Your Albums">All Your Albums
  <?=$options;?> 
  </SELECT>
<br />

<SELECT NAME="month" id="month" class="main"> 
<OPTION VALUE=0>All Months
<?=$options2;?> 
</SELECT>
<br />

<SELECT NAME="year" id="year" class="main"> 
<OPTION VALUE=0>All Years
<?=$options3;?> 
</SELECT>

</FORM>

Link to comment
Share on other sites

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.