•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 375,225 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,225 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 751 | Replies: 10
![]() |
•
•
Join Date: Apr 2008
Posts: 18
Reputation:
Rep Power: 1
Solved Threads: 1
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource
#1
Apr 30th, 2008
Hi There
I'm a newcomer to php trying to develop a basic photo album. I have created a simple template in htm, and am trying to use php to show 15 thumbnails per page. However, I am experiencing the error message: "Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/fhlinux177/e/equinefocus.co.uk/user/htdocs/personal/gallery.php on line 26"
LINE 26 is while ($data = mysql_fetch_assoc($result)) {
Can anyone point me in the right direction with this problem, please? What is causing it, and how can I correct it?
I'm a newcomer to php trying to develop a basic photo album. I have created a simple template in htm, and am trying to use php to show 15 thumbnails per page. However, I am experiencing the error message: "Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/fhlinux177/e/equinefocus.co.uk/user/htdocs/personal/gallery.php on line 26"
$db = mysql_connect($hostname, $username, $password) or die ("Unable to connect to MySQL");
$sql = "SELECT url, thumb, ref, info FROM others LIMIT 15";
$result = mysql_query($sql, $db);
$table_template = file_get_contents($_SERVER['DOCUMENT_ROOT'].'/style/gallery_template.htm');
while ($data = mysql_fetch_assoc($result)) {
$mytable = $table_template;
foreach ($data as $key => $value) {
$mytable = str_replace("[".strtoupper($key)."]", $value, $mytable);
}
}
?>LINE 26 is while ($data = mysql_fetch_assoc($result)) {
Can anyone point me in the right direction with this problem, please? What is causing it, and how can I correct it?
Last edited by Borderline : Apr 30th, 2008 at 2:27 pm.
•
•
Join Date: Nov 2006
Location: South Wales
Posts: 159
Reputation:
Rep Power: 2
Solved Threads: 10
Re: Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource
#2
Apr 30th, 2008
I would use the following code:
php Syntax (Toggle Plain Text)
<?php $db = mysql_connect($hostname, $username, $password) or die ("Unable to connect to MySQL"); $sql = "SELECT url, thumb, ref, info FROM others LIMIT 15"; $result = mysql_query($sql); $table_template = file_get_contents($_SERVER['DOCUMENT_ROOT'].'/style/gallery_template.htm'); while ($data = mysql_fetch_assoc($result)) { $mytable = $table_template; foreach ($data as $key => $value) { $mytable = str_replace("[".strtoupper($key)."]", $value, $mytable); } } ?>
If you find my post useful please add to my reputation!! Thanks!
ajtrichards web solutions
http://www.ajtrichards.co.uk
ajtrichards web solutions
http://www.ajtrichards.co.uk
•
•
Join Date: Nov 2006
Location: South Wales
Posts: 159
Reputation:
Rep Power: 2
Solved Threads: 10
Re: Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource
#3
Apr 30th, 2008
Also use "LIMIT 0,15"
If you find my post useful please add to my reputation!! Thanks!
ajtrichards web solutions
http://www.ajtrichards.co.uk
ajtrichards web solutions
http://www.ajtrichards.co.uk
•
•
Join Date: Apr 2008
Posts: 18
Reputation:
Rep Power: 1
Solved Threads: 1
Re: Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource
#4
Apr 30th, 2008
Thanks for the prompt response.
The code now looks like this: http://www.equinefocus.co.uk/personal/gallery.pdf
I am getting the error message:
The code now looks like this: http://www.equinefocus.co.uk/personal/gallery.pdf
I am getting the error message:
•
•
•
•
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/fhlinux177/e/equinefocus.co.uk/user/htdocs/personal/gallery.php on line 25
•
•
Join Date: Nov 2006
Location: South Wales
Posts: 159
Reputation:
Rep Power: 2
Solved Threads: 10
Re: Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource
#5
Apr 30th, 2008
Try using this code:
Just replace your while statment with the one above.
Let me know how it goes!!
Regards,
Alex
php Syntax (Toggle Plain Text)
while ($data = mysql_fetch_array($result, MYSQL_ASSOC)) {
Just replace your while statment with the one above.
Let me know how it goes!!
Regards,
Alex
If you find my post useful please add to my reputation!! Thanks!
ajtrichards web solutions
http://www.ajtrichards.co.uk
ajtrichards web solutions
http://www.ajtrichards.co.uk
•
•
Join Date: Apr 2008
Posts: 18
Reputation:
Rep Power: 1
Solved Threads: 1
Re: Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource
#6
May 2nd, 2008
•
•
Join Date: Nov 2006
Location: South Wales
Posts: 159
Reputation:
Rep Power: 2
Solved Threads: 10
Re: Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource
#7
May 2nd, 2008
Your not selecting a database in your code.
Try adding
Try adding
php Syntax (Toggle Plain Text)
mysql_select_db('databasename');
If you find my post useful please add to my reputation!! Thanks!
ajtrichards web solutions
http://www.ajtrichards.co.uk
ajtrichards web solutions
http://www.ajtrichards.co.uk
Re: Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource
#8
May 2nd, 2008
•
•
Join Date: Apr 2008
Posts: 18
Reputation:
Rep Power: 1
Solved Threads: 1
Re: Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource
#9
May 3rd, 2008
Many thanks for your assistance - adding the line regarding the database removed the error message!
Unfortunately, now, I have a blank page, not the photo gallery I was hoping for. Does anyone have any theories on this?
http://www.equinefocus.co.uk/personal/gallery.pdf
I appreciate your help, thank you.
Unfortunately, now, I have a blank page, not the photo gallery I was hoping for. Does anyone have any theories on this?
http://www.equinefocus.co.uk/personal/gallery.pdf
I appreciate your help, thank you.
•
•
Join Date: Nov 2006
Location: South Wales
Posts: 159
Reputation:
Rep Power: 2
Solved Threads: 10
Re: Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource
#10
May 3rd, 2008
replace your while loop with this:
This should loop through the images and display them. Obviously edit the <IMG> tag to suit e.g width / height / border, etc.
php Syntax (Toggle Plain Text)
while ($data = mysql_fetch_array($result, MYSQL_ASSOC)) { echo '<img src="'.$row['url'].'" /><br/>'; }
This should loop through the images and display them. Obviously edit the <IMG> tag to suit e.g width / height / border, etc.
If you find my post useful please add to my reputation!! Thanks!
ajtrichards web solutions
http://www.ajtrichards.co.uk
ajtrichards web solutions
http://www.ajtrichards.co.uk
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
Similar Threads
- Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource (PHP)
- mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource (PHP)
- Newbie (PHP)
- dosent like query (PHP)
- while function and "mysql_fetch_assoc() not a valid MySQL result resource" (PHP)
Other Threads in the PHP Forum
- Previous Thread: update the rows in the database using the same form
- Next Thread: PHP MySQL 5.0 stored procedure


Linear Mode