Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Web Coding › PHP rows to HTML drop down list?
New Posts  All Forums:Forum Nav:

PHP rows to HTML drop down list?

post #1 of 2
Thread Starter 
So I've inserted some values to a table in mysql and I want to convert them to a drop down list.


How do I do that?

I tried my own code

Quote:
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("mydatabase", $con);

$result = mysql_query("SELECT * FROM stat_emp");

echo "<select>
while($row = mysql_fetch_array($result))
{
<option>.$row['emp_status'].</option>
}
</select>";
?>
and it gives me this error
Quote:
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in
Any help will be really appreciated!
Edited by gerikoh - 3/22/11 at 9:19pm
   
Ivy's Panther
(15 items)
 
CPUMotherboardGraphicsRAM
AMD Ryzen 7 1700 @ 4ghz 1.35v ASRock AB350 Gaming-ITX/ac ZOTAC GeForce GTX 1080 8GB Mini ZT-P10800H-10P ... Team Dark Pro 2x8GB 3000Mhz 14-14-14-31 
Hard DriveCoolingOSMonitor
Samsung 960Pro 512GB M.2 NVMe Noctua NH-L9a 92mm SSO2 Windows 10 x64 Pro ASUS PG278QR 27" 1440p Gsync 165Hz 
KeyboardPowerCaseMouse
Logitech G710+ MX Brown HDPLEX 300W Hi-Fi DC-ATX + Dell 330W AC NFC S4 Mini Logitech G900 Chaos Spectrum Wireless 
Mouse Pad
Logitech G440 
CPUMotherboardGraphicsRAM
Intel Core i7 4800mq Clevo W230ST Nvidia GTX 765m 8x2GB Samsung ULV 1600 @1.25v 
Hard DriveOS
Sandisk Extreme SSD 480GB Windows Server 2012 R2 
CPUMotherboardGraphicsRAM
i7 3770 w/ vpro @ 2.5ghz 0.9v Asus Maximus V Gene Z77 MSI GeForce GTX 660ti Power Edition 4x4gb Samsung MV-3V4G3D 1600-cl7 @ 1.35v 
Hard DriveCoolingOSMonitor
2x480gb Sandisk Extreme SSD Raid0 Prolimatech Samuel+AC4 w/ Corsair SP120 Windows 7 Ultimate x64 LG D2342P 1080p 3D 
KeyboardPowerCaseMouse
Rosewill RK-9100BR Cherry MX-Brown w/ backlight Andyson Platinum 550w Modular Silverstone SG-02B Logitech MX 950 
Mouse PadAudioOther
CoolerMaster Storm Creative SB SupremeFX III Atheros Killer Wireless-N 1202+BT4.0 
  hide details  
Reply
   
Ivy's Panther
(15 items)
 
CPUMotherboardGraphicsRAM
AMD Ryzen 7 1700 @ 4ghz 1.35v ASRock AB350 Gaming-ITX/ac ZOTAC GeForce GTX 1080 8GB Mini ZT-P10800H-10P ... Team Dark Pro 2x8GB 3000Mhz 14-14-14-31 
Hard DriveCoolingOSMonitor
Samsung 960Pro 512GB M.2 NVMe Noctua NH-L9a 92mm SSO2 Windows 10 x64 Pro ASUS PG278QR 27" 1440p Gsync 165Hz 
KeyboardPowerCaseMouse
Logitech G710+ MX Brown HDPLEX 300W Hi-Fi DC-ATX + Dell 330W AC NFC S4 Mini Logitech G900 Chaos Spectrum Wireless 
Mouse Pad
Logitech G440 
CPUMotherboardGraphicsRAM
Intel Core i7 4800mq Clevo W230ST Nvidia GTX 765m 8x2GB Samsung ULV 1600 @1.25v 
Hard DriveOS
Sandisk Extreme SSD 480GB Windows Server 2012 R2 
CPUMotherboardGraphicsRAM
i7 3770 w/ vpro @ 2.5ghz 0.9v Asus Maximus V Gene Z77 MSI GeForce GTX 660ti Power Edition 4x4gb Samsung MV-3V4G3D 1600-cl7 @ 1.35v 
Hard DriveCoolingOSMonitor
2x480gb Sandisk Extreme SSD Raid0 Prolimatech Samuel+AC4 w/ Corsair SP120 Windows 7 Ultimate x64 LG D2342P 1080p 3D 
KeyboardPowerCaseMouse
Rosewill RK-9100BR Cherry MX-Brown w/ backlight Andyson Platinum 550w Modular Silverstone SG-02B Logitech MX 950 
Mouse PadAudioOther
CoolerMaster Storm Creative SB SupremeFX III Atheros Killer Wireless-N 1202+BT4.0 
  hide details  
