Jump to content

[SOLVED] mySQL code problem


GreenSmurf

Recommended Posts

SELECT * ,
IF (
month_lookup.bmonth_num < MONTH( CURDATE( ) )
OR month_lookup.bmonth_num = MONTH( CURDATE( ) )
AND table.bday < DAYOFMONTH( CURDATE( ) ) , CONCAT( table.bmonth, ' ', YEAR( CURDATE( ) ) +1 ) , table.bmonth
) display_month,
IF (
month_lookup.bmonth_num < MONTH( CURDATE( ) )
OR month_lookup.bmonth_num = MONTH( CURDATE( ) )
AND table.bday < DAYOFMONTH( CURDATE( ) ) , month_lookup.bmonth_num+12, month_lookup.bmonth_num
)*32+bday prio
FROM $month_lookup,
addressbook WHERE table.bmonth = month_lookup.bmonth
ORDER BY prio ASC

 

For some odd reason this code finds each instance three times.  Attatched is an image to give you an idea of what I am talking about. Also, I ahve checked the query in HeidiSQL and it is the query not my php loop that is creating the problem. I even checked the actual table and each entry is in there only once. The 'id' number associated with each is a dead give away that each row is being displaed multiple times.

bifdays.jpg

 

Any suggestions would be great, thanks.

 

-Brandon

Link to comment
https://forums.phpfreaks.com/topic/114741-solved-mysql-code-problem/
Share on other sites

This:

 

FROM $month_lookup,
addressbook WHERE table.bmonth = month_lookup.bmonth

 

Is strange -- and is php.

 

Yeah sorry, I was trying to make it look like it normally would in mySQL form. I forgot to take the '$' out and rename the table to addressbook. I will post the real mySQL code and its results soon.

SELECT * , IF ( month_lookup.bmonth_num < MONTH( CURDATE( ) ) OR month_lookup.bmonth_num = MONTH( CURDATE( ) ) AND addressbook.bday < DAYOFMONTH( CURDATE( ) ) , CONCAT( addressbook.bmonth, ' ', YEAR( CURDATE( ) ) +1 ) , addressbook.bmonth ) display_month, IF ( month_lookup.bmonth_num < MONTH( CURDATE( ) ) OR month_lookup.bmonth_num = MONTH( CURDATE( ) ) AND addressbook.bday < DAYOFMONTH( CURDATE( ) ) , month_lookup.bmonth_num+12, month_lookup.bmonth_num )*32+bday prio FROM month_lookup, addressbook WHERE 1=1 AND addressbook.bmonth = month_lookup.bmonth ORDER BY prio ASC

 

Here is the actualy mySQL query. Any help would be apperciated. Thank you.

 

 

-Brandon

if ($prevID != $id)
{

$prevID = $id;

...

}

 

In the meanwhile I used this if statement to control the excessive listsing that the query returns. I would much rather that the mySQL query NOT have this problem but I have been over it time and time again and I can't see why it returns results three times. Thank you to fenway for trying to help.

 

 

-Brandon

I do not follow you- how is it not unique enough?

 

 

-Brandon

I mean that one bmonth value from one table matches more than one record in the other table.

 

I understand now. You are absolutely right. I had to go and remove multiple entries from the db to fix the problem. All months were listed three times thus returning three results. Thank you.

 

 

-Brandon

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.