Solved

mysql php - No records found

Posted on 2011-02-15
6
489 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
ID: 34903828
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
ID: 34904478
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
ID: 34906763

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
Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

 
LVL 11

Accepted Solution

by:
Amar Bardoliwala earned 250 total points
ID: 34913618
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
ID: 34976859
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
ID: 34976888
The end of query should be:

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

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
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…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

867 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

25 Experts available now in Live!

Get 1:1 Help Now