Spraban9 Posted April 3, 2013 Share Posted April 3, 2013 this coding is working in localhost <?php include("include/connection.php"); $profile= mysql_query("SELECT count( user )FROM (SELECT user FROM computerrepair UNION ALL SELECT user FROM computersale UNION ALL SELECT user FROM hospital UNION ALL SELECT user FROM hotel UNION ALL SELECT user FROM house UNION ALL SELECT user FROM land UNION ALL SELECT user FROM mobile UNION ALL SELECT user FROM theater UNION ALL SELECT user FROM upload UNION ALL SELECT user FROM vechicle) AS a WHERE user = '$login_session'",$conn); $menus=mysql_fetch_assoc($profile); $noof=$menus['count( user )']; ?> Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/a8326388/public_html/profile.php on line 59 $menus=mysql_fetch_assoc($profile); is in line 59 Quote Link to comment https://forums.phpfreaks.com/topic/276465-count-coding-is-working-in-localhost-but-in-000webhost-i-get-error/ Share on other sites More sharing options...
requinix Posted April 3, 2013 Share Posted April 3, 2013 That means the query failed. Use mysql_error to find out why. Quote Link to comment https://forums.phpfreaks.com/topic/276465-count-coding-is-working-in-localhost-but-in-000webhost-i-get-error/#findComment-1422592 Share on other sites More sharing options...
exeTrix Posted April 3, 2013 Share Posted April 3, 2013 (edited) I think you'll need to check to make sure that the result set is not empty before calling that function. Normally though the error will also include "boolean given" (false). So try this: if( empty( $profile ) ){ echo 'No results found'; }else{ //do whatever here with your results } As requinix said it could be to do with your connection in the include. Although I'd expect it to fail on mysql_query. Sorry for my uncertainty I'm used to PDO. Edited April 3, 2013 by exeTrix Quote Link to comment https://forums.phpfreaks.com/topic/276465-count-coding-is-working-in-localhost-but-in-000webhost-i-get-error/#findComment-1422593 Share on other sites More sharing options...
requinix Posted April 3, 2013 Share Posted April 3, 2013 I think you'll need to check to make sure that the result set is not empty before calling that function. Normally though the error will also include "boolean given" (false). So try this: if( empty( $profile ) ){ echo 'No results found'; }else{ //do whatever here with your results } As long as the query worked, $profile will be set to something. empty($profile) won't tell you if there were any results, and you won't get an error trying to fetch from a (successful) resultset even if it's empty. Quote Link to comment https://forums.phpfreaks.com/topic/276465-count-coding-is-working-in-localhost-but-in-000webhost-i-get-error/#findComment-1422598 Share on other sites More sharing options...
Spraban9 Posted April 4, 2013 Author Share Posted April 4, 2013 (edited) I think you'll need to check to make sure that the result set is not empty before calling that function. Normally though the error will also include "boolean given" (false). So try this: if( empty( $profile ) ){ echo 'No results found'; }else{ //do whatever here with your results } As requinix said it could be to do with your connection in the include. Although I'd expect it to fail on mysql_query. Sorry for my uncertainty I'm used to PDO. this coding is not counting but it working localhost <?php include("include/connection.php"); $profile= mysql_query("SELECT count( user )FROM (SELECT user FROM computerrepair UNION ALL SELECT user FROM computersale UNION ALL SELECT user FROM hospital UNION ALL SELECT user FROM hotel UNION ALL SELECT user FROM house UNION ALL SELECT user FROM land UNION ALL SELECT user FROM mobile UNION ALL SELECT user FROM theater UNION ALL SELECT user FROM upload UNION ALL SELECT user FROM vechicle) AS a WHERE user = '$login_session'",$conn); if( $profile ){ $menus=mysql_fetch_assoc($profile); $noof=$menus['count( user )']; }else{ //do whatever here with your results $noof= '0'; } ?> Edited April 4, 2013 by Spraban9 Quote Link to comment https://forums.phpfreaks.com/topic/276465-count-coding-is-working-in-localhost-but-in-000webhost-i-get-error/#findComment-1422809 Share on other sites More sharing options...
Spraban9 Posted April 4, 2013 Author Share Posted April 4, 2013 (edited) Error SQL query: b_help.png SELECT count( user ) FROM ( SELECT user FROM computerrepair UNION ALL SELECT user FROM computersale UNION ALL SELECT user FROM hospital UNION ALL SELECT user FROM hotel UNION ALL SELECT user FROM house UNION ALL SELECT user FROM land UNION ALL SELECT user FROM mobile UNION ALL SELECT user FROM theater UNION ALL SELECT user FROM upload UNION ALL SELECT user FROM vechicle ) AS a WHERE user = 'mathu' MySQL said: b_help.png #1054 - Unknown column 'user' in 'field list' same database like the localhost have but in 000webhost phpmyadmin display this error to this query Edited April 4, 2013 by Spraban9 Quote Link to comment https://forums.phpfreaks.com/topic/276465-count-coding-is-working-in-localhost-but-in-000webhost-i-get-error/#findComment-1422810 Share on other sites More sharing options...
trq Posted April 4, 2013 Share Posted April 4, 2013 The error is pretty self explanatory. You should learn to format better questions if you want better answers. Quote Link to comment https://forums.phpfreaks.com/topic/276465-count-coding-is-working-in-localhost-but-in-000webhost-i-get-error/#findComment-1422832 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.