Re: [PHP] html form question

2001-07-26 Thread Lenar

 Funny you should ask - just done it myself:

Why you use mysql_result function?

This can be done a bit simpler way (and more effective):

?php
mysql_connect(db, $user, $password);
$result = mysql_query( SELECT eventName FROM $table);
while(list($event) = mysql_fetch_row($result))
echo option$event/option\n;
?

Lenar


 ?php
   $table=shoots;
   require (connect.php4);
   $result=MYSQL_QUERY( SELECT eventName FROM $table);
   $num_rows = mysql_num_rows($result);

   for ($i=0;$i$num_rows;$i++)
   {
   echo option;
   echo mysql_result($result,$i,eventName);
   echo /option;
   }


   MYSQL_CLOSE();
 ?

 - seb



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] html form question

2001-07-26 Thread Seb Frost

Thanks for that!  I was just using the same structure as I found in a code
sample somewhere.

- seb

-Original Message-
From: Lenar [mailto:[EMAIL PROTECTED]]
Sent: 26 July 2001 13:16
To: [EMAIL PROTECTED]
Subject: Re: [PHP] html form question


 Funny you should ask - just done it myself:

Why you use mysql_result function?

This can be done a bit simpler way (and more effective):

?php
mysql_connect(db, $user, $password);
$result = mysql_query( SELECT eventName FROM $table);
while(list($event) = mysql_fetch_row($result))
echo option$event/option\n;
?

Lenar


 ?php
   $table=shoots;
   require (connect.php4);
   $result=MYSQL_QUERY( SELECT eventName FROM $table);
   $num_rows = mysql_num_rows($result);

   for ($i=0;$i$num_rows;$i++)
   {
   echo option;
   echo mysql_result($result,$i,eventName);
   echo /option;
   }


   MYSQL_CLOSE();
 ?

 - seb



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] html form question

2001-07-26 Thread Seb Frost

OK so how would that look if I'd done SELECT * instead of SELECT eventName?
I'm guessing I have two nested while loops then?

I'm guessing something like this.?  Or is it not possible and I have to
go back to mysql_result?

?php
mysql_connect(db, $user, $password);
$result = mysql_query( SELECT * FROM $table);

while(list($field) = mysql_fetch_column($result))
{
  while(list($value) = mysql_fetch_row($result))
echo option$value/option\n;
}
?

- seb

-Original Message-
From: Lenar [mailto:[EMAIL PROTECTED]]
Sent: 26 July 2001 13:16
To: [EMAIL PROTECTED]
Subject: Re: [PHP] html form question


 Funny you should ask - just done it myself:

Why you use mysql_result function?

This can be done a bit simpler way (and more effective):

?php
mysql_connect(db, $user, $password);
$result = mysql_query( SELECT eventName FROM $table);
while(list($event) = mysql_fetch_row($result))
echo option$event/option\n;
?

Lenar


 ?php
   $table=shoots;
   require (connect.php4);
   $result=MYSQL_QUERY( SELECT eventName FROM $table);
   $num_rows = mysql_num_rows($result);

   for ($i=0;$i$num_rows;$i++)
   {
   echo option;
   echo mysql_result($result,$i,eventName);
   echo /option;
   }


   MYSQL_CLOSE();
 ?

 - seb



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] html form question

2001-07-26 Thread Lenar Lhmus



On Thu, 26 Jul 2001, Seb Frost wrote:

 OK so how would that look if I'd done SELECT * instead of SELECT eventName?
 I'm guessing I have two nested while loops then?
 
 I'm guessing something like this.?  Or is it not possible and I have to
 go back to mysql_result?

Nope, instead you can do smething like this:

?php
mysql_connect(db, $user, $password);
$result = mysql_query( SELECT * FROM $table);
while($row = mysql_fetch_assoc($result))
  while(list($colname, $colval) = each($row))
echo option value=\$colname\$colval/option\n;
?

Lenar

 
 ?php
 mysql_connect(db, $user, $password);
 $result = mysql_query( SELECT * FROM $table);
 
 while(list($field) = mysql_fetch_column($result))
 {
 while(list($value) = mysql_fetch_row($result))
 echo option$value/option\n;
 }
 ?
 
 - seb
 
 -Original Message-
 From: Lenar [mailto:[EMAIL PROTECTED]]
 Sent: 26 July 2001 13:16
 To: [EMAIL PROTECTED]
 Subject: Re: [PHP] html form question
 
 
  Funny you should ask - just done it myself:
 
 Why you use mysql_result function?
 
 This can be done a bit simpler way (and more effective):
 
 ?php
 mysql_connect(db, $user, $password);
 $result = mysql_query( SELECT eventName FROM $table);
 while(list($event) = mysql_fetch_row($result))
 echo option$event/option\n;
 ?
 
 Lenar
 
 
  ?php
$table=shoots;
require (connect.php4);
$result=MYSQL_QUERY( SELECT eventName FROM $table);
$num_rows = mysql_num_rows($result);
 
for ($i=0;$i$num_rows;$i++)
{
echo option;
echo mysql_result($result,$i,eventName);
echo /option;
}
 
 
MYSQL_CLOSE();
  ?
 
  - seb
 
 
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]
 
 
 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] html form question

