If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > How to add more than one value to a mysql field at a time?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-13-08, 11:23
Snot Snot is offline
Registered User
 
Join Date: Jun 2008
Posts: 14
How to add more than one value to a mysql field at a time?

Ok guys no more error messages! ;D

You try it out here

I think its connecting with the database even though its not valid code but I'll work on that So this is my new code in echo.php

Code:
<div class="c1">
    <table cellspacing="20">
<tr>
        	<th>Habitat</th>
            <th>Humidity</th>
            <th>Speed</th>
            <th>Size</th>
            <th>Location</th>
            <th>Aggression</th>
        </tr>
        
    <?
include("connect.php");
// now you are connected and can query the database
$request = mysql_query("SELECT * FROM common_traits 
	WHERE habitat = \"".$_REQUEST['habitat']."\" 
	AND humidity = \"".$_REQUEST['humidity']."\"
	AND speed = \"".$_REQUEST['speed']."\"
	AND size = \"".$_REQUEST['size']."\"
	AND location = \"".$_REQUEST['location']."\",
	AND aggression = \"".$_REQUEST['aggression']."\"");

// loop through the results with mysql_fetch_array()
if ( @mysql_num_rows($row) > 0 ) {
	while($row = mysql_fetch_array($result)){
	  echo "
		<tr>
				<td>".$row['habitat']."</td>
				<td>".$row['humidity']."</td>
				<td>".$row['speed']."</td>
				<td>".$row['size']."</td>
				<td>".$row['location']."</td>
				<td>".$row['aggression']."</td>
			</tr>
	  ";
	}

} else {

	echo "<tr><td colspan = 6></td></tr>";

}

// don't forget to close the mysql connection
mysql_close();
?> 	 
</table>

<a href="http://www.tarantuladatabase.com/assets/pages/search.html"><input name="Back" type="button" value="Back" /></a></div>
  </div>
Please correct me if i'm wrong but i think my next step in the project is to create a form that will submit data to my database so that I have something to search?

I need to add all of the database field values for genus there are a lot of them. I think about 113 give or take

in this pic I have 4 of them added already.

http://www.tarantuladatabase.com/fv.jpg

I know there is a way to past them into my sql and submit them all at one time but I don't know the format. What I would like to do is create the file in a .txt file and then copy and past it to the database once its all compiled.

Is there any way you can give me any example of the code I would need to submit that to the database?

I have also added a species field that will be typed in by my users when they submit a new species into the database. but before I start doing all this I just wanted to check and make sure it was necessary.

Just to explain how the submission form will work you select a genus from the drop down then type in the species name in the text box. Click one of each of the bullet points and click the tarantula submission button.

This is the submission form

I want that to create a new tarantula in my database under the selected genus. Is this adding up?

Thanks so much for all the help and advice.
Reply With Quote
  #2 (permalink)  
Old 06-13-08, 12:18
Snot Snot is offline
Registered User
 
Join Date: Jun 2008
Posts: 14
I am going to try this?

Code:
<body>
<?php
include("connect.php");
$genus = array (
'Aphonopelma',
'Augacephalus',
'Avicularia',
'Batesiella',
'Bonnetina',
'Brachionopus',
'Brachypelma',
'Cardiopelma',
'Catumiri',
'Cerato*****',
'Chaetopelma',
'Chilobrachys',
'Chromatopelma',
'Citharacanthus',
'Citharischius',
'Citharognathus',
'Clavopelma',
'Coremiocnemis',
'Crassicrus',
'Cratorrhagus',
'Cyclosternum',
'Cyriocosmus',
'Cyriopagopus',
'Cyrtopholis',
'Davus',
'Encyocratella',
'Encyocrates',
'Ephebopus',
'Euathlus',
'Eucratoscelus',
'Eumenophorus',
'Eupalaestrus',
'Euphrictus',
'Grammostola',
'Hapalopus',
'Hapalotremus',
'Haploclastus',
'Haplocosmia',
'Haplopelma',
'Harpactira',
'Harpactirella',
'Hemiercus',
'Hemirrhagus',
'Heteroscodra',
'Heterothele',
'Holothele',
'Homoeomma',
'Hysterocrates',
'Idiothele',
'Iracema',
'Iridopelma',
'Ischnocolus',
'Lampropelma',
'Lasiodora',
'Lasiodorides',
'Loxomphalia',
'Loxoptygus',
'Lyrognathus',
'Mascaraneus',
'Megaphobema',
'Melloina',
'Melloleitaoina',
'Metriopelma',
'Monocentropus',
'Myostola',
'Neostenotarsus',
'Nesiergus',
'Nesipelma',
'Nhandu',
'Oligoxystre',
'Ornithoctonus',
'Orphnaecus',
'Ozopactus',
'Pachistopelma',
'Pamphobeteus',
'Paraphysa',
'Phlogiellus',
'Phoneyusa',
'Phormictopus',
'Phormingochilus',
'Plesiopelma',
'Plesiophrictus',
'Poecilotheria',
'Proshapalopus',
'Psalmopoeus',
'Pseudhapalopus',
'Pseudoligoxystre',
'Pterinochilus',
'Reversopelma',
'Schismatothele',
'Schizopelma',
'Selenobrachys',
'Selenocosmia',
'Seleno*****',
'Selenotholus',
'Selenotypus',
'Sericopelma',
'Sickius',
'Sphaerobothria',
'Stichoplastoris',
'Stromatopelma',
'Tapinauchenius',
'Theraphosa',
'Thrigmopoeus',
'Thrixopelma',
'Tmesiphantes',
'Trichognathella',
'Vitalius',
'Xenesthis',
'Yamia',
);

