Jump to content

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]
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?
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.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.