2001-07-25 Thread Matt Greer



 What's the method for populating any number of html
 form option.../option tags with query results?
 I've seen lots of php-embedded examples for CHECKBOX,
 RADIO and even SELECT, but I can't seem to figure out
 how to create a simple drop-down menu. HELP!!!

Wouldn't it just be:

select name=menu
  option value=?php echo $firstoptionvalue; ??php echo
$firstoption; ?/option
  option value=?php echo $secoptionvalue; ??php echo
$secoption; ?/option
/select

If there's a varying number of options run a loop with arrays


select name=menu
?php
for ($i = 0; $i  $numoptions; $i++)
  echo option value='$optionvalue[$i]'$option[$i]/option
?
/select

Matt


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] html form question

2001-07-25 Thread Lawrence . Sheed

I use the following 

Looks a bit unwieldy to call, but does everything I need.

eg, say I have a table called foo with ID, Name

print OptionCreate (ID,returnID, foo order by Name, ,Name);

will create me a drop down


print OptionCreate (ID,returnID, foo order by Name, 1,Name);

will create me a drop down with item 1 selected.

Hope this helps.



//OptionName = field to list, passedname=option Select name
//tablename= table name , selected value = option select selected value if
found

//NOTE THAT THE DB open MUST have been already made in the calling
routine!!!
//eg$db = mysql_connect($db_domain, $db_user,$db_password);
//  mysql_select_db($db_databasename,$db);

function OptionCreate ($optionname,$passedname, $tablename,
$selectedvalue=,$optiontext=) {
if ($optiontext==)
$sqlstring = select $optionname from $tablename;
else 
$sqlstring = select $optionname, $optiontext from
$tablename;


global $db;
$result=mysql_query($sqlstring,$db);
$rows = mysql_num_rows ($result);

$tmpOut = select name=\$passedname\ size=1;   
for ($count=0;$count $rows; $count++) {
$tmpOut = $tmpOut . option value=\ .
MYSQL_RESULT($result,$count,$optionname) . \;

//Select item if passed variable is found
if ($selectedvalue ==
MYSQL_RESULT($result,$count,$optionname))
$tmpOut=$tmpOut . selected;
if ($optiontext==)
$tmpOut = $tmpOut .  .
MYSQL_RESULT($result,$count,$optionname) . /option;
else
$tmpOut = $tmpOut .  .
MYSQL_RESULT($result,$count,$optiontext) . /option;
}
$tmpOut = $tmpOut . /select;
return ($tmpOut);
}

-Original Message-
From: David Robley [mailto:[EMAIL PROTECTED]]
Sent: July 26, 2001 9:02 AM
To: CGI GUY; [EMAIL PROTECTED]
Subject: Re: [PHP] html form question


On Thu, 26 Jul 2001 10:27, CGI GUY wrote:
 What's the method for populating any number of html
 form option.../option tags with query results?
 I've seen lots of php-embedded examples for CHECKBOX,
 RADIO and even SELECT, but I can't seem to figure out
 how to create a simple drop-down menu. HELP!!!

You only need to loop through the query result in the usual fashion and 
echo the results within option tags. Here's a function I wrote to to 
useful things with SELECT:

?php
/* formDropDown - create an HTML SELECT
 * vars: $name - the form variable NAME
 *   $value - the SELECTED option which may be an array for multiple 
selected items
 *   $labels - assoc. array, list of values=labels
 *   $multiple - if non-empty, select multiple
 * $size - number of rows to show if multiple
 * returns: string, HTML (i.e. for use in echo or print statement) */
function formDropDown($name,$value,$labels,$multiple = '',$size ='') {
  $html = 'SELECT NAME=' .$name . '';
if(!empty($multiple)) {
$html .= ' MULTIPLE';
}
if(!empty($size)) {
$html .= ' SIZE=' . $size;
}

  $html .= \n;
  $key = key($labels);
  while($key != ) {
/* Check if the current value is in the $value variable */
if(is_array($value)) {
  if(in_array($key,$value)) {
$selected = ' SELECTED';
  } else {
$selected = '';
  }
} else {
  if ($key == $value) {
$selected = ' SELECTED';
  } else {
$selected = '';
  }
}
$html .= OPTION VALUE=\$key\$selected$labels[$key]\n;
next($labels);
$key = key($labels);
  }
  $html .= /SELECT\n;
  return $html;
}
?
4ÈÑ4

-- 
David Robley  Techno-JoaT, Web Maintainer, Mail List Admin, etc
CENTRE FOR INJURY STUDIES  Flinders University, SOUTH AUSTRALIA  

   Why build a wall round a cemetery when no-one wants to get in?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] html form question

2001-07-25 Thread Seb Frost

Funny you should ask - just done it myself:

?php
$table=shoots;
require (connect.php4);
$result=MYSQL_QUERY( SELECT eventName FROM $table);
$num_rows = mysql_num_rows($result); 

for ($i=0;$i$num_rows;$i++)
{
echo option;
echo mysql_result($result,$i,eventName);
echo /option;
}


MYSQL_CLOSE();
?

- seb

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]