Jump to content


Photo

Inputting Two Variables in One field


  • Please log in to reply
5 replies to this topic

#1 dark dude

dark dude
  • Members
  • PipPipPip
  • Advanced Member
  • 53 posts

Posted 10 September 2006 - 01:48 PM

$num = mysql_numrows($result);

$UpDateNum = $num + 1;

$query="INSERT INTO Planets VALUES ('','$Galaxy','$System','$Planet','$Continent','','Colony','$Username','0','500','10','250','100','Colony11','1','','','','','','','','','$ip',CURRENT_TIMESTAMP(NOW()))";
mysql_query($query);


Focus on the bit in bold red...

I want to be able to make it something like:

'Colony(whatever $UpDateNum is)'

But I cant find how to do it. I've tried 'Colony'.$UpDateNum.'' but that doesnt work...

Please help? ???

#2 hostfreak

hostfreak
  • Members
  • PipPipPip
  • Advanced Member
  • 581 posts

Posted 10 September 2006 - 01:53 PM

You would have to do this:

$query = "INSERT INTO Planets(field, field, Colony) VALUES('$field','$field','$Colony$UpDateNum')";


#3 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 10 September 2006 - 02:02 PM

Putting more than one value in a field is easy; it's getting them out separately that's the problem. Are you absolutely certain that that's what you want to do?  One more field in your database table is pretty cheap.
Legend has it that reading the manual never killed anyone.
My site

#4 hostfreak

hostfreak
  • Members
  • PipPipPip
  • Advanced Member
  • 581 posts

Posted 10 September 2006 - 02:05 PM

If you must have them in one field, you may want to consider separating them by something. Then when you retrieve the data you can explode it. That would make things easier.

#5 dark dude

dark dude
  • Members
  • PipPipPip
  • Advanced Member
  • 53 posts

Posted 10 September 2006 - 02:18 PM

Putting more than one value in a field is easy; it's getting them out separately that's the problem. Are you absolutely certain that that's what you want to do?  One more field in your database table is pretty cheap.


Yeah, I just want the two variables to merge :P

Because my finding system finds "Colonies" by the number after it.

The "UpDateNum" variable holds the number that's to go after the name "Colony".

So, if there are already 4 colonies, UpDateNum will equal 5, and it will input into the database "Colony5"...

#6 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 10 September 2006 - 02:25 PM

Yeah, I just want the two variables to merge :P

Because my finding system finds "Colonies" by the number after it.


There are no numbers in Colony5 or Colony23 - those are strings.
Legend has it that reading the manual never killed anyone.
My site




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users