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?
Keep a variable and add a second in database field
Moderator: General Moderators
- jaoudestudios
- DevNet Resident
- Posts: 1483
- Joined: Wed Jun 18, 2008 8:32 am
- Location: Surrey
Re: Keep a variable and add a second in database field
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!
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
I'll add my firm endorsement of that.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!
Even though I don't know what NED is.
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.
- jaoudestudios
- DevNet Resident
- Posts: 1483
- Joined: Wed Jun 18, 2008 8:32 am
- Location: Surrey
Re: Keep a variable and add a second in database field
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 oncalifdon wrote:Even though I don't know what NED is.![]()
Re: Keep a variable and add a second in database field
Hmm, sounds like it's naughty language...jaoudestudios wrote: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 oncalifdon wrote:Even though I don't know what NED is.![]()