Solved

mysql php - No records found

Posted on 2011-02-15
6
505 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
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

Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

Question has a verified solution.

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

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…
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 …

691 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