Jump to content

count coding is working in localhost but in 000webhost i get error


Spraban9

Recommended Posts

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

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.

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.

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';
}

 ?>

 

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.