Jump to content

[SOLVED] Adding three fields to one variable


twilitegxa

Recommended Posts

What would the code be for combining the information from three different fields in table into one variable?

 

I want to have the variable, $birthdate, include the information from three fields, birthdatemonth, birthdateday and birthdateyear. Howdo I do this with PHP?

But I was wondering if those suggestions weren't working because in this example

 

$birthdate[0]=$birthdatemonth;

$birthdate[1]=$birthdateday;

$birthdate[2]=$birthdateyear;

 

am I not naming $birthdatemonth as a variable and so on? I have not named it as a variable yet, and in a another post, I was asking for help with naming a variable and pulling the information from a field in my table in my database because I don't understand hwo to do it properly yet. To name the $birthdatemonth variable, hwo do I pull the information from the field, "birthdatemonth"?

$sql = ""SELECT * FROM TABLE";
$result = mysql_query($sql, $conn) or die (mysql_error());
while($row = mysql_fetch_array($result){
$birthdateday = $row["day"];
$birthdatemonth = $row["month"];
$birthdateyear = $row["year"];
}

$birthdate = $birthdateday ".-." $birthdatemonth ".-." $birthdateyear;

echo "$birthdate";

 

Is this what you wanted???

Of course it's not working.

 

You need adjust it to your DB. The query is not returning anything, it's just for example...

 

Adjust it to your code and post it back here and I'll take a look why is not working.

 

I hade a tippo here:

 

$sql = "SELECT * FROM table_name";

You need to put your table_name here

 

 $birthdateday = $row["day"];
$birthdatemonth = $row["month"];
$birthdateyear = $row["year"];

 

Hre you need to put names of your columns form your DB.

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.