No results

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
elAdi
Forum Newbie
Posts: 4
Joined: Tue Nov 22, 2005 7:09 pm
Location: Perth, Australia

No results

Post by elAdi »

Hi all,

I'm usually using ColdFusion and am still a bit shaky with my php. Hope somebody can help me with this.

I have a MySql DB and there are two sets of data in there, but when try to retrieve the data, I get no results. The data would be used to create the layout dynamically. So the site loads (no error messages on the 'or die' comands, so connection to the DB should work), but the CSS functionality doesn't work.
I tried a var_dump, this is the outcome:

NULL resource(4) of type (mysql result) NULL NULL NULL NULL

This is the code I have (the connectivity data is excluded here...). Does anybody see an error on this?

Code: Select all

<?
$JapWholesaleDB = mysql_pconnect($hostname_JapWholesaleDB, $username_JapWholesaleDB, $password_JapWholesaleDB) or trigger_error(mysql_error(),E_USER_ERROR); 

mysql_connect($hostname_JapWholesaleDB, $username_JapWholesaleDB, $password_JapWholesaleDB)
	or die( "Error! Could not connect to database: " . mysql_error() );
mysql_select_db($database_JapWholesaleDB)
	or die( "Error! Could not select the database: " . mysql_error() );
$query = mysql_query("SELECT * FROM jap_page_templates");
var_dump($row_query );
var_dump($query );
	while ($row_query = mysql_fetch_object($query))
		{
			$colour_primary = $row['temp_col_primary'];			
			$colour_nav = $row['temp_col_secondary'];			
			$temp_image = $row['temp_image'];			
			$temp_status = $row['$temp_status'];
		}
var_dump($colour_primary);
var_dump($colour_nav);
var_dump($temp_image);
var_dump($temp_status);		
include("inc_css.css");
mysql_close(); ?>
Thanks for the help.
Adrian
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

It loks like you are creating two connections. The first mysql_pconnect() returns a connection ID that you put in a var. The second mysql_connect() then connects and become the "current" connection. You then select the database with the first connection, but all for the following calls will use the second connection.
User avatar
Wayne
Forum Contributor
Posts: 339
Joined: Wed Jun 05, 2002 10:59 am

Post by Wayne »

well its rather early in the morning but try this ... (might have missed some stuff!)

Code: Select all

<? 
$JapWholesaleDB = mysql_pconnect($hostname_JapWholesaleDB, $username_JapWholesaleDB, $password_JapWholesaleDB) or trigger_error(mysql_error(),E_USER_ERROR); 

mysql_connect($hostname_JapWholesaleDB, $username_JapWholesaleDB, $password_JapWholesaleDB) 
   or die( "Error! Could not connect to database: " . mysql_error() ); 
mysql_select_db($database_JapWholesaleDB) 
   or die( "Error! Could not select the database: " . mysql_error() ); 
$query = mysql_query("SELECT * FROM jap_page_templates"); 
   while ($row_query = mysql_fetch_array($query)) 
      { 
         $colour_primary = $row_query['temp_col_primary'];          
         $colour_nav = $row_query['temp_col_secondary'];          
         $temp_image = $row_query['temp_image'];          
         $temp_status = $row_query['temp_status']; 

         echo $colour_primary; 
         echo $colour_nav; 
         echo $temp_image; 
         echo $temp_status;       
      } 
include("inc_css.css"); 
mysql_close(); 
?>
you also seem to be opening a connection to the same database twice?
Post Reply