dc_jt Posted May 15, 2007 Share Posted May 15, 2007 I posted this in sql forum but there is no one in there! Hi I have a very long list for example john, david, james, john. I want to add these names into my table which containts user_id, name, password Obviously I want these in the name field. How would I do this? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/51505-insert-long-list-into-phpmyadmin-table/ Share on other sites More sharing options...
MadTechie Posted May 15, 2007 Share Posted May 15, 2007 i assume $names is an array <?php foreach($names as $n) { mysql_query("INSERT INTO table_name (`Name`) VALUES ($N)"); }?> this is just a basic example Quote Link to comment https://forums.phpfreaks.com/topic/51505-insert-long-list-into-phpmyadmin-table/#findComment-253662 Share on other sites More sharing options...
pocobueno1388 Posted May 15, 2007 Share Posted May 15, 2007 <?php $name = array("john", "david", "james", "linda"); $password = "??"; for ($i=0; $i < count($name); $i++){ mysql_query("INSERT INTO table (name, password) VALUES ('$name[$i]', '$password')"); } ?> I'm not sure if you already have the values of user_id and password already filled in for these people, or if you are trying to add all completely new rows? This code adds all completely new rows. Quote Link to comment https://forums.phpfreaks.com/topic/51505-insert-long-list-into-phpmyadmin-table/#findComment-253664 Share on other sites More sharing options...
dc_jt Posted May 15, 2007 Author Share Posted May 15, 2007 Thanks for your help. Another question though. I have about 500 names, and they are listed just like john, david, peter etc. They are not in quotes. Is there a fast way to put quotes around them? Quote Link to comment https://forums.phpfreaks.com/topic/51505-insert-long-list-into-phpmyadmin-table/#findComment-253691 Share on other sites More sharing options...
pocobueno1388 Posted May 15, 2007 Share Posted May 15, 2007 Well, if you have all these names in a text file there is a way to pull them all out using fopen() and then putting them all into an array....but I don't have time to put the script together for you. There are plenty of tutorials out there that explain how to do this though, just google it and I am sure you will find something. Maybe someone else can help you =] You might want to give an example of what your text file looks like. Like are the names separated by commas, spaces, or what? Just copy and paste like 5 names from the file to show us how you set it up. I will be back on later if you still need the help, I am sure someone will come along and help you though ^^ Quote Link to comment https://forums.phpfreaks.com/topic/51505-insert-long-list-into-phpmyadmin-table/#findComment-253730 Share on other sites More sharing options...
MadTechie Posted May 15, 2007 Share Posted May 15, 2007 try this $thedate = "david, john, paul"; $thedate = '"'.str_replace(',', '","', $thedate).'"'; NOTE: that single double single (')(")(') Quote Link to comment https://forums.phpfreaks.com/topic/51505-insert-long-list-into-phpmyadmin-table/#findComment-253944 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.