Hi,
I come from a background in C and sed/awk/unix so please be patient with me 🙂
I am trying to make the code I have written more robust, and more modular so that I can re-use many elements (and hopefully speed things up).
I tend to do design in Dreamweaver, and then once happy with the layout/template - I use dreamweaver to create connections etc to the DB so that I can print out records and repeating regions. I then use text editors to "improve" the php to the extent of my knowledge.
That siad, I am now trying to make a function that simply retruns a filename from a database......
One thing that I can't see to understand is the following function.
image_lib.php
require_once('../Connections/gall_db_con.php');
function get_last_image () {
mysql_select_db($database_gall_db_con, $gall_db_con);
$query_latest_image = "SELECT id, filename, image_name, protect, active FROM es_img_images WHERE protect = 'N' AND active = 'Y' ORDER BY es_img_images.filename DESC LIMIT 1";
$latest_image = mysql_query($query_latest_image, $gall_db_con) or die(mysql_error());
$row_latest_image = mysql_fetch_assoc($latest_image);
$totalRows_latest_image = mysql_num_rows($latest_image);
mysql_free_result($latest_image);
return ($row_latest_image['filename']);
}
now when I call the function as below, I get a raft of errors:
$a = get_last_image();
echo $a ;
Notice: Undefined variable: database_gall_db_con in E:\es_gallery\includes\image_lib.php on line 6
Notice: Undefined variable: gall_db_con in E:\es_gallery\includes\image_lib.php on line 6
Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in E:\es_gallery\includes\image_lib.php on line 6
Notice: Undefined variable: gall_db_con in E:\es_gallery\includes\image_lib.php on line 8
Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in E:\es_gallery\includes\image_lib.php on line 8
but yet when I include the following line as pasrt of the function
include('../Connections/gall_db_con.php');
it works 😕 now I undertsand how it works, a little - but I wish to create about 20 functions that all return different images from the database, I surely I don't need to use the include('../Connections/gall_db_con.php'); in each function?
would it also be possible to move the mysql_select_db to outside the function? becuase I only ever select the one database?
regards
StevenJ