Jump to content

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.

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.