|
How to add moor than one value to a mysql database field at once?
06-13-2008, 12:31 PM
|
How to add moor than one value to a mysql database field at once?
|
Posts: 132
Name: Chase
|
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.
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.
|
|
|
|
06-13-2008, 01:21 PM
|
Re: How to add moor than one value to a mysql database field at once?
|
Posts: 132
Name: Chase
|
I am going to try this?
Quote:
<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-2008 at 01:44 PM..
|
|
|
|
06-13-2008, 02:55 PM
|
Re: How to add moor than one value to a mysql database field at once?
|
Posts: 5,662
Name: John Alexander
|
A table is a grid of rows and columns - each cell can only have one value. (That's a tiny bit oversimplified, because you can use crazy schemes of forcing multiple values, like yamia|xenesthis could go in one cell and your code could parse them out, or you can use XML to stuff the world in a cell, but both of these are cheating - they make things more complicated than they need to be, and they don't apply to your project.)
What are you trying to accomplish by putting these values into your table? Yesterday I had suggested using another table with a list of genus names, and an ID that corresponds to each of them, then storing only that ID in your main table. If you wanted to do that, you'd need to fill our your list, which is what you're asking about. But if you don't want to do that, if you want those values in a drop down list on a web form, and to store the result a human picked in your table as text, then the only place you really need to store the complete list is in your web form, in HTML code making the drop down list. If you were going to store it in the database, you'd probably want a query to get the values for your drop down. If scientists ever discover a new genus of spider, say the John Alexanderus, you'll be able to add it to your table, and the web form will automatically pick it up.
Now if you're still using the schema where you have one table, with one row per spider, you can't add a bunch of rows, one per genus, without breaking things. Breaking here means that one row doesn't represent one spider anymore.
|
|
|
|
06-16-2008, 02:49 PM
|
Re: How to add moor than one value to a mysql database field at once?
|
Posts: 132
Name: Chase
|
THanks so much for the help I see what you mean.
I thought I needed to add all of them into my database but it turns out that I didnt after all.
|
|
|
|
|
« Reply to How to add moor than one value to a mysql database field at once?
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|