I have 2 tables
USERS
------------
id | user
1 | john
2 | George
3 | Andy
Text
--------------------------------
id | user |date |text
1 | 1 |2012/10/2 | ABC
2 | 3 |2012/11/2 | ABCD
3 | 2 |2012/12/2 | ABCDE
4 | 2 |2012/1/2 | ABCDE
In the Text table the user column gets the id from the Users table.
I have the following query:
$sql= mysql_query ("SELECT
user.id,
users.user,
CASE
WHEN text.date = CURDATE() THEN '1'
ELSE '0'
END AS 'today',
text.date,
text.text
FROM users user, text text
WHERE users.id = text.user;");
if (mysql_num_rows($sql)<=0)
echo "NO ENTRIES FOUND";
while ($row = mysql_fetch_assoc($sql))
{
$user =$row['user'];
$id =$row['id'];
$date2 =$row['date'];
if ($row['today'] == 1) { echo"
<div class='z'><a href='viewuser.php?id=$user'>$user</a></div><br>
"; } else { echo"
<div class='zx'><a href='viewuser.php?id=$user'>$user</a></div><br>
"; };
}
My question is:
How can I display the users whose date is equal with today’s date, the first div(zx), and if not with the second div(z), comparing from 2 tables and display once if is it 2 times the user.
Now to display the results just say
Code is abbreviated, let me know if you need it detailed out.
Here is your updated code with my solution from above: