Jump to content

[SOLVED] Same script works on one page and not another


zhangy

Recommended Posts

Hi, I may have been staring at this too long but I have this script below that works fine on my homepage but does not work on another page that is in the same directory as the homepage.  :wtf:

 

I get this error: Unknown column 'col_2' in 'field list'

<?php

require_once('load_data.php');

$result = mysql_query("SELECT DISTINCT(col_2) FROM $table ORDER BY submission_id DESC LIMIT 6")or die(mysql_error());
$Check = "";
$i = 0;

while($row = mysql_fetch_array($result))
{

	if(($i%2) == 0 ) {
	   $class = 'even';
	   }else{
	   $class = 'odd';
	   }

	if(!in_array($row['col_2'], $Check)) {
            $Check[] = $row['col_2'];
            $subject = $row['col_2'];
		echo "<li class=\"{$class}\">";
		echo '<a href="employer.php?id='.urlencode($subject).'" class="job_link" title="recent posts by '.$row['col_2'].'">'.$row['col_2'].'</a>';
		echo "</li>";

		$i++;
	}
}
mysql_free_result($result);
?>

yeah, $table is set in the load_data.php file. but I also tried defining it in the page instead of using require_once and received the same error. I dont know, Ill have to play around with it some more and hopefully the answer will present itself.

I generally do not advocate echoing variables directly into a query statement (for many reasons), my guess is that $table does not contain what you think it contains, when you're using the script on the page that it does not work on.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.