alanl1 Posted June 20, 2013 Share Posted June 20, 2013 Hi All I have a loop in php which loops through all the values from a previous page like so foreach ($_POST['textbox'] as $datanumcolumns=>$datadownboxValue){ echo "Textbox value" .$datanumcolumns. " has a value of " .$datadownboxValue. " "?><br /><?php } I also have a sql procedure which passes in variables of 1:csv file 2:table to be created and 3: column count from my loop as shown below $sql = "exec importspreadsheet " . "'" . $newfilename . "'," ."'" .$table_name."'," ."'" .$datanumcolumns."' "; from that within my sql procedure I iterate through the column count and create the database table which builds up a table like so while (@intflag < @column_count-3) begin set @midcolumns = 'colname' + cast(@intflag as nvarchar(2)) + ' nvarchar(max) null,'; set @middlecolumns = @middlecolumns + @midcolumns; set @intflag = @intflag +1; end this produces column1,column2,column3,column4 etc minus my first 3 standard column i have does anyone know if there is a way to pass the actual column values in so for instance if there were 6 columns it would pass in exec impostspreadsheet SPREADSHEETNAME, TABLENAME, Software Man,Product Name,Version Number,Part Number,Edition,Invoice Number the spreadsheet can change so if there were 5 columns then invoice number would not show I hope I make sense Quote Link to comment https://forums.phpfreaks.com/topic/279374-dynamic-procedure-variables/ Share on other sites More sharing options...
alanl1 Posted June 20, 2013 Author Share Posted June 20, 2013 I will try and make this a bit easier to understand My loop foreach ($_POST['textbox'] as $datanumcolumns=>$datadownboxValue){ $test = "exec importspreadsheet " . "'" . $newfilename . "'," ."'" .$table_name."'," ."'" .$datadownboxValue."' "; echo $test; //echo "Textbox value" .$datanumcolumns. " has a value of " .$datadownboxValue. " "?><br /><?php } creates exec importspreadsheet 'Synergy_SARnew.csv','newtable','Software Man'exec importspreadsheet 'Synergy_SARnew.csv','newtable','Product Name'exec importspreadsheet 'Synergy_SARnew.csv','newtable','Version Number'exec importspreadsheet 'Synergy_SARnew.csv','newtable','Part Number'exec importspreadsheet 'Synergy_SARnew.csv','newtable','Edition'exec importspreadsheet 'Synergy_SARnew.csv','newtable','Invoice Number'exec importspreadsheet 'Synergy_SARnew.csv','newtable','Supplier'exec importspreadsheet 'Synergy_SARnew.csv','newtable','Purchasing Officer' when I want it to loop through and create exec importspreadsheet 'Synergy_SARnew.csv','newtable','Software Man','Product Name','Version Number','Part Number','Edition','Invoice Number','Supplier','Purchasing Officer'hope this is more meaningful thanks Quote Link to comment https://forums.phpfreaks.com/topic/279374-dynamic-procedure-variables/#findComment-1436976 Share on other sites More sharing options...
Solution boompa Posted June 20, 2013 Solution Share Posted June 20, 2013 Wouldn't logic dictate that if you're seeing "exec importspreadsheet" on each row, and you only want to see it once, that that part of the string doesn't belong in the loop? SMH Quote Link to comment https://forums.phpfreaks.com/topic/279374-dynamic-procedure-variables/#findComment-1436996 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.