Advanced search  

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Pages: [1]   Go Down

Author Topic: MySQL query help  (Read 3139 times)

0 Members and 1 Guest are viewing this topic.

paulpalmer1983

  • Coppermine newbie
  • Offline Offline
  • Posts: 8
MySQL query help
« on: March 21, 2005, 04:08:06 pm »

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.
Logged

kegobeer

  • Dev Team member
  • Coppermine addict
  • ****
  • Offline Offline
  • Gender: Male
  • Posts: 4637
  • Beer - it does a body good!
    • The Kazebeer Family Website
Re: MySQL query help
« Reply #1 on: March 21, 2005, 07:50:14 pm »

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.
Logged
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

  • Coppermine newbie
  • Offline Offline
  • Posts: 8
Re: MySQL query help
« Reply #2 on: March 22, 2005, 12:16:36 pm »

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
Logged

kegobeer

  • Dev Team member
  • Coppermine addict
  • ****
  • Offline Offline
  • Gender: Male
  • Posts: 4637
  • Beer - it does a body good!
    • The Kazebeer Family Website
Re: MySQL query help
« Reply #3 on: March 22, 2005, 12:51:51 pm »

Post your query here.
Logged
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

  • Coppermine newbie
  • Offline Offline
  • Posts: 8
Re: MySQL query help
« Reply #4 on: March 22, 2005, 01:05:58 pm »

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

jpaffett

  • Contributor
  • Coppermine novice
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 38
    • Lesvosisland.com
Re: MySQL query help
« Reply #5 on: March 22, 2005, 03:04:02 pm »

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

Code: [Select]
<?

$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

  • Coppermine newbie
  • Offline Offline
  • Posts: 8
Re: MySQL query help
« Reply #6 on: March 22, 2005, 03:24:10 pm »

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
Logged

kegobeer

  • Dev Team member
  • Coppermine addict
  • ****
  • Offline Offline
  • Gender: Male
  • Posts: 4637
  • Beer - it does a body good!
    • The Kazebeer Family Website
Re: MySQL query help
« Reply #7 on: March 22, 2005, 04:36:00 pm »

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.
Logged
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
Pages: [1]   Go Up
 

Page created in 0.025 seconds with 20 queries.