You are here: Re: New problem for Newbie « PHP Programming Language « IT news, forums, messages
Re: New problem for Newbie

Posted by ZeldorBlat on 06/14/07 19:50

jsd219 wrote:
> On Jun 14, 12:31 pm, ZeldorBlat <zeldorb...@gmail.com> wrote:
> > On Jun 14, 12:23 pm, jsd219 <i...@musiclanerecording.com> wrote:
> >
> >
> >
> > > here is my code:
> >
> > > $query = "SELECT SEC_TITLE
> > > FROM section
> > > WHERE SEC_TITLE != ''";
> >
> > > $result = mysql_query($query);
> >
> > > echo "<form action='#'>\r\n<select name='section'>\r\n";
> > > while ($row = mysql_fetch_array($result, MYSQL_NUM))
> > > {
> > > echo " <option value='{$section[0]}'>$row[0]\r\n";
> >
> > > }
> >
> > > It works great but I need it to also select the ID from the section
> > > table without displaying it. so the client only sees a drop down box
> > > with the section titles but when they select one and send the form it
> > > will send both the section title and sec id
> >
> > > I have tried changing the SELECT SEC_TITLE to SELECT SEC_TITLE, SEC_ID
> > > but i am lost from there.
> >
> > > Anyone please :-)
> >
> > > God bless
> > > jason
> >
> > Change your query as you described above, then replace section[0] (not
> > sure what that was anyway) with row[1].
>
> Actually turns out the above code was not working properly. it needs
> to be this:
>
> $query = "SELECT SEC_TITLE
> FROM section
> WHERE SEC_TITLE != ''";
>
> $result = mysql_query($query);
>
> echo "<form action='#'>\r\n<select name=section>\r\n";
> while ($line = mysql_fetch_array($result, MYSQL_NUM)) {
> $section = $line[0];
>
> echo " <option value=$section>$section\r\n";
> }
>
> This allows the client to select a section from a dynamically
> generated drop down box, when they submit the form whatever section
> they selected get placed in the section field of the new row in the
> category table. i need the ids from the section table to be the same
> as the corresponding categories added. so if i create a section called
> Jack and it has an (auto increment) id of 1. And then i create a
> category called Jack's Pale by selecting Jack from my drop down box.
> My category table should populate a row with the CAT_TITLE=Jack's
> Pale, CAT_SECTION=Jack and CAT_ID=1
>
> Everything is working except i can not figure out how to grab the
> SEC_ID and send it along with the SEC_TITLE

You want the SEC_ID as the "value" attribute, and the SEC_TITLE
between the <option> tags. So, you're already got the SEC_TITLE out
into the variable called $section:

$section = $line[0];

So now you want the id:

$id = $line[1];

And you adjust your echo as follows:

echo "<option value=$id>$section\r\n";

And, BTW, you technically need (read: you should) have double quotes
around $id. So something like this:

echo "<option value=\"$id\">$section\r\n";

 

Navigation:

[Reply to this 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

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