/    Sign up×
Community /Pin to ProfileBookmark

hi guys i have a litter problem

i have the follwing table structure

[CODE]CREATE TABLE `survey_type` (
`type_id` int(10) unsigned NOT NULL auto_increment,
`type_name` varchar(45) NOT NULL default ”,
PRIMARY KEY (`type_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=5 ;[/CODE]

on a php page im trying to fill the combo with the type_name like that

[code=php]<select name=”survey” dir=”rtl”>
<?php
$data = get_survey_types_name();

foreach ($data as $survey)
{
echo “<option value=$survey>$survey</option>”;
}
?>
</select>[/code]

where get_survey_types_name() function is

[code=php]function get_survey_types_name()
{
db_connect();
$sql = “select type_name from survey_type”;
$result = mysql_query($sql) or die(mysql_error());

if (!$result)
return false ;

$poll_data = array();

for ($count=0 ; $row=mysql_fetch_array($result) ; $count++)
{
$poll_data[$count] = $row[0] ;

}

return $poll_data;
} [/code]

im was trying to retuen the type_id from the same function and place them as values for the options cuz later i’ll use that for updating the database..

any ideas how to do that ??

Regards,

Noor

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@sacx13Mar 29.2006 — Hi,

First we change your function in this way :

[CODE]

for ($count=0 ; $row=mysql_fetch_array($result) ; $count++)
{
$poll_data[$count] = $row[0]."|".row[1] ;

}
[/CODE]


Next we change the main code:

[CODE]

foreach ($data as $survey)
{
list($id,$name)=explode("|",$survey);
echo "<option value=$id>$name</option>";
}
[/CODE]


or you can use matrix arrays ?

$array[0][0]=id;

$array[0][1]=name;

$array[1][0]=id2;

$array[1][1]=name2;

etc

Regards

Adrian
Copy linkTweet thisAlerts:
@nooor83authorMar 29.2006 — thanx alot adirian i really appreciate it..
×

Success!

Help @nooor83 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...