coppermine-gallery.com/forum

Support => cpg1.3.x Support => Older/other versions => cpg1.3 Installation & Setup => Topic started by: isa150183 on July 15, 2005, 01:13:18 PM

Title: Connect in a different page ?
Post by: isa150183 on July 15, 2005, 01:13:18 PM
Hello,  sorry for my english, i'm french !

I have done a webpage with this to have the theme.
How can i do to connect the database in this page ?


<?php

define
('IN_COPPERMINE'true);
require(
'include/init.inc.php');
pageheader('titre');
?>



<?php
[b]
//HERE IS IT OK OR DOES IT EXIST A BEST CODE ?
$db mysql_connect('IP''Base''passe')  or die('Erreur de connexion '.mysql_error());
mysql_select_db('base',$db)  or die('Erreur de selection '.mysql_error()); 
[/
b]
$sql 'SELECT .... desc limit 5'

// on envoie la requête 
$req mysql_query($sql) or die('Erreur SQL !<br>'.$sql.'<br>'.mysql_error()); 

// on fait une boucle qui va faire un tour pour chaque enregistrement 
echo "<br><br><b>Liste  : </b><br><br>";
while(
$data mysql_fetch_assoc($req)) 
    { 
    
// on affiche les informations de l'enregistrement en cours 
    
echo '<b>'.$data['nom'].' '.$data['prenom'].'</b> ('.$data['nomconcours'].')'
    echo 
' <i>date : '.$data['date'].'</i><br>'
    } 
?>


<?php

pagefooter
();
?>



Thank you for all !!
Title: Re: Connect in a different page ?
Post by: Abbas Ali on July 15, 2005, 02:23:14 PM
There is no need to connect to the database if the database is same as cpg's database.  The connection already stands established since you are including init.inc.php in your script. You can directly use db_query() function to fire the query and fetch the results using mysql_fetch_row or other some other function.
Title: Re: Connect in a different page ?
Post by: isa150183 on July 18, 2005, 02:22:07 PM
Thank you i will try
Title: Re: Connect in a different page ?
Post by: isa150183 on July 26, 2005, 11:49:31 AM
Can you post the code i have to put on my first code here ?
thank you a lot !!
Title: Re: Connect in a different page ?
Post by: Abbas Ali on July 26, 2005, 12:50:32 PM
The code below is useful only if the table from which u are trying to retrieve the data and the cpg tables are in same database


<?php

define
('IN_COPPERMINE'true);
require(
'include/init.inc.php');
pageheader('titre');

$sql 'SELECT .... desc limit 5';

// on envoie la requête
$req db_query($sql);

// on fait une boucle qui va faire un tour pour chaque enregistrement
echo "<br><br><b>Liste  : </b><br><br>";
while(
$data mysql_fetch_assoc($req))
    {
    
// on affiche les informations de l'enregistrement en cours
    
echo '<b>'.$data['nom'].' '.$data['prenom'].'</b> ('.$data['nomconcours'].')';
    echo 
' <i>date : '.$data['date'].'</i><br>';
    }
?>


<?php

pagefooter
();
?>

Title: Re: Connect in a different page ?
Post by: isa150183 on July 27, 2005, 06:06:28 PM
Thank you very much, that is exactly that i want !
thanks a lot