Jump to content

how to make a variable equale 2 values??


techiefreak05

Recommended Posts

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]
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]
[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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.