karatekid36 Posted May 16, 2007 Share Posted May 16, 2007 What is the proper way to reference he birthday variable I am calling from the table in my code on line 44? My goal here is to tell each member exactly how hold they are. The birthday is in the table as yyyy-mm-dd. Am I some how confusing the php and mysql dates? Not sure what my issue is right now. The code is telling every user that they are 37 years old or so. Not good..... <?php session_name ('YourVisitID'); session_start(); // Start the session. // If no session value is present, redirect the user. if (!isset($_SESSION['user_id'])) { // Start defining the URL. $url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']); // Check for a trailing slash. if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) { $url = substr ($url, 0, -1); // Chop off the slash. } $url .= '/index.php'; // Add the page. header("Location: $url"); exit(); // Quit the script. } $page_title = 'Brothers'; include ('includes/header.html'); // Page header. echo '<h1 id="mainhead">Brothers</h1>'; require_once ('includes/mysql_connect.php'); // Connect to the db. // Make the query. $query = "SELECT birthday, CONCAT_WS(' ', first_name, last_name) AS name FROM brothers ORDER BY last_name, first_name ASC"; $result = mysql_query ($query); // Run the query. if (!$result) { echo "The Query: $query Produced the error: ".mysql_error(); exit; } $starttime=time(); //standard this is just today's date // the start time can change to =strtotime($endtime); $endtime = birthday; //$endtime can be any format as well as it can be converted to secs $timediff = $starttime-$endtime; $years=intval($timediff/31557600); $remain=$timediff%31557600; $days=intval($remain/86400); $remain=$timediff%86400; $hours=intval($remain/3600); $remain=$remain%3600; $mins=intval($remain/60); $secs=$remain%60; //$days is what you need // this is just an output that tells the difrence $timediff=$years . 'years' . $days . 'days' . $hours . 'hr' . $mins . 'min'. $secs . 's'; // Table header. echo '<table align="center" cellspacing="0" cellpadding="5"> <tr> <td align="left"><b>Name</b></td> <td align="left"><b>Birthday</b></td> <td align="left"><b>Days</b></td> </tr>'; // Fetch and print all the records. $bg = '#eeeeee'; // Set the background color. while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $bg = ($bg=='#eeeeee' ? '#ffffff' : '#eeeeee'); // Switch the background color. echo '<tr bgcolor="' . $bg . '"> <td align="left">' . $row['name'] . '</td> <td align="left">' . $row['birthday'] . '</td> <td align="left">' . $timediff . '</td> </tr> '; } echo '</table>'; mysql_free_result ($result); // Free up the resources. mysql_close(); // Close the database connection. include ('includes/footer.html'); // Include the HTML footer. ?> Quote Link to comment https://forums.phpfreaks.com/topic/51599-i-need-help-with-referencing-a-variable-i-am-pulling-from-one-of-my-tables/ Share on other sites More sharing options...
phast1 Posted May 16, 2007 Share Posted May 16, 2007 If you are SELECTing more than 1 row at a time, then you should do a loop to run through the result rows.. Something like this: while ($row=mysql_fetch_assoc($result)){ $birthday = $row['birthday']; $name = $row['name']; // do some calculations here and save to array } Hope that helps! Quote Link to comment https://forums.phpfreaks.com/topic/51599-i-need-help-with-referencing-a-variable-i-am-pulling-from-one-of-my-tables/#findComment-254151 Share on other sites More sharing options...
MadTechie Posted May 17, 2007 Share Posted May 17, 2007 same Quote Link to comment https://forums.phpfreaks.com/topic/51599-i-need-help-with-referencing-a-variable-i-am-pulling-from-one-of-my-tables/#findComment-255527 Share on other sites More sharing options...
karatekid36 Posted May 17, 2007 Author Share Posted May 17, 2007 Thank you for yelling at me for a rule that I was unaware of. That was extremely helpful. Quote Link to comment https://forums.phpfreaks.com/topic/51599-i-need-help-with-referencing-a-variable-i-am-pulling-from-one-of-my-tables/#findComment-255530 Share on other sites More sharing options...
MadTechie Posted May 17, 2007 Share Posted May 17, 2007 You should read the rules BEFORE posting Quote Link to comment https://forums.phpfreaks.com/topic/51599-i-need-help-with-referencing-a-variable-i-am-pulling-from-one-of-my-tables/#findComment-255532 Share on other sites More sharing options...
karatekid36 Posted May 17, 2007 Author Share Posted May 17, 2007 I had, but I think I should read them again. Would you be a good little forum helper and point me in the right direction? Quote Link to comment https://forums.phpfreaks.com/topic/51599-i-need-help-with-referencing-a-variable-i-am-pulling-from-one-of-my-tables/#findComment-255537 Share on other sites More sharing options...
MadTechie Posted May 17, 2007 Share Posted May 17, 2007 their at the top.. and in my signature and here Quote Link to comment https://forums.phpfreaks.com/topic/51599-i-need-help-with-referencing-a-variable-i-am-pulling-from-one-of-my-tables/#findComment-255540 Share on other sites More sharing options...
karatekid36 Posted May 17, 2007 Author Share Posted May 17, 2007 I found them. I am not being a jerk, but I am unclear where it says no triple posts. I searched the page for triple, three, and 3. I am just curious because I am wondering if this is a rule or just general courtesy on this board. Quote Link to comment https://forums.phpfreaks.com/topic/51599-i-need-help-with-referencing-a-variable-i-am-pulling-from-one-of-my-tables/#findComment-255545 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.