473,385 Members | 1,813 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

php/mysql which is more efficient - multiple queries, or search key/value from array?

110 100+
I'm building a calendar site, and am wondering if I've gone wrong in the way I have structured it.

Right now, I take the date of each cell, and pass it as a query to mysql and put the response in that cell output.
That was the easy way to do it.
But now i realize I could have selected dates between, and then used php to search the returned array for the date and then find the cell which matches that date and put the value in that cell.

The second way seems much more complicated, but I am concerned about long-term efficiency. Can anybody tell me which way is more efficient?

Here's an example of the code I have now
Expand|Select|Wrap|Line Numbers
  1.  
  2. echo"</tr><tr class=\"notes\"><td>$first_name $last_name Notes</td>";
  3.  
  4. $un=0;
  5. $newDate3 = date('y/m/d', mktime(0,0,0, $month, $day+$un, $year));
  6.  
  7. while($un<7){
  8. $queryUserNote = "SELECT notes.note FROM notes WHERE date = '$newDate3' AND uid = '$uid'";
  9. $resultUserNote = mysql_query($queryUserNote)or die(mysql_error('could not get personal notes'));
  10.  
  11. $userNoteArray=mysql_fetch_array($resultUserNote);
  12. $userNote = $userNoteArray['note'];
  13.  
  14. echo "<td class=\"notes\">$userNote</td>";
  15. $un++;
  16. }
  17.  
thanks for your help,
Pete
Feb 6 '08 #1
3 2286
MarkoKlacar
296 Expert 100+
Hi,

My guess would be to select all the dates using a MySQL statement and then looping through the result array.

If you display a whole year you have a maximum of 365(+leap year) iterations and one SQL statement, otherwise you end up with 365(+leap year) SQL statements...

Hope I understood you correctly..

Good Luck
Feb 7 '08 #2
pedalpete
110 100+
I happy that this maybe isn't an obvious question.

If I have about 365 queries, the majority will likely return null, so I can't just iterate through the sql response, I have to actually check that the date is in the results

eg, for each day, I have to use php to check the entire sql returned array and then it has to decide either
1 - the date is not in the array ( the result for that day was null)
2 - the date is in the array and put that data into the proper cell in the table.

I'm not sure if I clarified this or made it more confusing.
programatically, I think it is MUCH easier to query each day for data rather then querying the response array for the date and then getting the data.

Hi,

My guess would be to select all the dates using a MySQL statement and then looping through the result array.

If you display a whole year you have a maximum of 365(+leap year) iterations and one SQL statement, otherwise you end up with 365(+leap year) SQL statements...

Hope I understood you correctly..

Good Luck
Feb 8 '08 #3
MarkoKlacar
296 Expert 100+
Hi,

You're probably looking at the same latency no matter what solution you choose.
Just as long as it woks.
Feb 8 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: elyob | last post by:
Hi, I'm looking at storing snippets of details in MySQL about what credit cards a business excepts. Rather than have a whole column for Visa, another for Amex etc ... I am looking at having a...
1
by: SC | last post by:
I'm developing a site that may eventually have a very large database of users (hopefully, but who knows). It will be a community website where users can search each other (think Friendster,...
1
by: mpar612 | last post by:
Hi everyone, I'm not sure if this is asking too much or not. I am trying to get the following PHP code to work on my website. It utilizes PHP 5, MySQL 4.1 and the PEAR DB module. I am...
7
by: Daz | last post by:
Hi. I am trying to select data from two separate MySQL tables, where I cannot use join, but when I put the two select queries into a single query, I get an error telling me to check my syntax. Both...
13
by: Ciaran | last post by:
Hi All, Is it faster to have mySql look up as much data as possible in one complex query or to have php do all the complex processing and submit lots of simple queries to the mysql database? ...
6
Atli
by: Atli | last post by:
This is an easy to digest 12 step guide on basics of using MySQL. It's a great refresher for those who need it and it work's great for first time MySQL users. Anyone should be able to get...
11
by: rich | last post by:
I'm having a tough time figuring out which of these two options are best. This is a matter of processing my data in PHP, vs MySQL. Usually that's a no brainer, but I have a couple gotchyas here...
0
bilibytes
by: bilibytes | last post by:
hi, i am trying to UPDATE multiple rows with mysql. I know how to do it with multiple queries but i think it would be less resource consuming generating mysql query code with php and update all...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.