Jump to content

MYSQL Query 2 in 1 Issue


j201

Recommended Posts

Hi there, using MYSQL version 5.0.

 

I'm trying to display 2 different sets of dates (registration dates from a forum and old registration dates from a former forum) in one list in chronological order.  So far everything works fine except having them be in the same list together. 

 

 

$membersql = "SELECT * FROM members ORDER BY old_date, register_date;";
$memberres = mysql_query($membersql);

Gets the dates across the user base.

 

$current = date("z");
$check = date("Y");
$limit = date("z")+30;

while($memberrow = mysql_fetch_assoc($memberres)) {
$join = date("z", strtotime($memberrow['register_date']));
$join2 = date("z", strtotime($memberrow['register_date']))+365;
$joincheck = date("Y", strtotime($memberrow['register_date']));

Used later to limit the actual output to only dates within 30 days of today, and starts the while loop.

 

if($current <= $join && $join <= $limit || $join2 <= $limit) {
if($check != $joincheck) {
echo "<div>(new) ".$memberrow['name'].": ";
echo date("n/j", strtotime($memberrow['register_date']))."</div>";
}
}

Checks if the normal join date is within 30 days, and outputs the user name if so.

 

if($memberrow['old_date'] != NULL) {
$old = date("z", strtotime($memberrow['old_date']));
$old2 = date("z", strtotime($memberrow['old_date']))+365;

if($current <= $old && $old <= $limit || $old2 <= $limit) {
echo "<div>(old) ".$memberrow['name'].": ";
echo date("n/j", strtotime($memberrow['old_date']))."</div>";
}
}
}

Same thing, only for the old registration date.

 

Right now that outputs:

 

<div>(new) Username1: 12/31</div>
<div>(new) Username2: 1/4</div>
<div>(new) Username3: 1/12</div>
<div>(old) Username4: 1/1</div>
<div>(old) Username5: 1/6</div>

Whereas I need:

 

<div>(new) Username1: 12/31</div>
<div>(old) Username4: 1/1</div>
<div>(new) Username2: 1/4</div>
<div>(old) Username5: 1/6</div>
<div>(new) Username3: 1/12</div>

 

All help is appreciated.  :)

Link to comment
https://forums.phpfreaks.com/topic/138710-mysql-query-2-in-1-issue/
Share on other sites

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.