Welcome Guest [Log In] [Register]
We hope you enjoy your visit.

You're currently viewing our forum as a guest. This means you are limited to certain areas of the board and there are some features you can't use. If you join our community, you'll be able to access member-only sections, and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free.


Join our community!


If you're already a member please log in to your account to access all of our features:

Username:   Password:
Add Reply
php need help
Topic Started: Nov 1 2009, 08:48 AM (184 Views)
Black Shadow
Join the Dark Side...We have cookies :)
[ *  *  *  * ]
I have this list
Code:
 
$cat = array (1 => 'Hardware', 'Software', 'Console', 'Others');
and it generates a drop down list.I want to assign one of those values to a variable. How do I do it i can't figure it out :(
Offline Profile Quote Post Goto Top
 
dZ
Member
[ *  * ]
$name = 'activation_word';
$$name = word;
echo $activation_word; // outputs: word
Offline Profile Quote Post Goto Top
 
Black Shadow
Join the Dark Side...We have cookies :)
[ *  *  *  * ]
? i dont understand.. how would that help me.. whats is activation word and how do i assign the value from a list to a variable in your example ?
i print my drop down menu using a function.. so it looks smth like this
Code:
 

<?php function_name($var['cat']) ?>

Edited by Black Shadow, Nov 1 2009, 10:30 AM.
Offline Profile Quote Post Goto Top
 
Jory
Member Avatar


dZ, variable variables are a rather complex topic that you really shouldn't try to tell a beginning coder about. They cause value and difficult to debug code, and should be avoided if possible.

Black Shadow, so you have an array, and you want to take one value from that array and assign it to a variable? You could do that, like so:
Code:
 
$array = array('Hardware', 'Software', 'Console', 'Others');
$hardware = $array[0]; // 0 because, if you don't define the index yourself, PHP (and most other languages, really) starts counting at 0.
echo $hardware; // Prints 'Hardware' to the screen.

Does that do what you want?
Offline Profile Quote Post Goto Top
 
Zefer
Member Avatar
Member
[ *  * ]
That code is not only invalid, it's completely irrelevant to the subject.

Here's a solution, not sure if it's what you want - if it isn't then please just let me know and I'll change the code for you.

Code:
 

<?php
$list = array (
"Hardware",
"Software",
"Computers",
"Others"
);
?>
<form action="category.php" method="get">
<select name="category">
<?php
foreach ($list as $item) {
echo "<option name=\"$item\">$item</option>";
};
?>
</select>
<button type="submit">
Go!
</button>
</form>


Hope that helps,
Ryan.
Offline Profile Quote Post Goto Top
 
1 user reading this topic (1 Guest and 0 Anonymous)
« Previous Topic · Programming and Scripting Chat · Next Topic »
Add Reply