Solved

mysql php - No records found

Posted on 2011-02-15
6
495 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Suggested Solutions

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
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.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

856 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