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
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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.