Page 1 of 1

No results

Posted: Tue Jan 17, 2006 12:08 am
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

Posted: Tue Jan 17, 2006 2:31 am
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.

Posted: Tue Jan 17, 2006 3:04 am
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?