Reply
post #2 of 2
Thread Starter 
Ha! Nevermind, I got it!

It's just a syntax error. Here it is


Quote:
<select>

<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("mydatabase", $con);

$result = mysql_query("SELECT * FROM stat_emp");

while($row = mysql_fetch_array($result))
{
$option=$row['emp_status'];
echo "<option>$option</option>";
}
?>

</select>
Hope this could be useful for beginners like me!
Edited by gerikoh - 3/22/11 at 9:20pm
   
Ivy's Panther
(15 items)
 
CPUMotherboardGraphicsRAM
AMD Ryzen 7 1700 @ 4ghz 1.35v ASRock AB350 Gaming-ITX/ac ZOTAC GeForce GTX 1080 8GB Mini ZT-P10800H-10P ... Team Dark Pro 2x8GB 3000Mhz 14-14-14-31 
Hard DriveCoolingOSMonitor
Samsung 960Pro 512GB M.2 NVMe Noctua NH-L9a 92mm SSO2 Windows 10 x64 Pro ASUS PG278QR 27" 1440p Gsync 165Hz 
KeyboardPowerCaseMouse
Logitech G710+ MX Brown HDPLEX 300W Hi-Fi DC-ATX + Dell 330W AC NFC S4 Mini Logitech G900 Chaos Spectrum Wireless 
Mouse Pad
Logitech G440 
CPUMotherboardGraphicsRAM
Intel Core i7 4800mq Clevo W230ST Nvidia GTX 765m 8x2GB Samsung ULV 1600 @1.25v 
Hard DriveOS
Sandisk Extreme SSD 480GB Windows Server 2012 R2 
CPUMotherboardGraphicsRAM
i7 3770 w/ vpro @ 2.5ghz 0.9v Asus Maximus V Gene Z77 MSI GeForce GTX 660ti Power Edition 4x4gb Samsung MV-3V4G3D 1600-cl7 @ 1.35v 
Hard DriveCoolingOSMonitor
2x480gb Sandisk Extreme SSD Raid0 Prolimatech Samuel+AC4 w/ Corsair SP120 Windows 7 Ultimate x64 LG D2342P 1080p 3D 
KeyboardPowerCaseMouse
Rosewill RK-9100BR Cherry MX-Brown w/ backlight Andyson Platinum 550w Modular Silverstone SG-02B Logitech MX 950 
Mouse PadAudioOther
CoolerMaster Storm Creative SB SupremeFX III Atheros Killer Wireless-N 1202+BT4.0 
  hide details  
Reply
   
Ivy's Panther
(15 items)
 
CPUMotherboardGraphicsRAM
AMD Ryzen 7 1700 @ 4ghz 1.35v ASRock AB350 Gaming-ITX/ac ZOTAC GeForce GTX 1080 8GB Mini ZT-P10800H-10P ... Team Dark Pro 2x8GB 3000Mhz 14-14-14-31 
Hard DriveCoolingOSMonitor
Samsung 960Pro 512GB M.2 NVMe Noctua NH-L9a 92mm SSO2 Windows 10 x64 Pro ASUS PG278QR 27" 1440p Gsync 165Hz 
KeyboardPowerCaseMouse
Logitech G710+ MX Brown HDPLEX 300W Hi-Fi DC-ATX + Dell 330W AC NFC S4 Mini Logitech G900 Chaos Spectrum Wireless 
Mouse Pad
Logitech G440 
CPUMotherboardGraphicsRAM
Intel Core i7 4800mq Clevo W230ST Nvidia GTX 765m 8x2GB Samsung ULV 1600 @1.25v 
Hard DriveOS
Sandisk Extreme SSD 480GB Windows Server 2012 R2 
CPUMotherboardGraphicsRAM
i7 3770 w/ vpro @ 2.5ghz 0.9v Asus Maximus V Gene Z77 MSI GeForce GTX 660ti Power Edition 4x4gb Samsung MV-3V4G3D 1600-cl7 @ 1.35v 
Hard DriveCoolingOSMonitor
2x480gb Sandisk Extreme SSD Raid0 Prolimatech Samuel+AC4 w/ Corsair SP120 Windows 7 Ultimate x64 LG D2342P 1080p 3D 
KeyboardPowerCaseMouse
Rosewill RK-9100BR Cherry MX-Brown w/ backlight Andyson Platinum 550w Modular Silverstone SG-02B Logitech MX 950 
Mouse PadAudioOther
CoolerMaster Storm Creative SB SupremeFX III Atheros Killer Wireless-N 1202+BT4.0 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Web Coding
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Web Coding › PHP rows to HTML drop down list?