Solved

mysql php - No records found

Posted on 2011-02-15
6
486 Views
Last Modified: 2013-12-13

Hello Experts,

I really need a light on this problem.

a php page with a select statement caching data from a database was working fine but today the page is showing "no records found".

I run to check that the database on the hosting server... its fine!
and also to run the same select statement in the phpmyadmin.

The only error while running the same select statement in phpmyadmin was the "1104 would examine more than MAX_JOIN_SIZE rows..."

I added in the phpmysql above the select statement the following: SET SQL_BIG_SELECTS=1;

and all is fine! i got all the results!

i copied and paste the same select statement into the php page and upload it and then again... it prints "no results found".

should i add "SET SQL_BIG_SELECTS=1;" in the PHP page as well?

here is the main code please if someone can see where is the problem?
$search_query="";
$list_companies = $mysqli_link->prepare(
"SELECT `vo-companies`.company_id,
`vo-companies`.company_name AS company,
OFFICEQ.startdate,
OFFICEQ.officeplan,
OFFICEQ.officecenter,
PARTNERQ.partnername,
PARTNERQ.partnerLName,
EMAILQ.email,
PHONESQ.phone,
ADDRESSQ.address_id,
ADDRESSQ.address1, 
ADDRESSQ.address2,
ADDRESSQ.city,
ADDRESSQ.state,
ADDRESSQ.zip,
ADDRESSQ.country
FROM `vo-companies`
LEFT JOIN (SELECT 
`vo-offices`.office_id,
`vo-offices`.company_id,
`vo-offices`.office_date as startdate,
`vo-offices`.office_plan,
`vo-offices`.office_center,
`vo-plans`.plan_name as officeplan,
`vo-centers`.center_name as officecenter
FROM `vo-offices` LEFT JOIN `vo-plans` ON `vo-offices`.office_plan=`vo-plans`.plan_id LEFT JOIN `vo-centers` ON `vo-offices`.office_center=`vo-centers`.center_id GROUP BY `vo-offices`.company_id)
AS OFFICEQ on OFFICEQ.company_id=`vo-companies`.company_id
LEFT JOIN (SELECT 
`vo-partners`.partner_id,
`vo-partners`.company_id,
`vo-partners`.partner_fname as partnername,
`vo-partners`.partner_lname as partnerLName
FROM `vo-partners` GROUP BY `vo-partners`.company_id)
AS PARTNERQ on PARTNERQ.company_id=`vo-companies`.company_id
LEFT JOIN (SELECT 
`vo-company_emails`.company_id,
`vo-company_emails`.company_emails_email as email 
FROM `vo-company_emails` GROUP BY `vo-company_emails`.company_id)
AS EMAILQ on EMAILQ.company_id=`vo-companies`.company_id
LEFT JOIN (SELECT 
`vo-company_phones`.company_id,
`vo-company_phones`.company_phones_phone as phone 
FROM `vo-company_phones` GROUP BY `vo-company_phones`.company_id)
AS PHONESQ on PHONESQ.company_id=`vo-companies`.company_id
LEFT JOIN (SELECT 
`vo-company_addr`.company_addr_id as address_id, 
`vo-company_addr`.company_id,
`vo-company_addr`.company_addr_line1 as address1,
`vo-company_addr`.company_addr_line2 as address2, 
`vo-company_addr`.company_addr_city as city,
`vo-company_addr`.company_addr_state as state, 
`vo-company_addr`.company_addr_zip as zip,
`vo-countries`.name AS country
FROM `vo-company_addr` LEFT JOIN `vo-countries` ON `vo-company_addr`.company_addr_country_iso=`vo-countries`.iso GROUP BY `vo-company_addr`.company_id) 
AS ADDRESSQ on ADDRESSQ.company_id=`vo-companies`.company_id WHERE `vo-companies`.company_active='Y' $search_query");

$list_companies->execute();
$list_companies->bind_result($company_id, $company_name, $start_date, $plan, $center, $partner_fname, $partner_lname, $company_email, $company_phone, $company_addr_id, $address_line1, $address_line2, $city, $state, $zip, $country);
$list_companies->store_result();
if($list_companies->num_rows==0) echo "<tr><td colspan='8' align='center'> No results found.</td></tr>";
while ($list_companies->fetch()) {
echo "<tr>
<td nowrap='nowrap'><a href='company_details.php?cid=$company_id'>$company_name</a></td>";
}
$list_companies->close();

Open in new window

0
Comment
Question by:Refael
6 Comments
 
LVL 11

Expert Comment

by:Amar Bardoliwala
Comment Utility
Hello Refael,

I think following link can give you some good information on your problem.

Please look at it and act accordingly.

http://stackoverflow.com/questions/950465/mysql-sql-big-selects

According to me you can add "SET SQL_BIG_SELECTS=1;" in php code too if necessary.

Hope this will help you.

Thanks
0
 
LVL 34

Expert Comment

by:Beverley Portlock
Comment Utility
I would edit /etc/my.cnf and set SQL_BIG_SELECTS to ON then you know the problem is resolved no matter how the query is run.
0
 

Author Comment

by:Refael
Comment Utility

Hello amar_bardoliwala, bportlock,

the article was not really helping as i do not know where and how to add it.
i tried to search on the hosting server for the etc/my.cnf  or mysql.cnf but could not find any.
i have a (require) config file in the php page, should i add it there, can you show me how?

anyway i add a limit "LIMIT 20" to the end like so:

WHERE `vo-companies`.company_active='Y' LIMIT 20 $search_query

still showing up no records! please HELP!
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 11

Accepted Solution

by:
Amar Bardoliwala earned 250 total points
Comment Utility
Hello Refael,

If your code is on some hosting server than you will need to ask them for the help, regarding the matter.

If you have it installed on your local pc than following link will help you to find it.

http://dev.mysql.com/doc/refman/5.1/en/option-files.htm

Also for now you can try running following statement just before your query execution and see if that works for you.

"SET SQL_BIG_SELECTS=1;"

Thanks.



0
 
LVL 2

Expert Comment

by:eZov
Comment Utility
Try to add at the end of your SQL query LIMIT 0, 100; to limit the number of rows returned. This will tell you if the number of rows is too big to be processed by one sql query.
0
 
LVL 2

Assisted Solution

by:eZov
eZov earned 250 total points
Comment Utility
The end of query should be:

WHERE `vo-companies`.company_active='Y' $search_query LIMIT 0, 100;
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now