Intranet Journal

Go Back   IT Management Forum > Intranet Journal

Intranet Journal The new discussion forum for Intranet Journal readers. Leave comments and questions for IJ authors. Suggest story ideas and provide feedback.

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-08-2009, 04:23 AM
UD2008 UD2008 is offline
Registered User
 
Join Date: Jan 2009
Posts: 3
mysql_fetch_array still has an error

Hi there, I've used the tutorial to create the basic for an intranet, but I keep getting an error. I know others had that problem aswell, I've looked through the forum for a solution but nothing works. All the solutions are solved (I checked the code and nothing seems wrong).

The error I get is this:
Code:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\intranet test\includes\DbConnector.php on line 50
So here I post the code I have:
DbConnector.php
Code:
<?php
////////////////////////////////////////////////////////////////////////////////////////
// Class: DbConnector
// Purpose: Connect to a database, MySQL version
///////////////////////////////////////////////////////////////////////////////////////
require_once ('SystemComponent.php');

class DbConnector extends SystemComponent {

var $theQuery;
var $link;

//*** Function: DbConnector, Purpose: Connect to the database ***
function DbConnector(){

	// Load settings from parent class
	$settings = SystemComponent::getSettings();

	// Get the main settings from the array we just loaded
	$host = $settings['dbhost'];
	$db = $settings['dbname'];
	$user = $settings['dbusername'];
	$pass = $settings['dbpassword'];

	// Connect to the database
	$this->link = mysql_connect($host, $user, $pass);
	mysql_select_db($db);
	register_shutdown_function(array(&$this, 'close'));

}

//*** Function: query, Purpose: Execute a database query ***
function query($query) {
	$this->theQuery = $query;
	return mysql_query($query, $this->link);
}

//*** Function: getQuery, Purpose: Returns the last database query, for debugging ***
function getQuery() {
	return $this->theQuery;
}

//*** Function: getNumRows, Purpose: Return row count, MySQL version ***
function getNumRows($result){
	return mysql_num_rows($result);
}

//*** Function: fetchArray, Purpose: Get array of query results ***
function fetchArray($result) {
	return mysql_fetch_array($result);
}

//*** Function: close, Purpose: Close the connection ***
function close() {
	mysql_close($this->link);
}


}
?>
Here the viewarticles.php:
Code:
<?php
// Require the database class
require_once('includes/DbConnector.php');

// Create a new DbConnector object
$connector = new DbConnector();

// IMPORTANT!!! Validate the ID number. See next article

// Execute the query to retrieve the selected article
$result = $connector->query('SELECT title,thearticle FROM cmsarticles WHERE ID = '.$_GET['id']);

// Get an array containing the resulting record
$row = $connector->fetchArray($result);

?>

Your selected article: <?php echo $row['title,tagline'];?>
<br><br>
<?php echo $row['thearticle'];?>
Here is the SystemComponent.php:
Code:
<?php
class SystemComponent {

var $settings;

function getSettings() {

// System variables
$settings['siteDir'] = '../intranet%20test/';

// Database variables
$settings['dbhost'] = 'localhost';
$settings['dbusername'] = 'root';
$settings['dbpassword'] = '';
$settings['dbname'] = 'intratest';

return $settings;

}

}
?>
Hope someone can help me with this problem.
Reply With Quote
  #2 (permalink)  
Old 01-08-2009, 09:01 AM
UD2008 UD2008 is offline
Registered User
 
Join Date: Jan 2009
Posts: 3
Just for furture information:

I use:
PHP: 5.2.8
MySQL: 5.1.30
Reply With Quote
  #3 (permalink)  
Old 01-09-2009, 02:10 AM
UD2008 UD2008 is offline
Registered User
 
Join Date: Jan 2009
Posts: 3
Thumbs up

I found the solution, in the index.php.

Code:
// Execute the query to retrieve articles
$result = $connector->query('SELECT ID,title FROM intraarticles ORDER BY ID DESC LIMIT 0,5');
The part FROM intraarticles, was cmsarticles, when I changed it to intraarticles (the name of my table) the problem was gone.
Reply With Quote
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -5. The time now is 03:30 PM.





Acceptable Use Policy

WebMediaBrands

internet.comMediabistrojusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Shopping | E-mail Offers

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.0.0