Jump to content

Why does my if statement fire improperly!


iPixel

Recommended Posts

Unless i'm mistaken, the part within the IF statement should only occur if $table_res['Field'] is found within $data but instead it pushes to the array no matter what!

 

#Read the file that was just uploaded for use
	$csvfile = "csv/datafile.csv";
	$fh = fopen($csvfile,"r")  or die("Could not open rename.csv file !");

	#GET ALL THE FIELDS WITHIN THE TABLE STRUCTURE
	#USE IT TO COMPARE AGAINST THE COLUMNS IN THE CSV FILE
	#MAP WHICH COLUMN BELONGS TO WHAT FIELD

	$tbls_sql = "SHOW COLUMNS FROM $tablename";
	$tbls_qry = mysql_query($tbls_sql) or die(mysql_error());

	$fieldarray = array();
	$keyarray = array();
	$data = fgetcsv($fh);

	while($tbls_res = mysql_fetch_assoc($tbls_qry))
		{
			#echo $tbls_res['Field'] . "<BR>";

			if($getkey = array_search($tbls_res['Field'],$data))
				{	
					array_push($fieldarray,$tbls_res['Field']);
					array_push($keyarray,$getkey);
				}
			else
				{
					echo "";
				}

		}

Link to comment
Share on other sites

Ok, i'm pretty new to this, but it seems like you are trying to perform an IF test and define a variable in the same line.

 

See if the following makes sense.

 

Perform the test, then if TRUE, define the $getkey variable?

 

if(array_search($tbls_res['Field'],$data))					{							$getkey = $tbls_res['Field'];
array_push($fieldarray,$tbls_res['Field']);						array_push($keyarray,$getkey);					}				else					{						echo "";					}						}

Link to comment
Share on other sites

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.