...

View Full Version : Select option to display all the row data



nani_nisha06
11-12-2012, 11:15 AM
Hi,

I have table for the user login where where there is field with the username.


now in an form I am trying to created a select field which should show all these user names...

I have try to use while loop but I am not success....


Any suggestions to the same ??


regards,
nani

firepages
11-12-2012, 01:40 PM
really need more info to help ;) assuming mysql you might end up with something like this...


<?php
$q=mysql_query("SELECT $username_field,$username_id FROM $user_table");
while($r=mysql_fetch_assoc($q)){
$ops[]="<option value=\"{$r[$username_id]}\">{$r[$username_field]}</option>";
}
?>
...in your form...
<select name="user"><?php echo explode($ops);?></select>
?>

nani_nisha06
11-12-2012, 03:33 PM
really need more info to help ;) assuming mysql you might end up with something like this...


<?php
$q=mysql_query("SELECT $username_field,$username_id FROM $user_table");
while($r=mysql_fetch_assoc($q)){
$ops[]="<option value=\"{$r[$username_id]}\">{$r[$username_field]}</option>";
}
?>
...in your form...
<select name="user"><?php echo explode($ops);?></select>
?>


Firepages,

Although i have customized another 20% on the above code it worked like a charm.

Thanks

Regards,
nani

nani_nisha06
11-12-2012, 03:53 PM
Firepages,

Although i have customized another 20% on the above code it worked like a charm.

Thanks

Regards,
nani

But i am worried about the notice it still displaying with the expected output?


Notice: Undefined variable: item in C:\xampp\htdocs\MYM\index.php on line 41

Fou-Lu
11-12-2012, 06:17 PM
But i am worried about the notice it still displaying with the expected output?


Notice: Undefined variable: item in C:\xampp\htdocs\MYM\index.php on line 41

Is 'item' related to either of these property names?
Looks to me that it won't have anything to do with this block of code. This is part of the joy when it comes to using unknown data with things that should be hard coded structures (such as SQL). You simply need to use isset checks to see if it exists before attempting to read from the array (whichever this error represents).

nani_nisha06
11-13-2012, 08:07 AM
Is 'item' related to either of these property names?
Looks to me that it won't have anything to do with this block of code. This is part of the joy when it comes to using unknown data with things that should be hard coded structures (such as SQL). You simply need to use isset checks to see if it exists before attempting to read from the array (whichever this error represents).

Thanks Fou-Lu,

Now I have closed this issue by declaring null to the item variable...

Regards,
Nani

alemcherry
11-13-2012, 11:59 AM
Turning off PHP notice is fine. These are not really errors and you are likely to have a few of them unless you are very careful and correct.

This should help:
error_reporting(E_ALL ^ E_NOTICE);

http://php.net/manual/en/function.error-reporting.php

nani_nisha06
11-13-2012, 04:01 PM
Turning off PHP notice is fine. These are not really errors and you are likely to have a few of them unless you are very careful and correct.

This should help:
error_reporting(E_ALL ^ E_NOTICE);

http://php.net/manual/en/function.error-reporting.php

Thanks alemcherry,



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum