3 Replies - 897 Views - Last Post: 13 May 2009 - 09:42 AM Rate Topic: -----

#1 MartinPL  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 17-November 08

Values from table to 'Select'

Posted 13 May 2009 - 02:17 AM

Hi,
I have created a simple script which takes values from database(memebers table) and put them into 'select' form.
I works, however not exacly as I want.

<?php
include ("connectiontomembers.php");
  
$sql = "SELECT * FROM members";
$res = mysql_query($sql);

while ($field = mysql_fetch_array($res))
	  {
	  $username = $field['username'];
	  
	  //echo 'Username: ' . $field['username'] . '<br />';
	  $array = array("$username");
	  
	   echo "<select name=\"name\">"; 

foreach($array as $value) { 
	echo "<option value=\"$value\">$value</option>"; 
	  
	  }
	 
	 echo "</select>";	   


	 } 
?>


I takes values from databas but every user is in seperate 'option'.
Just take a look.
Posted Image

To be hones, I have realized that using this 'technic' for selecting users(by admin) is not good idea. For longer run(many records in database) it would be useless. Nomatter of what I'm going to try finish this.

Have a nice day.

This post has been edited by MartinPL: 13 May 2009 - 02:18 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Values from table to 'Select'

#2 Wimpy  Icon User is offline

  • R.I.P. ( Really Intelligent Person, right? )
  • member icon

Reputation: 159
  • View blog
  • Posts: 1,038
  • Joined: 02-May 09

Re: Values from table to 'Select'

Posted 13 May 2009 - 02:21 AM

You have an unnecessary loop in there, I think, try this:
echo "<select name=\"nazwa\">";
while($field = mysql_fetch_array($res))
{
	$username = $field['username'];
	echo "<option value=\"$username\">$username</option>"; 
}
echo "</select>"; 


Hope it helps! :)

View PostMartinPL, on 13 May, 2009 - 11:17 AM, said:

Hi,
I have created a simple script which takes values from database(memebers table) and put them into 'select' form.
I works, however not exacly as I want.

<?php
include ("connectiontomembers.php");
  
$sql = "SELECT * FROM members";
$res = mysql_query($sql);

while ($field = mysql_fetch_array($res))
	  {
	  $username = $field['username'];
	  
	  //echo 'Username: ' . $field['username'] . '<br />';
	  $array = array("$username");
	  
	   echo "<select name=\"name\">"; 

foreach($array as $value) { 
	echo "<option value=\"$value\">$value</option>"; 
	  
	  }
	 
	 echo "</select>";	   


	 } 
?>


I takes values from databas but every user is in seperate 'option'.
Just take a look.
Posted Image

To be hones, I have realized that using this 'technic' for selecting users(by admin) is not good idea. For longer run(many records in database) it would be useless. Nomatter of what I'm going to try finish this.

Have a nice day.

This post has been edited by Wimpy: 13 May 2009 - 02:22 AM

Was This Post Helpful? 1
  • +
  • -

#3 noorahmad  Icon User is offline

  • Untitled
  • member icon

Reputation: 209
  • View blog
  • Posts: 2,290
  • Joined: 12-March 09

Re: Values from table to 'Select'

Posted 13 May 2009 - 02:27 AM

<form name="form1" method="post" action="">
<select name="select" id="select">
<?php
for ($i=0;$i<5;$i++)
{
echo "<option value=1>$i</option>";
}
?>
</select>
</form> 


This post has been edited by noorahmad: 13 May 2009 - 02:33 AM

Was This Post Helpful? 0
  • +
  • -

#4 MartinPL  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 17-November 08

Re: Values from table to 'Select'

Posted 13 May 2009 - 09:42 AM

Thanks @Wimpy, now it works as I wanted :)

Btw, I will think about this 'for'. It was exaclly what i was thinking about.

Thx guys :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1