sending information in a drop down menu

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
isabelle
Forum Newbie
Posts: 7
Joined: Mon Jan 17, 2005 2:12 pm

sending information in a drop down menu

Post by isabelle »

Hello,
I am having problems understanding how to pass information and receive it on another page. I am working on a series of drop down menus where one can search a record album by year, then label, then artist then album name. Here is what I have so far:
http://www.runreturn.com/winestore/ch06 ... e.6-8e.php
when you select a year, the labels producing records in that year appear and that works fine.
But when you submit on this page with the label you've selected, it shows you artists which produce anytime as long as it's on the label. I want it to, instead, show artists that are on the label selected who released an album during the year that was originally selected.
I am very new to PHP and am thankful for any help.

Here is the code for the page I am stuck on where it displays the artists:

Code: Select all

<?php

   // Connect to the server
  if (!($connection = @ mysql_connect($hostName, $username, $password)))
     showerror();

  if (!mysql_select_db($databaseName, $connection))
     showerror();
  
  // Show all wines in a region in a <table>
  function displayArtistList($connection,
                            $query,
                            $labelName)
  &#123;
     // Run the query on the server
     if (!($result = @ mysql_query ($query, $connection)))
        showerror();

     // Find out how many rows are available
     $rowsFound = @ mysql_num_rows($result);
     
     // If the query has results ...
     if ($rowsFound > 0)
     &#123;
 
	// ... print out a header

         print "Artists under the label $labelName in $yearName<br>". "<br>".  
         "<SELECT NAME=artists>";
         
        // Fetch each of the query rows
          $options="artists";
		 while ($row = @ mysql_fetch_array($result))
		 &#123;

			$id=$row&#1111;"id"];
			//adding $row&#1111;] allows for the options to show up
 			$artists=$row&#1111;"artist"];
 			//$options.="<OPTION VALUE="$result">".$label;
			$options=$artists;
            // Print one row of results
            
            print "<OPTION>$options</OPTION>";
 			
         &#125; // end while loop body
         
         

		
     &#125; // end if $rowsFound body

         print "</SELECT>" ."<br>" ."<br>" ;

     // Report how many rows were found
     print "\n" . "\n" ."&#123;$rowsFound&#125; artists found matching your criteria<br>";
  &#125; // end of function

  // Connect to the MySQL server
  if (!($connection = @ mysql_connect($hostName, $username, $password)))
     die("Could not connect");

  // Secure the user parameter $yearName
  $labelName = mysqlclean($_GET, "label", 30, $connection);
  
    // Secure the user parameter $yearName
  $yearName = mysqlclean($_GET, "yearName", 30, $connection);

  if (!mysql_select_db($databaseName, $connection))
     showerror();

  // Start a query ...
  $query = "SELECT DISTINCT artist
            FROM   brazil
            WHERE label = "&#123;$labelName&#125;"";

   // ... then, if the user has specified a year, add the yearName 
   // as an AND clause ...
   
    if (isset($yearName) && $yearName != "All")
     $query .= " AND year = "&#123;$yearName&#125;"";
   if (isset($labelName) && $labelName != "All")
     $query .= " AND label = "&#123;$labelName&#125;"";

   // ... and then complete the query.
   $query .= " ORDER BY artist";

   // run the query and show the results
   displayArtistList($connection, $query, $labelName) . "\n" ."\n";
  

?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

probably the simplest way is to toss the submitted year, or artist, or whatever into a hidden field in the form. Then make sure this data reaches the next page by simply looking for it. In your case, it looks like the information is passed via the $_GET superglobals..
isabelle
Forum Newbie
Posts: 7
Joined: Mon Jan 17, 2005 2:12 pm

Thank you!

Post by isabelle »

Your advice was exactly what I needed! Thank you so much!
Post Reply