techiefreak05 Posted September 11, 2006 Share Posted September 11, 2006 how can i do this?? i know its simple// but idk how to.. Link to comment https://forums.phpfreaks.com/topic/20352-how-to-make-a-variable-equale-2-values/ Share on other sites More sharing options...
kenrbnsn Posted September 11, 2006 Share Posted September 11, 2006 Can you explain what you are trying to accomplsh. You're question, as it stands, doesn't make a whole lot of sense.Ken Link to comment https://forums.phpfreaks.com/topic/20352-how-to-make-a-variable-equale-2-values/#findComment-89641 Share on other sites More sharing options...
techiefreak05 Posted September 11, 2006 Author Share Posted September 11, 2006 i havea sdcrip[t that shows all your friends bulletins.. but not your won,, cuz i have the $poster variable equal .. any of your friends.. how do i make it so $ poster equals your friend, AND you.. heres the code:[code]<?php$query="SELECT * FROM friends WHERE `username` = '$_SESSION[username]' AND `accepted` = 'yes'";$result=mysql_query($query);while($array=mysql_fetch_assoc($result)){$poster = $array['friend'];?>[/code] Link to comment https://forums.phpfreaks.com/topic/20352-how-to-make-a-variable-equale-2-values/#findComment-89645 Share on other sites More sharing options...
Jenk Posted September 11, 2006 Share Posted September 11, 2006 er, what?Clarify with an example in pseudo please. Link to comment https://forums.phpfreaks.com/topic/20352-how-to-make-a-variable-equale-2-values/#findComment-89730 Share on other sites More sharing options...
obsidian Posted September 11, 2006 Share Posted September 11, 2006 the only way to have a variable hold more than one value is to have an array:[code]<?php// straight assignment can only hold one value:$var = 18;// arrays hold multiple values:$var = array(18, 22);?>[/code]make sense? Link to comment https://forums.phpfreaks.com/topic/20352-how-to-make-a-variable-equale-2-values/#findComment-89745 Share on other sites More sharing options...
techiefreak05 Posted September 11, 2006 Author Share Posted September 11, 2006 i get it! thanks that helped! Link to comment https://forums.phpfreaks.com/topic/20352-how-to-make-a-variable-equale-2-values/#findComment-90037 Share on other sites More sharing options...
Barand Posted September 11, 2006 Share Posted September 11, 2006 However (assuming this is related to your other recent post) you can't use a php array in a query as it is, that is you cant do this[code]$var = array (10,20);$sql = "SELECT * FROM mytable WHERE poster = '$var'";[/code]You need to join the array elemnts and use it like this[code]$list = join ("','" $var);$sql = "SELECT * FROM mytable WHERE poster IN ('$list')";[/code] Link to comment https://forums.phpfreaks.com/topic/20352-how-to-make-a-variable-equale-2-values/#findComment-90083 Share on other sites More sharing options...
techiefreak05 Posted September 12, 2006 Author Share Posted September 12, 2006 uimmm .. idk what ur talking about :-) lol Link to comment https://forums.phpfreaks.com/topic/20352-how-to-make-a-variable-equale-2-values/#findComment-90182 Share on other sites More sharing options...
techiefreak05 Posted September 12, 2006 Author Share Posted September 12, 2006 grr... your array suggestion doesnt work.. what im after is how to assign 2 different values to one variable Link to comment https://forums.phpfreaks.com/topic/20352-how-to-make-a-variable-equale-2-values/#findComment-90185 Share on other sites More sharing options...
kenrbnsn Posted September 12, 2006 Share Posted September 12, 2006 You can't. A variable can only have one value at a time.Ken Link to comment https://forums.phpfreaks.com/topic/20352-how-to-make-a-variable-equale-2-values/#findComment-90205 Share on other sites More sharing options...
obsidian Posted September 12, 2006 Share Posted September 12, 2006 [quote author=kenrbnsn link=topic=107605.msg432510#msg432510 date=1158035197]You can't. A variable can only have one value at a time.Ken[/quote]right, as was stated above, a variable can only hold one value at a time:[code]<?php$var = 5;$var = 3;echo $var; // will always output '3' since you're overwriting the value?>[/code]a variable can only hold one value at a time. even when you assign an array to the variable, you're still only holding one value: the value of the array. if you will put a little thought into your post and explain [b]what you are trying to do[/b], we may be able to help you work through it. a post like [i]"grr... your array suggestion doesnt work.. what im after is how to assign 2 different values to one variable"[/i] is really not informative at all. what doesn't work about it? why did it break? what are you trying to do with the variable? how are you trying to access and use the values you are assigning? all of these need to be answered in order to help you come to a solution. Link to comment https://forums.phpfreaks.com/topic/20352-how-to-make-a-variable-equale-2-values/#findComment-90373 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.