Hi

I was wondering if someone could help me.
I have a dropdown list which is populated from MySQL. The dropdown data is classed as sections. When a user selects a section from the dropdown a form on the same page is populate with the section name and they are then able to edit the section name and click save.

Its quite simple but as I have minimal PHP and MySQL I was wondering if you guys could help.

Thanks in advance

do u want a linked drop down button or only want to edit the name selected in drop down ?????

do u want a linked drop down button or only want to edit the name selected in drop down ?????

It will be to edit whats in the drop down only. The drop down will be populated by the section table in MySQL

MySQL of Section:
section_id | Section_Name | slitingid

Results:
1233 | Home | 1
1234 | Work | 2
1235 | Away | 0
1236 | Holiday | 5

The dropdown would contain Section_Name

I hope that helps :)

Cheers

is this the output that you mean?

<select name="select">
<option value="">select option</option>
<option value="Home">Home</option>
<option value="Work">Work</option>
//and so on
</select>

if y then

//query from section table
$a = mysql_query("select Section_Name from Section");
echo '<select name="select">';
while($b = mysql_fetch_array($a)){
echo '<option value="'.$b['Section_Name'].'">'.$b['Section_Name'].'</option>';
}
echo '</select>';

this is to get drop down populated from mysql.....

<?php
$con=mysql_connect("localhost","root","")
or die("couldn't connect to mysql");
$db=mysql_select_db("abc",$con)
or die("database not found");
$result=mysql_query("SELECT name FROM aaa")
or die("query error");
echo "<select>";
while($r=mysql_fetch_array($result))
{
//echo $r['name'];
echo "<option value='".$r['name']."'>".$r['name']."</option>";
}
echo "</select>";
?>

now next part of ur problem will be done soon....i m a lil busy now...so will try it after some time....

this is to get drop down populated from mysql.....

<?php
$con=mysql_connect("localhost","root","")
or die("couldn't connect to mysql");
$db=mysql_select_db("abc",$con)
or die("database not found");
$result=mysql_query("SELECT name FROM aaa")
or die("query error");
echo "<select>";
while($r=mysql_fetch_array($result))
{
//echo $r['name'];
echo "<option value='".$r['name']."'>".$r['name']."</option>";
}
echo "</select>";
?>

now next part of ur problem will be done soon....i m a lil busy now...so will try it after some time....

Thanks so far! I appreciate your help

if i give u remaining code tomorrow...will it be ok....at present i m busy with my college stuff.....

if i give u remaining code tomorrow...will it be ok....at present i m busy with my college stuff.....

Not a problem at all. I am grateful for the help

if i give u remaining code tomorrow...will it be ok....at present i m busy with my college stuff.....

Hi Tomato, wondered if you had an update for me?

Cheers

sorry...i forgot ...wait i m preparing the one for u ...n just uploading it in this forum....

ok....ur work is done..here is the code i used...it was becoming conjusted in a page so i used second page although we can do it using a single page only....

HERE's UR CODE

1.php

<?php
$con=mysql_connect("localhost","root","")
or die("couldn't connect to mysql");
$db=mysql_select_db("abc",$con)
or die("database not found");
$result=mysql_query("SELECT name FROM aaa")
or die("query error");
echo "<form action='' method='GET'>";
echo "<select name='s'>";
while($r=mysql_fetch_array($result))
{
//echo $r['name'];
echo "<option value='".$r['name']."'>".$r['name']."</option>";
}
echo "</select>";
echo "<input type='submit' value='submit' name='submit'>";
echo "</form>";
if(isset($_GET['s']))
{echo "<form action='abc.php'>";
echo "<input type='text' value='".$_GET['s']."' name='a'>";
echo "<input type='submit' value='submit' name='submit'>";
echo "<input type='hidden' value='".$_GET['s']."' name='b'>";
echo "</form>";
}
?>

abc.php

<?php
$con=mysql_connect("localhost","root","")
or die("couldn't connect to mysql");
$db=mysql_select_db("abc",$con)
or die("database not found");
$result=mysql_query("UPDATE aaa SET name='".$_GET['a']."' where name='".$_GET['b']."'")
or die("query error");
header("Location:1.php");
?>

if it's useful...just respond positive to it....
and if ur problem is solved mark the thread solved and u can at any time PM me for any assisstance....

Member Avatar for diafol

I suggest using a ".=" to build the select options as opposed to echoing everything out:

$options ="";
while(...){
  $options .= "\t<option value=\"...\">...</option>\n";
}

The later on, you can insert it in general html. Otherwise creating a basic html file gets really messy with four million echoes!

<select id="..." name="...">
<?php echo $options;?>
<select>

Thanks guys
Really appreciate your work and time

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.