473,466 Members | 1,619 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource

38 New Member
I am connecting to my database using Object oriented PHP. My query is returning results but at the end of my table,at the bottom of the page I keep having this error when I run my program: Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\mysql_class_2.php on line 45.

Can anyone help me?

The following is my PHP class:

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. class mysql {
  3. ////////////////////////////////////////////////////////////////
  4. function Connect($host, $name, $pass, $db){
  5. $connection = mysql_connect("$host","$name","$pass");
  6. mysql_select_db("$db", $connection);
  7. }//ends the connection function
  8. ///////////////////////////////////////////////////////////////
  9. function Close(){
  10. mysql_close($this->connection);
  11. }//ends the close function
  12. //////////////////////////////////////////////////////////////
  13. function FetchRow($query){
  14. $rows = mysql_fetch_row($query);
  15. return $rows;
  16. }
  17. ////////////////////////////////////////////////////////////
  18. function FetchArray($query){
  19. $array = mysql_fetch_array($query);
  20. return $array;
  21. }
  22. ///////////////////////////////////////////////////////////
  23. function FetchNum($query){
  24. while ($num = mysql_num_rows($query));
  25. return $num;
  26. }
  27. ////////////////////////////////////////////////////////////////
  28. function Query($sql){
  29. $query = mysql_query($sql) or die(mysql_error());
  30. return $query;
  31. }//ends the query function
  32. ///////////////////////////////////////////////////////////////////////////////
  33. function FetchAssoc($query2){
  34. $array = mysql_fetch_assoc($query2);
  35. return $array;
  36. }
  37. ///////////////////////////////////////////////////////////////////////////////
  38. function TanimotoSimilarity($query,$input_arrays) {
  39. $i=0;
  40. $row= array();
  41. while( $row=mysql_fetch_assoc($query) )
  42. {
  43. $first[$i]=(count(array_intersect($row,$input_arrays)))/(count($row)+count($input_arrays)-count(array_intersect($row,$input_arrays)));
  44. $i++;
  45. }
  46. return($first);
  47.  
  48. }
  49. ///////////////////////////////////////////////////////////////////////////////////
  50. }//ends the class
  51. ?>
  52.  
On the code above Mysql_fetch_asson function is on line 33.

Thanks
Jan 8 '09 #1
2 16959
Atli
5,058 Recognized Expert Expert
Hi.

You get that warning when you try to fetch rows from a variable that is not a MySQL query resource.
(A MySQL query resource is the return value of a successful mysql_query call)

To avoid it, you need to make sure that the parameter you are passing it is in fact a valid resource. This usually works fine:
Expand|Select|Wrap|Line Numbers
  1. if($resource and !is_bool($resource)) {
  2.   $row = mysql_fetch_assoc($resource);
  3. }
When a mysql_query call fails, it returns FALSE, or in the case of successful queries that do not return a result set, TRUE.

P.S.
What's with the while loop on line 24?
Jan 8 '09 #2
poreko
38 New Member
The while loop in line 24 is my mistake. It was just me trying something out.
Jan 8 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: petemaxi | last post by:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\Program Files\xampp\htdocs\tockholes\includes\menu.inc.php on line 9 <div class="left"> <div class="menu">...
11
by: Breana | last post by:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/breana/public_html/category.php on line 88 ------------------------------------------- It does this...
3
by: chri | last post by:
hi i get the following errors returning me folloing post to data base Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\Documents and Settings\chris1\My...
5
by: Mubs | last post by:
Hi, I 'am trying to connect my sql database with my webpage for users log in. i have got this script so far but i keep getting the following error message which i cannot figure out.. could any1...
4
by: fisherd | last post by:
When i run this code, i keep getting this message; Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\wamp\www\checklogin.php on line 26 i use this code to...
4
by: kalyanip14 | last post by:
Hi I am new to Php.I am trying to read My sql database data from table to php. I am getting this warning Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource ...
1
mideastgirl
by: mideastgirl | last post by:
What does this error mean? Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/content/m/i/d/mideasthonors/html/student_session_proposal_success.php on...
2
by: macdalor | last post by:
Hi! I'm completely new to all dev and trying to put a website together using MySQLI and PHP; was running fine until I try to gather the DB content with the following script: <?...
9
by: Cxsey | last post by:
I get the following error code using this code: "Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource" It's on line 55 in this php script: <?php /** *...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.