You are here: Re: Populating <options> tag with SQL data? « PHP Programming Language « IT news, forums, messages
Re: Populating <options> tag with SQL data?

Posted by Ivαn Sαnchez Ortega on 05/03/07 15:32

cresh wrote:

> I can pull the data from the table using an array, no problems there.
> I can display the data, etc., just can't figure out how to put the
> data into a form <option> tag.
[...]
> Do you see what I'm trying to do now? I'm not sure if I'm making
> myself clear enough. $program[ ] is the variable to hold the
> information pulled from the database table.

In order to iterate through an array, do this:

<?php

foreach($program as $item)
{
echo "<option value='$item'>$item</option>";
}

?>


Or maybe you'd prefer something like this:


<?php

$r = mysql_query("select foo from baaz where foobar");

while($row = mysql_fetch_assoc($r))
{
echo "<option value='{$row['foo']}'>{$row['foo']}</option>";
}

?>


I hope you get the idea.

By the way, try to make your PHP blocks larger, and fewer in number - code
is more readable that way.

--
----------------------------------
IvΓ‘n SΓ‘nchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-

El clavo que sobresale siempre recibe un martillazo.
--Proverbio Chino

 

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

Π‘Π°ΠΉΡ‚ ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ Π² Π‘Ρ‚ΡƒΠ΄ΠΈΠΈ Π’Π°Π»Π΅Π½Ρ‚ΠΈΠ½Π° ΠŸΠ΅Ρ‚Ρ€ΡƒΡ‡Π΅ΠΊΠ°
ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ΠΈΠ΅ ΠΈ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠ° Π²Π΅Π±-сайтов, Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ° ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ½ΠΎΠ³ΠΎ обСспСчСния, поисковая оптимизация