Reply to Re: select box

Your name:

Reply:


Posted by Peter revera on 01/11/07 15:03

On Thu, 11 Jan 2007 14:51:41 -0000, "MS" <MS@nospam.com> wrote:

>> HI there.
>>
>> Ive got a quick question.
>>
>> How do I have a select box show a particular value.
>>
>> Same as a previous post but I dont think it got answered
>>
>
>I use the following function....
>
>// $name = the field name
>// $type = "selection" || "checkbox" || "radio", the type of field you want
>to display the data in.
>// $class = the class to use
>// $listarray = array("id","value")
>// $selected = Which item is selected within the list in the format
>"int,int,int" for radio and in the format "int" for selection & checkbox
>
>// So just by changing the $type in the calling function you can have the
>data displayed in 3 ways.
>
>function getFormInput($name,$type,$class,$listarray,$selected=""){
> $res = "";
> if($type == "selection"){
> $res .= "<select name='".$name."' class='".$class."'>\n";
> for ($i=0;$i <= count($listarray);$i++) {
> $sel = ($selected == $listarray[$i]['id']? " selected" : "");
> $res .= "<option
>value='".$listarray[$i]['id']."'$sel>".$listarray[$i]['name']."</option>\n";
> }
> $res .= "</select>\n";
> }elseif($type == "checkbox"){
> $selsplit = explode(',',$selected);
> for ($i=1;$i <= count($listarray);$i++) {
> $sel = (in_array($listarray[$i]['id'],$selsplit)? " checked" : "");
> $res .= "<input type='checkbox' name='".$name."[".$i."]'
>
>value='".$listarray[$i]['id']."'$sel>".$listarray[$i]['name']."<br>\n";
> }
> }elseif($type == "radio"){
> for ($i=1;$i <= count($listarray);$i++){
> $sel = ($listarray[$i]['id'] == $selected) ? " checked" : "";
> $res .= "<input type='radio' name='".$name."'
>
>value='".$listarray[$i]['id']."'$sel>".$listarray[$i]['name']."<br>\n";
> }
> }
> return $res;
>}
>
>
>Hope that helps
>
>MS
>Join MyClubWeb.co.uk - The Home of Club Websites and Medium to Small
>Businesses.


Thanks for the response.
Bit confused.

This is the code I currently have which gets me the info from the db.

$get = "SELECT * FROM categories";
$answer = mysql_query($get)
or die ("Couldn't execute query.");

echo "<select name=listid' class='gradientform'>\n";
while ($row = mysql_fetch_array($answer))
{
extract($row);
echo "<option value='$itemid'>$item\n";
}
echo "</select>\n";

But I would like to do is based on having the itemID value passed via
URL I would like to get the matching listid vallue selected.

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация