MySQL query help MySQL query help
 

News:

CPG Release 1.6.26
Correct PHP8.2 issues with user and language managers.
Additional fixes for PHP 8.2
Correct PHP8 error with SMF 2.0 bridge.
Correct IPTC supplimental category parsing.
Download and info HERE

Main Menu

MySQL query help

Started by paulpalmer1983, March 21, 2005, 04:08:06 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

paulpalmer1983

Hi,

I am currently designing a wedding album site, i've got plenty of time to develop it so no rush, just would like to get the bulk of it done so i can propely test it. Plus it will give me time to beef up my home server to power it.

Anyway, I'm just working on the frontpage, for various reasons this is not the index.php of coppermine. I would like to intergrate certain features, such as the gallery name as specified in the config page. My mysql skills are pretty weak at the moment, better, what I'm asking is how I run a query to get this information into a variable so i can use it to propogate the page title. I ideally need to draw various bits of information from various tables, but I could do with a hand. Anyhelp with this query would be appreciated.

Thanks.

kegobeer

Well, I'd start out with an include statement for config.inc.php and functions.inc.php.  That gives you the MySQL connection string and the functions needed to query the database.  Then you can write queries that pull whatever data you want.  Just look at the init.inc.php file for examples of the $CONFIG array, which contains the basic gallery configuration information: title, description, etc.  You will have to look at the various php files to see how the other data is queried, sorted, added, deleted, etc.

If you are looking to display images on your index page, you should instead look at the cpgfetch and other mods.  They are designed to interface with your gallery and grab pictures.
Do not send me a private message unless I ask for one.  Make your post public so everyone can benefit.

There are no stupid questions
But there are a LOT of inquisitive idiots

paulpalmer1983

Hi, thanks for the help. I'm still having a little trouble.

I think i've got the includes right, I've added them just as normal php includes

as <?php include("photoAlbum/include/config.inc.php"> and
<?php include("photoAlbum/include/functions.inc.php">

however no matter what I try I can't get any queries to return what I want. I am to start off with just trying to retrieve the gallary title from the cpg132_config table so I can use it in my non coppermine index page. I seem to be hitting a brick wall with this one. I would be really appreciative if someone could help me with maybe an example of how to do this, as once i can see how it is done once I should be able to pick it up, I have plenty of programming experince, just not php and mysql just doesnt like me!

Thanks

kegobeer

Do not send me a private message unless I ask for one.  Make your post public so everyone can benefit.

There are no stupid questions
But there are a LOT of inquisitive idiots

paulpalmer1983

$DBhost = "localhost";
$DBuser = "root";
$DBpass = "test";
$DBName = "palbum";
$table = "cpg132_config";

mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable toconnect to database");
@mysql_select_db("$DBName") or die("Unable to select database $DBName"); $sqlquery = "SELECT name FROM $table WHERE name = 'albums_per_page'";

am actually trying to extract the gallery title but was using albums_per_page as a test

jpaffett

This snippet should show you how to do what you want:

<?

$DBhost = "localhost";
$DBuser = "root";
$DBpass = "test";
$DBName = "palbum";
$table = "cpg132_config";

mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable toconnect to database");
@mysql_select_db("$DBName") or die("Unable to select database $DBName");
$sqlquery = "SELECT name FROM $table WHERE name = 'albums_per_page'";

$q = mysql_query($sqlquery);

$row = mysql_fetch_row($q);

echo $row[0];

?>


Really though you need to study up on PHP and MySQL. as this forum isn't a PHP training course.

Jeff

paulpalmer1983

Thanks! I've got it working now. Sorry for asking, but I've been pulling my hair out over this. I code VB and Java, never mastered php though.

Thanks for the help

kegobeer

The reason I told you to include those files is you could then use the Coppermine functions to connect to your database and query the database.  If you don't use Coppermine functions, don't bother including functions.inc.php.

That's also why I told you to look at the different Coppermine files: you'd see how the cpg_db_connect, db_query, and db_fetch_rowset functions are used.
Do not send me a private message unless I ask for one.  Make your post public so everyone can benefit.

There are no stupid questions
But there are a LOT of inquisitive idiots