khristian Posted January 8, 2008 Share Posted January 8, 2008 Hi, This might be simple, but I fear I am being a bit dim today. I currently have a form that has three fields (id1, id2, and id3) What I want to do is when it comes to processing form and storing it in a database I want a fourth field created (user) but this being a combincation of the previous three fields. I have tried: $user = $id1,$id2,$id3 or $user = $id1+$id2+$id3 and many other variations, but I cannot seem to get it to work. Any advice anyone? Quote Link to comment https://forums.phpfreaks.com/topic/85038-merging-variables/ Share on other sites More sharing options...
revraz Posted January 8, 2008 Share Posted January 8, 2008 $user = $id1.$id2.$id3 Quote Link to comment https://forums.phpfreaks.com/topic/85038-merging-variables/#findComment-433667 Share on other sites More sharing options...
khristian Posted January 8, 2008 Author Share Posted January 8, 2008 Absolute genius Quote Link to comment https://forums.phpfreaks.com/topic/85038-merging-variables/#findComment-433674 Share on other sites More sharing options...
revraz Posted January 8, 2008 Share Posted January 8, 2008 Sometimes I get lucky and my answer actually works. Quote Link to comment https://forums.phpfreaks.com/topic/85038-merging-variables/#findComment-433682 Share on other sites More sharing options...
khristian Posted January 8, 2008 Author Share Posted January 8, 2008 LOL Well sadly I now have another issue (Yes I really am having a dumb day) What I want, is if some selects 'Block One' from a list, then it has this stored as 'blockname', but also a shorter version as 'shortblockname' I have tried this (but it dosent work): if ($blockname == 'Block 1') { $shortblockname = 'B1'}; else { end if; } Quote Link to comment https://forums.phpfreaks.com/topic/85038-merging-variables/#findComment-433688 Share on other sites More sharing options...
revraz Posted January 8, 2008 Share Posted January 8, 2008 Lets see the list Quote Link to comment https://forums.phpfreaks.com/topic/85038-merging-variables/#findComment-433690 Share on other sites More sharing options...
khristian Posted January 8, 2008 Author Share Posted January 8, 2008 The list itself comes from a form, but here it is: <select size="1" name="blockname"> <option selected>-- SELECT BLOCK NAME --</option> <option>Western Harbour Midway</option> <option>Western Harbour Terrace</option> <option>Western Harbour Breakwater</option> </select> Quote Link to comment https://forums.phpfreaks.com/topic/85038-merging-variables/#findComment-433692 Share on other sites More sharing options...
revraz Posted January 8, 2008 Share Posted January 8, 2008 How about doing something like this <select size="1" name="blockname"> <option selected>-- SELECT BLOCK NAME --</option> <option value="WHM">Western Harbour Midway</option> <option value="WHT">Western Harbour Terrace</option> <option value="WHB">Western Harbour Breakwater</option> </select> Now the value returned from $_POST['blockname'] is the Value instead of the name. Or do you want both? Quote Link to comment https://forums.phpfreaks.com/topic/85038-merging-variables/#findComment-433694 Share on other sites More sharing options...
khristian Posted January 8, 2008 Author Share Posted January 8, 2008 Ah I need both, as one will go into an address field (blockname), and one will go to form part of the username (shortblockcode). I just managed it with just: if ($blockname == 'Western Harbour Midway') { $shortblockname = 'WHM';} if ($blockname == 'Western Harbour Terrace') { $shortblockname = 'WHT';} if ($blockname == 'Western Harbour Breakwater') { $shortblockname = 'WHB';} But I am unsure if there is a better way. Quote Link to comment https://forums.phpfreaks.com/topic/85038-merging-variables/#findComment-433700 Share on other sites More sharing options...
revraz Posted January 8, 2008 Share Posted January 8, 2008 Depends on how many you have, and if they are static or dynamic. I personally would use a database and load them from there. But you can make yours more compact. $shortblockname = ($blockname == 'Western Harbour Midway') ? "WHM" : ""; $shortblockname = ($blockname == 'Western Harbour Terrace) ? "WHT" : ""; $shortblockname = ($blockname == 'Western Harbour Breakwater') ? "WHB" : ""; Quote Link to comment https://forums.phpfreaks.com/topic/85038-merging-variables/#findComment-433706 Share on other sites More sharing options...
khristian Posted January 8, 2008 Author Share Posted January 8, 2008 Cool. Will give it a try, if not then yeah I may go down the database route :-) Quote Link to comment https://forums.phpfreaks.com/topic/85038-merging-variables/#findComment-433714 Share on other sites More sharing options...
kenrbnsn Posted January 8, 2008 Share Posted January 8, 2008 Another way to do this would be to use an array: <?php $blocks = array('Western Harbour Midway' => 'WHM', 'Western Harbour Terrace' => 'WHT', 'Western Harbour Breakwater' => 'WHB'); $shortblockname = (array_key_exists($blockname, $blocks))?$blocks[$blockname]:''; ?> It looks like the shortblockname is the first character of each word in the blockname. If this is correct, this is another method: <?php $tmp = explode(' ',$blockname); $shortblockname = ''; foreach ($tmp as $word) $shortblockname .= strtoupper($word[0]); ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/85038-merging-variables/#findComment-433723 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.