Jump to content

Recommended Posts

Hi All,

 

I'm fairly new to MySQL and just want to make sure I wrote some good code for an important part of my project before it is released to dozens of users and I don't want it to be a performance bottleneck. Here is what I'm trying to do:

 

-Alert users on login of data that has not been submitted (application requires daily entries for each user)

 

I'm trying to figure out what the best way to write this:

 

1) Is it possible to run a query that tells me which columns in a table are empty? (i.e. entries for, say, Mon, Wed, Thur, Fri are empty)

2) Should I create a table for each user that tracks this on a weekly or bi-weekly basis?

3) Or should I just run a query on the table that needs to be updated each time the user logs in?

 

I'm trying to figure out the best way to alert a user when data needs to be entered, but I don't want run excess queries. Right now the only way I know how to check if columns are empty in X rows is to run a query on each row and use mysql_num_rows? (So this could be potentially 6 queries on login for each user)

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/202257-status-table-optimization/
Share on other sites

1) Is it possible to run a query that tells me which columns in a table are empty? (i.e. entries for, say, Mon, Wed, Thur, Fri are empty)

 

Yes take a look at the CASE-statement for MySQL

 

2) Should I create a table for each user that tracks this on a weekly or bi-weekly basis?

 

No.

 

3) Or should I just run a query on the table that needs to be updated each time the user logs in?

 

Yes.

OK quick follow up statement:

 

I tried this query:

 SELECT CASE dow when "1" then "Entered" END from daily where storeid = '7' and wedate = '2010-04-20' 

and it returns:

 

CASE dow when "1" then "Entered" END

NULL

NULL

NULL

NULL

NULL

Entered

NULL

 

However, if I run the following:

SELECT *
FROM `daily`
WHERE `storeid` =7
AND `wedate` = '2010-04-20'
AND `dow` = '1'

 

It only returns 1 row.

 

Why does my case statement return 7 rows? The column "dow" is an enum with values 0, 1, 2, 3, 4, 5, 6, 7. Do I need to add something else to the CASE statement so force it to only check where "dow" = 1?

 

Thanks!

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.