Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding more than one record to a row... 1

Status
Not open for further replies.

perlone

Programmer
May 20, 2001
438
US
Is it possible to add more than one record to a row? Or is there a space limit? There is no Knowledge, That is not power.
Age: 16
E-mail: projectnet01@yahoo.com
School: Coral Springs High (Company:(not done yet) :)
Status: Currently working with C++ for game developing.
-Aaron
 
Not quite sure what you mean, since most folks use 'records' and 'rows' meaning the same thing. If you mean rows with more than one column, then sure, MySQL can do that (
Code:
CREATE TABLE mytable(var1 int, var2 int)
). Can you describe your problem in more detail?

-Rob
 
Go here:


See that I added 2 emails on the record for the name Aaron. Can you do that with MySQL? There is no Knowledge, That is not power.
Age: 16
E-mail: projectnet01@yahoo.com
School: Coral Springs High (Company:(not done yet) :)
Status: Currently working with C++ for game developing.
-Aaron
 
I don't know if you can, but having two email addresses in the same cell looks like a poor design choice.
 
I know but this is for a game i'm working on and I want to put all users weapons to one row. There is no Knowledge, That is not power.
Age: 16
E-mail: projectnet01@yahoo.com
School: Coral Springs High (Company:(not done yet) :)
Status: Currently working with C++ for game developing.
-Aaron
 
Of course you can add any information you want into one cell. You shouldn't use the term recvord to describe this, though, since generally a record = a row.

What you are really asking is how can you differentiante multiple bits of information placed inside a singe cell. Absolutely not a problem, as long as you are familiar with the string manipulation functions of whatever programming language you are using (such as PHP). You can then just treat the contents of that cell as a string, with a separator, such as a comma, which allows you to extract both email addresses from it. I recommend using the comma as a separator (with no spaces), rather than a line break, since it is easier to deal with programmatically. Thus a cell with multiple emails would look like "host@mail.com,newmail@host.com".

For a PHP example, if you want to extract multiple emails form the "email" column of your MySQl query, just do this:

Code:
<?php
//database connection stuff

$result = mysql_query(&quot;SELECT * FROM users&quot;);

while($row = mysql_fetch_array($result)
{

$username = $row[&quot;username&quot;];
$password = $row[&quot;password&quot;];
$email_array = explode(&quot;,&quot;,$row[&quot;email&quot;]);
//separate string into array using comma as separator

}

?>
From this code, for each row of the database, you now have an array of all the user's email addresses, which you can manipulate however you want. $email_array[0] will have the first email, $email_array[1] will have the second, etc...

However, if you really want to have something like &quot;multiple pieces of data for one user&quot;, you should consider your overall database design. Good relational database design is called &quot;normalization&quot; and has some very good ways of dealing with these types of problems. Example: 1 table for user name, additional table relates to username, and keeps track of multiple emails per user, in a many-to-one relationship.
 
Thanks a lot! That was exactly I was looking for! There is no Knowledge, That is not power.
Age: 16
E-mail: projectnet01@yahoo.com
School: Coral Springs High (Company:(not done yet) :)
Status: Currently working with C++ for game developing.
-Aaron
 
You're welcome. Whe should have looked at the preview longer. It's great when the word I highlight is the mispelled one (lol).

Oh, and take the comma out of your sig. (sorry, I was an English teacher for a short time. Age: 35) Look up Ralph Waldo Emerson's quotes and you'll see.

Better change it man, or I'll take a short drive up from Pembroke Pines and visit your English teacher ;-).
 
Take the comma out of my sig? You mean the one on the quote? I'll do it since you asked so nicely:). I'm not good with english, so I don't mind if you correct me:) There is no Knowledge that is not power.
Age: 16
E-mail: projectnet01@yahoo.com
School: Coral Springs High (Company:(not done yet) :)
Status: Currently working with C++ for game developing.
-Aaron
 
Just kidding, anyway. But I am a Florida resident, just a few miles to the south. I have driven by Coral Springs High quite a few times.

Glad to see young guys learning how to code serious stuff, instead of just playing with VB and kewl Javascripts. It's serious young computer guys like yourself that might just be the salvation of this country ;-). Keep it up!
 
Thanks, I'll do my best.:)

There is no Knowledge that is not power.
Age: 16
E-mail: projectnet01@yahoo.com
School: Coral Springs High (Company:(not done yet) :)
Status: Currently working with C++ for game developing.
-Aaron
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top