Hi..

I'm having problem with my website, and I just cannot figure it out what's the problem with my code. Any ideas?
Thanks.

// get related files from database
	if ($settings['related_files'] == 1) {
		$related_query = mysql_query('SELECT f.fileid, f.title, f.description, f.icon, f.iconlocation, f.timesplayed from '. $tbl_prefix .'related AS r JOIN '. $tbl_prefix .'files AS f ON (f.fileid = r.related_id) WHERE r.file_id = '. $file['id'] .' LIMIT '. $settings['max_related_files']);

		// find new related files
		if (mysql_num_rows($related_query) == 0 && strpos($file_row['keywords'], " ") !== false) {
			mysql_free_result($related_query);

			$related_query = mysql_query("SELECT fileid, title, description, icon, iconlocation, timesplayed
				FROM ". $tbl_prefix ."files USE INDEX (search)
				WHERE MATCH(title, description, keywords) AGAINST('". escape_string(str_replace(',', '', $file_row['keywords'])) ."') AND status = '1' AND fileid != ". $file['id'] ." LIMIT ". $settings['max_related_files']); 

			$save_related = true;
		} else {
			$save_related = false;
		}

		$txt['related'] = array();
		while ($related_row = mysql_fetch_assoc($related_query)) {
			$txt['related'][] = array (
	'id'	=>	$related_row['fileid'],
	'title'	=>	$related_row['title'],
	'url'	=>	fileurl($related_row['fileid'],$related_row['title']),
	'description'	=>	shorten_description($related_row['description']),
	'image'	=>	file_image_url($related_row['icon'], $related_row['iconlocation']),
	'played'		=>	$related_row['timesplayed']
);
		}
		mysql_free_result($related_query);
		$settings['related_files'] = !empty($txt['related']); // do not show if empty

		// save found related files
		if ($save_related && $settings['related_files']) {
			$related_sql = array();
			foreach ($txt['related'] AS $val) {
				$related_sql[] = '('. $file['id'] .', '. $val['id'] .')';
			}
			mysql_query('INSERT INTO '. $tbl_prefix .'related (file_id,related_id) VALUES '. implode(',', $related_sql));
		}
	}

Recommended Answers

All 4 Replies

for starters you need to make a call to 'mysql_connect' in order to get a connection to your database.

$connection = mysql_connect( 'localhost', 'user', 'secret_password' );

and then '$connection' would be your mysql resource that your would use in 'mysql_free_result'.

hope this was helpful.

my guess is that $related_query not succseful and is null or something.
check the query in the DB and see what result u get.
and try to print_r $related_query before the while loop and see what it containts

you can use something like to find out whats wrong

$related_query = mysql_query(' your query here' )or die( mysql_error());

Hi. Thanks for your help. EricIskhakov had the solution. I checked the query in my Database, and I saw that some lines were in plus. I deleted those entries and now it's working like charm. Thank you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.