zhangy Posted July 16, 2009 Share Posted July 16, 2009 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. 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); ?> Quote Link to comment Share on other sites More sharing options...
akitchin Posted July 16, 2009 Share Posted July 16, 2009 the most likely cause of the error is that $table is not being defined in the page that it isn't working on. is $table being set before the script, or is it being set in load_data.php? Quote Link to comment Share on other sites More sharing options...
zhangy Posted July 17, 2009 Author Share Posted July 17, 2009 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. Quote Link to comment Share on other sites More sharing options...
akitchin Posted July 17, 2009 Share Posted July 17, 2009 two quick tips: 1. echo the query to see what it's trying to run, in case it isn't what you expect, and 2. make sure you didn't commit a typo when you defined the table (ie. check that it is named col_2). Quote Link to comment Share on other sites More sharing options...
phporcaffeine Posted July 17, 2009 Share Posted July 17, 2009 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.