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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.