Inserting a simple list into MySQL table (php) -


after bit of hunting around solution. thought time ask brains trust here on stackoverflow.

i'm looking way take list, in form of string, split using commas , insert columns in mysql table.

the list like:

  1. tim moltzen, 2. joel reddy, 3. blake ayshford, 4. chris lawrence, 5. james tedesco, 6. benji marshall, 7. braith anasta, 8. aaron woods, 9. robbie farah, 10. jack buchanan, 11. bodene thompson, 12. liam fulton, 13. adam blair, 14. ben murdoch masila, 15. ava seumanufagai 16. matt bell, 17. eddy pettybourne

from list, 2 things needed split. number , name.

so, number inserted "player_number" column , name "player_name". of course commas used spacing, , don't need interested table.

any assistance on how split string , insert table extremely appreciated.

edit::

i'll see can work using explode , running loop insert them table.

$string="1. tim moltzen, 2. joel reddy, 3. blake ayshford, 4. chris lawrence, 5. james tedesco, 6. benji marshall, 7. braith anasta, 8. aaron woods, 9. robbie farah, 10. jack buchanan, 11. bodene thompson, 12. liam fulton, 13. adam blair, 14. ben murdoch masila, 15. ava seumanufagai 16. matt bell, 17. eddy pettybourne";  $string=explode(', ',$string); foreach($string $val)     {     $val=explode('. ',$val);     mysql_query('insert yourtable (col_number,col_name) values ("'.$val[0].'.","'.$val[1].'")';     } 

i don't understand why want insert period along number, mean column has unnecessarily varchar instead of int. anyway, asked.

change mysql_query mysqli_query if prefer.

to explode between numbers use:

$string=preg_split('/ ?[0-9]+\.? /', $string, null, preg_split_no_empty); 

but don't have numbers each name. won't able insert this.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -