Featured post

c# - Usage of Server Side Controls in MVC Frame work -

i using asp.net 4.0 , mvc 2.0 web application. project requiremrnt have use server side control in application not possibl in noraml case. ideally want use adrotator control , datalist control. i saw few samples , references in codepleax mvc controllib howwver found less useful. can tell how utilize theese controls in asp.net application along mvc. note: please provide functionalities related adrotator , datalist controls not equivalent functionalities thanks in advace. mvc pages not use normal .net solution makes use of normal .net components impossible. a normal .net page use event driven solution call different methods service side mvc use actions , view completly different way handle things. also, mvc not use viewstate normal .net controlls require. found article discussing mixing of normal .net , mvc.

php array data in mysql -


i new mysql , php. need put array php data table:

the array looks this:

$memberdata     key    value     apple  5     banana 8     salmon 3     candle 4     ..........     , 100 more... 

my mysql table looks this:

membertable     id(int11)=pk    memid(int11)      stuff(varchar)     value(int2)     1               23                apple              5     2               23                banana             8     3               23                salmon             3     4               23                candle             4     5               45                banana             1     6               45                apple              9 

so each member; here member 23 , 45 can have same stuff other values, every member have 1 php array of data. (mysql id auto increment).

my question: there possibility store array directly mysql table...? in book read make foreach loop , in loop open connection database... thought maybe time consuming:

book example:

$cxn = mysqli_connect($host,$user,$pass,$dbname); $memid = "23"; $query_pre = "insert membertable ('memid','stuff','value') values ("; foreach ($memberdata $stuff => $value) {  $query = $query_pre . "$memid,$stuff,$value)";   $result = mysqli_query($cxn, $query) or die ("couldn't execute query"); }   

regards, thijs

well that's strange book. although idea in general right, particular code contains both php , mysql errors.

it should (not tested):

$cxn = mysqli_connect($host,$user,$pass,$dbname); $memid = "23"; $prequery = array(); foreach ($memberdata $stuff => $value) {   $stuff = mysqli_real_escape_string($stuff);   $value = mysqli_real_escape_string($value);   $prequery[] = "($memid,'$stuff','$value')";  }  $query = "insert membertable (memid,stuff,value) values ".implode(",",$prequery); $result = mysqli_query($cxn, $query) or die (mysqli_error($cxn).$query); 

Comments

Popular posts from this blog

c# - Usage of Server Side Controls in MVC Frame work -

cocoa - Nesting arrays into NSDictionary object (Objective-C) -

ios - Very simple iPhone App crashes on UILabel settext -