/    Sign up×
Community /Pin to ProfileBookmark

Fetching data from foreign table mysql to HTML dropdownlist

Hi,

I am trying to find out how to update my catgor table (which is the second table in my first table(update form)). catgor table has to columns of cat_id (primary key) and catgory(such as good, bad).
When the client update the updateform, the first table has cat_id as a foreign key in it.
My below code works perfectly to read the info (good or bad) from the table however my only concern is that instead of showing good or bad option in my dropdown it shows the completed list with word selected good or selected bad. I would like to have a sticky dropdown for the update form which shows only good, bad or select (in case the client didn’t choose any of them) and then customer do the modification if required. Please advise how I can achieve it?

Thanks,
Saba

<p>
<label for=”cat_id”>Condition:</label>
<select name=”cat_id” id=”cat_id”>
<option value=””>Select Condition</option>
<?php
// get categories
$getCat = ‘SELECT * FROM categor’;
$cats = $conn->query($getCat);
while ($row = $cats->fetch_assoc()) {
$selection = $row[‘cat_id’];
?>
<option value=”<?php echo $row[cat_id’]; ?>”>
<?php
if ($row[‘cat_id’] == $cat_id) {
echo ‘selected’;
}
?>
<?php

echo $row[‘category’]; ?></option>
<?php } ?>

</select>
</p>

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@sean26Jul 28.2015 — Hello Saba ,

We gone through your requirement and we would be happy to assist you .

BR

Sean

Skype:cisin.sean
×

Success!

Help @Saba2015 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,
)...