Page 1 of 1

Problem with </select> using PHP?

Posted: Thu Oct 13, 2005 2:26 pm
by mmc01ms
Im trying to get list of options from a database into a select statment so the user can select one and nothing appears in my dropdown menu. the database is fine and the query is fine so im not usre what it is anyone help?

Code: Select all

<?php
require('database.class.php');

    class admin
    {

        function get_meetings()
        {
            $database = new database();
            $link_id = $database->database_connection();
            $query = 'select event, meetingid from epc_meetings';
            
            $result = @mysql_query($query, $link_id);
            if (!$result)
                return false;
            $num_meetings = @mysql_num_rows($result);
            if($num_meetings == 0)
                return false;
            
            $result = db_result_to_array($result);
            return $result;
            
        }
        
        function db_result_to_array($result)    
        {
            $res_array = array();
            for ($count=0; $row = @mysql_fetch_array($result); $count++)  
                $res_array[$count] = $row;                
            return $res_array;   
        }
    }
        

?>

Code: Select all

<?php //  ini_set ('display_errors', true );
require_once('../../spaw/spaw_control.class.php');
require_once('../../../classes/admin.class.php'); ?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>EPC Website Administration: Presentation</title>
<link href="../../../css/epc_admin.css" rel="stylesheet" type="text/css" />
<script language="JavaScript" type="text/JavaScript">
<!--
function BRB_PHP_DelWithCon(deletepage_url,field_name,field_value,messagetext) { //v1.0 - Deletes a record with confirmation
  if (confirm(messagetext)==1){
      location.href = eval('\"'+deletepage_url+'?'+field_name+'='+field_value+'\"');
  }
}
//-->
</script>
<script src="../../../includes/sorttable.js"></script>
</head>

<body>
<div id="heading">
<h1><a href="../../index.php">Website Adminstration</a>: Upload Presentations </h1>
<img src="../../../images/!genric/epc2.jpg" width="305" height="54" />
<div class="clear"></div>
</div>

<div id="main">
<p>[<a href="../index.php">Meeting Entries</a>]</p>
<form method="post" action="add.php" enctype="multipart/form-data">
<table border="0" cellpadding="0" cellspacing="0" class="editform" id="diary">
    
    <tr>
       <th scope="row">Meeting</th>
      <td><select name="meetingid">
        <?php
        $x = new admin();
        $meeting = $x->get_meetings();
        $meeting_array=$meeting;
        foreach ($meeting_array as $thismeeting)
        {
            echo '<option value="';
            echo $thismeeting['meetingid'];
            echo '"';
            echo '>';
            echo $thismeeting['event'];
            echo'</option>';
            echo"\n";
        }
        ?>
    </select></td>
    </tr>
    <tr>
      <th scope="row">Title:</th>
      <td><input type="text" name="event" id="event" size="50" maxlength="100" /></td>
    </tr>
    <tr>
      <th scope="row">Author</th>
      <td><input type="text" name="location" id="location" size="50" maxlength="120"/></td>
    </tr>
    <tr>
       <th scope="row">File</th>
      <td><input type="text" name="year" id="year" size="50" maxlength="40"/></td>
    </tr>
    <tr>
      <th scope="row">&nbsp;</th>
      <td><input name="Submit" type="submit" title="Sumbit" value="Save"/></td>
    </tr>
</table>
</form>
<p>&nbsp;</p>
</div>
</body>
</html>

Posted: Thu Oct 13, 2005 2:28 pm
by chrys
That's some whack coding... I have a function that makes a dropdown from an array.

Code: Select all

//-----
// Function: make_dropdown( string $name, array $stuff )
// Paramaters:
//              string $name - the name of the dropdown
//              array $stuff - an array of things to be put in a dropdown
//              mixed $match - value to be selected
//              int $size - size of the select
//              bool $multiple - whether or not it's a multiple select
//
// Returns:  string (HTML)
// Purpose:  To create an HTML dropdown abstraction
//-----

function make_dropdown( $name, $stuff, $match=-1, $size=1, $multiple=false )
{
  $dropdown = "<select name=\"$name\" size=\"$size\" ";
  if( $multiple )
  	$dropdown .= " multiple ";
  $dropdown .= ">";

  while( list( $value, $text ) = each( $stuff ) )
  {
		if( $value == $match || ( is_array($match) && in_array( $value, $match )) )
		  $dropdown.= "<option value=\"$value\" selected>$text</option>";
		else
		  $dropdown.= "<option value=\"$value\">$text</option>";
	
  }

  return $dropdown . "</select>";
}

Code: Select all

// Grab the stuff from the DB
   $sql = "SELECT id, name FROM database";
   $result = mysql_query($sql );

   while( $row = mysql_fetch_row($result) )
      $thearray[$row[0]] = $row[1];

   $dropdown = make_dropdown( "dropdown_name", $thearray );