Page 1 of 1

Keep a variable and add a second in database field

Posted: Sun Jan 11, 2009 5:55 am
by SB68
Hi,

To give an example first of a working code,

<?php
$package = explode("|",$slcustom32);

?>
New order:<select name="newcustom32" >
<option value=""><? if (empty($package[1])) { echo "Choose a package"; } else { echo $package[1]; } ?></option>
<option value="<?=$package[0]?>|Storage package B|" <? if ( $package[1] == "Storage package B|" ) { echo "selected"; } ?> >Storage package B</option>

The idea here, which works, is that if $package[0] exists in the database, then keep that and add $package[1] as Storage package B, and separate $package[0] and $package[1] by a |


Now, how can I do the same for a text field input? Must I use a str_replace for this one, or is this impossible to do?

Re: Keep a variable and add a second in database field

Posted: Sun Jan 11, 2009 6:31 am
by jaoudestudios
I would not NED the code together like that, I would have a separate table (one-to-many relationship) - normalise your database.

Also you are mixing your php tags, will full and abbreviated versions. I would definitely advise against using shorten tags!

Re: Keep a variable and add a second in database field

Posted: Sun Jan 11, 2009 2:52 pm
by califdon
jaoudestudios wrote:I would not NED the code together like that, I would have a separate table (one-to-many relationship) - normalise your database.

Also you are mixing your php tags, will full and abbreviated versions. I would definitely advise against using shorten tags!
I'll add my firm endorsement of that.

Even though I don't know what NED is. :wink:

First, in relational databases, every column in a table must be "atomic", that is, have a single value that cannot be separated into more than one value. So when you break that rule, all bets are off as to what you can do to recover data because it doesn't conform to the rules of database normalization. Secondly, the only time you should ever use the short-form PHP tag (<?) is when you don't care if the web server understands it or not--some older ones may not. Thirdly, to maintain your own sanity and enable others to read your code, don't bunch your code together like that.

Re: Keep a variable and add a second in database field

Posted: Sun Jan 11, 2009 3:00 pm
by jaoudestudios
califdon wrote:Even though I don't know what NED is. :wink:
Hahaha...its a long story, in a nutshell, it is when something is fudged. Thought I would give it a try and see if it catches on :D

Re: Keep a variable and add a second in database field

Posted: Sun Jan 11, 2009 3:31 pm
by califdon
jaoudestudios wrote:
califdon wrote:Even though I don't know what NED is. :wink:
Hahaha...its a long story, in a nutshell, it is when something is fudged. Thought I would give it a try and see if it catches on :D
Hmm, sounds like it's naughty language... :roll:

:P And here I thought I'd learn something new ... oh, well!