The Little Guy Posted July 26, 2011 Share Posted July 26, 2011 I can not get this method to work. When I get to while($buffer = fgets($handle) !== false){ when I dump my buffer, All I get is bool(true). Everything before the while loop works, but the while does not. Any Ideas why? - Line 1 contains the column names - Line 2+ contains my data I want to save. - The file is a CSV - $this->GetStateValue is a session of the file string: "../data/forms/myfile.csv". public function ocd_view(){ $location = $this->GetStateValue("authorize_fraud_file"); $handle = fopen($location, 'rb'); $line1 = fgets($handle); $line1 = preg_replace("/ |\/|-/", "", $line1); $items = explode(",", $line1); $tbl_cols = ""; $tbl_cols_sel = ""; foreach($items as $item){ $tbl_cols .= $this->enc($item)." char(100),"; $tbl_cols_sel .= $this->enc($item).","; } $tbl_cols = trim($tbl_cols,","); $tbl_cols_sel = trim($tbl_cols_sel,","); $this->db->ExecuteSql("create temporary table authorize_credit_card_fraud ($tbl_cols);"); while($buffer = fgets($handle) !== false){ var_dump($buffer); $items = explode(",",$buffer); $tbl_rows = ""; foreach($items as $item){ $tbl_rows .= "'".$this->enc($item)."',"; } $tbl_rows = trim($tbl_rows,","); echo $tbl_rows."<br>"; $this->db->ExecuteSql("insert into authorize_credit_card_fraud ($tbl_cols_sel) values ($tbl_rows)"); //echo count($items)."<br>"; } $sql = $this->db->ExecuteSql("select m.member_id, concat(first_name, ' ', last_name) as full_name from authorize_credit_card_fraud accf left join members m on (accf.CustomerID = m.member_id) where accf.CustomerFirstName != m.first_name and accf.CustomerLastName != m.last_name"); echo mysql_error(); $i = 1; echo "<a href='./csv_fraud.php'>Again</a>"; while($row = mysql_fetch_assoc($sql)){ echo $i.". ".$row['full_name']."<br />"; $i++; } } Quote Link to comment https://forums.phpfreaks.com/topic/242850-fgets-returns-bool/ Share on other sites More sharing options...
PFMaBiSmAd Posted July 26, 2011 Share Posted July 26, 2011 You are missing some () to force the correct operator precedence. The !== has higher precedence than the = and the fgets($handle) !== false is evaluated before the = assignment) - while(($buffer = fgets($handle)) !== false){ Quote Link to comment https://forums.phpfreaks.com/topic/242850-fgets-returns-bool/#findComment-1247340 Share on other sites More sharing options...
The Little Guy Posted July 26, 2011 Author Share Posted July 26, 2011 ahh!! I missed that! I guess copy and paste is better Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/242850-fgets-returns-bool/#findComment-1247345 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.