twilitegxa Posted September 16, 2008 Share Posted September 16, 2008 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? Quote Link to comment Share on other sites More sharing options...
dezkit Posted September 16, 2008 Share Posted September 16, 2008 $birthdate = $birthdatemonth . "/" . $birthdateday . "/". $birthdateyear; Quote Link to comment Share on other sites More sharing options...
Maq Posted September 16, 2008 Share Posted September 16, 2008 Depends on what you're trying to accomplish but here's another way. $birthdate[0]=$birthdatemonth; $birthdate[1]=$birthdateday; $birthdate[2]=$birthdateyear; Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted September 16, 2008 Author Share Posted September 16, 2008 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"? Quote Link to comment Share on other sites More sharing options...
budimir Posted September 16, 2008 Share Posted September 16, 2008 $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??? Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted September 16, 2008 Author Share Posted September 16, 2008 I don't know. It's not working for some reason. Quote Link to comment Share on other sites More sharing options...
budimir Posted September 16, 2008 Share Posted September 16, 2008 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. Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted September 16, 2008 Author Share Posted September 16, 2008 I did adjust it with your code, but it's okay because I had someone else help me with it as well. Thanks for trying to help though. I got it fixed now. :-) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.