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); ?> Link to comment https://forums.phpfreaks.com/topic/166225-solved-same-script-works-on-one-page-and-not-another/ 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? Link to comment https://forums.phpfreaks.com/topic/166225-solved-same-script-works-on-one-page-and-not-another/#findComment-876582 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. Link to comment https://forums.phpfreaks.com/topic/166225-solved-same-script-works-on-one-page-and-not-another/#findComment-876837 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). Link to comment https://forums.phpfreaks.com/topic/166225-solved-same-script-works-on-one-page-and-not-another/#findComment-876845 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. Link to comment https://forums.phpfreaks.com/topic/166225-solved-same-script-works-on-one-page-and-not-another/#findComment-876859 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.