// $sql = "INSERT INTO tablename (genus) VALUES ('".$genus[$i]."')";


//then make you a while loop that will loop through your Insert into query code 110 times -- Edit lol?

/*
while($i<=110)
{
mysql_query($sql,$con);
$i++;
}*/

for ($x=0;$x<count($genus);$x++) {
  $sql = "INSERT INTO common_traits(genus) VALUES ('".$genus[$x]."')";
  echo "$sql <br>";  
  //mysql_query($sql);  // Uncomment when your ready for the real deal
}
?> 
</body>

Last edited by Snot; 06-13-08 at 12:45.
Reply With Quote
  #3 (permalink)  
Old 06-13-08, 14:26
mike_bike_kite mike_bike_kite is offline
vaguely human
 
Join Date: Jun 2007
Location: London
Posts: 2,519
Not sure if your table name is good - either it should be called genus in which case in holds genus or it should be called common_traits in which case it should have a type field ie
Code:
INSERT INTO common_traits(trait_type,allowed_value)
VALUES ('genus', 'Aphonopelma')
Many folks on this forum don't like this type of set up but what the hell.

If you want to keep your original set up then why not just do it as sql ie
Code:
INSERT INTO common_traits(genus) VALUES ('Aphonopelma');
INSERT INTO common_traits(genus) VALUES ('Augacephalus');
INSERT INTO common_traits(genus) VALUES ('Avicularia');
INSERT INTO common_traits(genus) VALUES ('Batesiella');
INSERT INTO common_traits(genus) VALUES ('Bonnetina');
INSERT INTO common_traits(genus) VALUES ('Brachionopus');
INSERT INTO common_traits(genus) VALUES ('Brachypelma');
INSERT INTO common_traits(genus) VALUES ('Cardiopelma');
INSERT INTO common_traits(genus) VALUES ('Catumiri');
INSERT INTO common_traits(genus) VALUES ('Cerato*****');
INSERT INTO common_traits(genus) VALUES ('Chaetopelma');
INSERT INTO common_traits(genus) VALUES ('Chilobrachys');
INSERT INTO common_traits(genus) VALUES ('Chromatopelma');
INSERT INTO common_traits(genus) VALUES ('Citharacanthus');
INSERT INTO common_traits(genus) VALUES ('Citharischius');
INSERT INTO common_traits(genus) VALUES ('Citharognathus');
INSERT INTO common_traits(genus) VALUES ('Clavopelma');
INSERT INTO common_traits(genus) VALUES ('Coremiocnemis');
INSERT INTO common_traits(genus) VALUES ('Crassicrus');
INSERT INTO common_traits(genus) VALUES ('Cratorrhagus');
INSERT INTO common_traits(genus) VALUES ('Cyclosternum');
INSERT INTO common_traits(genus) VALUES ('Cyriocosmus');
INSERT INTO common_traits(genus) VALUES ('Cyriopagopus');
INSERT INTO common_traits(genus) VALUES ('Cyrtopholis');
INSERT INTO common_traits(genus) VALUES ('Davus');
INSERT INTO common_traits(genus) VALUES ('Encyocratella');
INSERT INTO common_traits(genus) VALUES ('Encyocrates');
INSERT INTO common_traits(genus) VALUES ('Ephebopus');
INSERT INTO common_traits(genus) VALUES ('Euathlus');
INSERT INTO common_traits(genus) VALUES ('Eucratoscelus');
INSERT INTO common_traits(genus) VALUES ('Eumenophorus');
INSERT INTO common_traits(genus) VALUES ('Eupalaestrus');
INSERT INTO common_traits(genus) VALUES ('Euphrictus');
INSERT INTO common_traits(genus) VALUES ('Grammostola');
INSERT INTO common_traits(genus) VALUES ('Hapalopus');
INSERT INTO common_traits(genus) VALUES ('Hapalotremus');
INSERT INTO common_traits(genus) VALUES ('Haploclastus');
INSERT INTO common_traits(genus) VALUES ('Haplocosmia');
INSERT INTO common_traits(genus) VALUES ('Haplopelma');
INSERT INTO common_traits(genus) VALUES ('Harpactira');
INSERT INTO common_traits(genus) VALUES ('Harpactirella');
INSERT INTO common_traits(genus) VALUES ('Hemiercus');
INSERT INTO common_traits(genus) VALUES ('Hemirrhagus');
INSERT INTO common_traits(genus) VALUES ('Heteroscodra');
INSERT INTO common_traits(genus) VALUES ('Heterothele');
INSERT INTO common_traits(genus) VALUES ('Holothele');
INSERT INTO common_traits(genus) VALUES ('Homoeomma');
INSERT INTO common_traits(genus) VALUES ('Hysterocrates');
INSERT INTO common_traits(genus) VALUES ('Idiothele');
INSERT INTO common_traits(genus) VALUES ('Iracema');
INSERT INTO common_traits(genus) VALUES ('Iridopelma');
INSERT INTO common_traits(genus) VALUES ('Ischnocolus');
INSERT INTO common_traits(genus) VALUES ('Lampropelma');
INSERT INTO common_traits(genus) VALUES ('Lasiodora');
INSERT INTO common_traits(genus) VALUES ('Lasiodorides');
INSERT INTO common_traits(genus) VALUES ('Loxomphalia');
INSERT INTO common_traits(genus) VALUES ('Loxoptygus');
INSERT INTO common_traits(genus) VALUES ('Lyrognathus');
INSERT INTO common_traits(genus) VALUES ('Mascaraneus');
INSERT INTO common_traits(genus) VALUES ('Megaphobema');
INSERT INTO common_traits(genus) VALUES ('Melloina');
INSERT INTO common_traits(genus) VALUES ('Melloleitaoina');
INSERT INTO common_traits(genus) VALUES ('Metriopelma');
INSERT INTO common_traits(genus) VALUES ('Monocentropus');
INSERT INTO common_traits(genus) VALUES ('Myostola');
INSERT INTO common_traits(genus) VALUES ('Neostenotarsus');
INSERT INTO common_traits(genus) VALUES ('Nesiergus');
INSERT INTO common_traits(genus) VALUES ('Nesipelma');
INSERT INTO common_traits(genus) VALUES ('Nhandu');
INSERT INTO common_traits(genus) VALUES ('Oligoxystre');
INSERT INTO common_traits(genus) VALUES ('Ornithoctonus');
INSERT INTO common_traits(genus) VALUES ('Orphnaecus');
INSERT INTO common_traits(genus) VALUES ('Ozopactus');
INSERT INTO common_traits(genus) VALUES ('Pachistopelma');
INSERT INTO common_traits(genus) VALUES ('Pamphobeteus');
INSERT INTO common_traits(genus) VALUES ('Paraphysa');
INSERT INTO common_traits(genus) VALUES ('Phlogiellus');
INSERT INTO common_traits(genus) VALUES ('Phoneyusa');
INSERT INTO common_traits(genus) VALUES ('Phormictopus');
INSERT INTO common_traits(genus) VALUES ('Phormingochilus');
INSERT INTO common_traits(genus) VALUES ('Plesiopelma');
INSERT INTO common_traits(genus) VALUES ('Plesiophrictus');
INSERT INTO common_traits(genus) VALUES ('Poecilotheria');
INSERT INTO common_traits(genus) VALUES ('Proshapalopus');
INSERT INTO common_traits(genus) VALUES ('Psalmopoeus');
INSERT INTO common_traits(genus) VALUES ('Pseudhapalopus');
INSERT INTO common_traits(genus) VALUES ('Pseudoligoxystre');
INSERT INTO common_traits(genus) VALUES ('Pterinochilus');
INSERT INTO common_traits(genus) VALUES ('Reversopelma');
INSERT INTO common_traits(genus) VALUES ('Schismatothele');
INSERT INTO common_traits(genus) VALUES ('Schizopelma');
INSERT INTO common_traits(genus) VALUES ('Selenobrachys');
INSERT INTO common_traits(genus) VALUES ('Selenocosmia');
INSERT INTO common_traits(genus) VALUES ('Seleno*****');
INSERT INTO common_traits(genus) VALUES ('Selenotholus');
INSERT INTO common_traits(genus) VALUES ('Selenotypus');
INSERT INTO common_traits(genus) VALUES ('Sericopelma');
INSERT INTO common_traits(genus) VALUES ('Sickius');
INSERT INTO common_traits(genus) VALUES ('Sphaerobothria');
INSERT INTO common_traits(genus) VALUES ('Stichoplastoris');
INSERT INTO common_traits(genus) VALUES ('Stromatopelma');
INSERT INTO common_traits(genus) VALUES ('Tapinauchenius');
INSERT INTO common_traits(genus) VALUES ('Theraphosa');
INSERT INTO common_traits(genus) VALUES ('Thrigmopoeus');
INSERT INTO common_traits(genus) VALUES ('Thrixopelma');
INSERT INTO common_traits(genus) VALUES ('Tmesiphantes');
INSERT INTO common_traits(genus) VALUES ('Trichognathella');
INSERT INTO common_traits(genus) VALUES ('Vitalius');
INSERT INTO common_traits(genus) VALUES ('Xenesthis');
INSERT INTO common_traits(genus) VALUES ('Yamia');
Mike
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On