Member Avatar for Borderline

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"

$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?

I would use the following code:

<?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);
  }
}

?>

Also use "LIMIT 0,15"

Try using this code:

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

Member Avatar for Borderline

Really sorry, it hasn't worked. Error message: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/fhlinux177/e/equinefocus.co.uk/user/htdocs/personal/gallery.php on line 25

Your not selecting a database in your code.

Try adding

mysql_select_db('databasename');

Be sure that your column names are correct, including capitalization, and that the table name is correct. You can also do a SELECT * FROM others; for testing until you figure out what the problem is.

Member Avatar for Borderline

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.

replace your while loop with this:

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.

Member Avatar for Borderline

Another step forward - thank you!

Result: http://www.equinefocus.co.uk/personal/gallery.php

gallery.php code:
http://www.equinefocus.co.uk/personal/gallery.pdf

gallery_template.htm code:
http://www.equinefocus.co.uk/personal/gallery_template.pdf

My issue now, is the error message at the bottom of the gallery.php page, and also the thumbnail issues, which is presumably caused by the template.htm page.

This was the code given to me in another forum, but I don't know how to make the two pages interact correctly. I am assuming the [REF] etc sections are causing the problems, but don't know what they are supposed to be replaced with to pull the relevant info from the database. Any thoughts?

Many thanks for assisting this bumbling amateur - it was given to me as a simple solution for what I wanted, but I'm not finding it that at this stage!



HI AGAIN


';

$template_bottom = '


- - -

Our company

e-mail: [email]x@y.com[/email]

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.