Jump to content


Photo

how to make a variable equale 2 values??


  • Please log in to reply
10 replies to this topic

#1 techiefreak05

techiefreak05
  • Members
  • PipPipPip
  • Advanced Member
  • 494 posts
  • LocationER, MN

Posted 11 September 2006 - 05:16 AM

how can i do this?? i know its simple// but idk how to..
Link shortener with advanced, detailed statistics:

http://tyny.us/

#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 11 September 2006 - 05:19 AM

Can you explain what you are trying to accomplsh. You're question, as it stands, doesn't make a whole lot of sense.

Ken

#3 techiefreak05

techiefreak05
  • Members
  • PipPipPip
  • Advanced Member
  • 494 posts
  • LocationER, MN

Posted 11 September 2006 - 05:22 AM

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:

<?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'];
?>

Link shortener with advanced, detailed statistics:

http://tyny.us/

#4 Jenk

Jenk
  • Members
  • PipPipPip
  • Advanced Member
  • 778 posts

Posted 11 September 2006 - 11:33 AM

er, what?

Clarify with an example in pseudo please.

#5 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 11 September 2006 - 12:35 PM

the only way to have a variable hold more than one value is to have an array:
<?php
// straight assignment can only hold one value:
$var = 18;

// arrays hold multiple values:
$var = array(18, 22);
?>

make sense?
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#6 techiefreak05

techiefreak05
  • Members
  • PipPipPip
  • Advanced Member
  • 494 posts
  • LocationER, MN

Posted 11 September 2006 - 09:58 PM

i get it! thanks that helped!
Link shortener with advanced, detailed statistics:

http://tyny.us/

#7 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 11 September 2006 - 11:09 PM

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
$var = array (10,20);
$sql = "SELECT * FROM mytable WHERE poster = '$var'";

You need to join the array elemnts and use it like this
$list = join ("','" $var);
$sql = "SELECT * FROM mytable WHERE poster IN ('$list')";

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#8 techiefreak05

techiefreak05
  • Members
  • PipPipPip
  • Advanced Member
  • 494 posts
  • LocationER, MN

Posted 12 September 2006 - 02:41 AM

uimmm .. idk what ur talking about :-) lol
Link shortener with advanced, detailed statistics:

http://tyny.us/

#9 techiefreak05

techiefreak05
  • Members
  • PipPipPip
  • Advanced Member
  • 494 posts
  • LocationER, MN

Posted 12 September 2006 - 03:07 AM

grr... your array suggestion doesnt work.. what im after is how to assign 2 different values to one variable
Link shortener with advanced, detailed statistics:

http://tyny.us/

#10 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 12 September 2006 - 04:26 AM

You can't. A variable can only have one value at a time.

Ken

#11 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 12 September 2006 - 01:00 PM

You can't. A variable can only have one value at a time.

Ken


right, as was stated above, a variable can only hold one value at a time:
<?php
$var = 5;
$var = 3;
echo $var; // will always output '3' since you're overwriting the value
?>

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 what you are trying to do, we may be able to help you work through it. a post like "grr... your array suggestion doesnt work.. what im after is how to assign 2 different values to one variable" 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.
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users