_spaz Posted December 7, 2009 Share Posted December 7, 2009 Can someone please help me with the below code, I'm trying to do a batch update on listed results where the column "priority" can either be 10 or 15, Im not sure if the syntax is correct, the result ID's do pass correctly but the "Priority Values" do not pass to my update.php script, i have a feeling that my syntax is wrong somewhere. Thanks in advance... <td> <?php print "<input type='hidden' name='ID[$i]' value='{$result_row['ID']}' />";?> <?php print "<select name='Priority[$i]' >"; ?> <?php print "<option value=''($result_row[Priority] == Null?' selected='selected'':null)></option>"; ?> <?php print "<option value='10'($result_row[Priority] == '10'?' selected='selected'':null)>10</option>";?> <?php print "<option value='15'($result_row[Priority] == '15'?' selected='selected'':null)>15</option>";?> <?php print "</select>" ?> </td> Quote Link to comment https://forums.phpfreaks.com/topic/184218-batch-processing-list-boxes/ Share on other sites More sharing options...
PFMaBiSmAd Posted December 7, 2009 Share Posted December 7, 2009 When you do a "view source" of your form in your browser is it as expected? It would take seeing your form processing code in order to be able to tell what it is or is not doing. Quote Link to comment https://forums.phpfreaks.com/topic/184218-batch-processing-list-boxes/#findComment-972657 Share on other sites More sharing options...
JustLikeIcarus Posted December 7, 2009 Share Posted December 7, 2009 Try formatting your ternary like (!isset($result_row[Priority]) ? " selected=selected" : NULL Quote Link to comment https://forums.phpfreaks.com/topic/184218-batch-processing-list-boxes/#findComment-972799 Share on other sites More sharing options...
premiso Posted December 7, 2009 Share Posted December 7, 2009 You had some major syntax issues in your code, namely your quotes. <?php print "<input type='hidden' name='ID[$i]' value='{$result_row['ID']}' />";?> <?php print "<select name='Priority[$i]' >"; ?> <?php print "<option value=''" . (is_null($result_row['Priority']) ?" selected='selected'":null) . "></option>"; ?> <?php print "<option value='10'" . ($result_row['Priority'] == '10'?" selected='selected'":null) . ">10</option>";?> <?php print "<option value='15'" . ($result_row['Priority'] == '15'?" selected='selected'":null) . ">15</option>";?> <?php print "</select>"; ?> Why in the world are you going in and our of PHP like that? This would be much simpler and works just the same: <?php print "<input type='hidden' name='ID[$i]' value='{$result_row['ID']}' /> <select name='Priority[$i]' > <option value=''" . (is_null($result_row['Priority']) ?" selected='selected'":null) . "></option> <option value='10'" . ($result_row['Priority'] == '10'?" selected='selected'":null) . ">10</option> <option value='15'" . ($result_row['Priority'] == '15'?" selected='selected'":null) . ">15</option> </select>"; ?> So I changed your quotes around on the selected, you were using a single quote after the ? and also using them around the ='selected' that was a syntax issue. Also you will notice on the first ternary I use the is_null function as that is how you have to test if a variable is null, you cannot simply do a comparison. Either way that should work for you. Quote Link to comment https://forums.phpfreaks.com/topic/184218-batch-processing-list-boxes/#findComment-972921 Share on other sites More sharing options...
JustLikeIcarus Posted December 7, 2009 Share Posted December 7, 2009 premiso is right. Your really making it more difficult on yourself than it it needs to be. @premiso All the times i've used ternarys ive formatted them as ($result_row['Priority'] == '15') ? " selected='selected'":null I notices you had the parens around the whole thing. Since ive never seen them done like that I was just curious if that was also a valid way? Just curious. Quote Link to comment https://forums.phpfreaks.com/topic/184218-batch-processing-list-boxes/#findComment-972937 Share on other sites More sharing options...
premiso Posted December 7, 2009 Share Posted December 7, 2009 I notices you had the parens around the whole thing. Since ive never seen them done like that I was just curious if that was also a valid way? Just curious. Give it a shot. <?php $x = "hello"; $ternTest = ($x == 4 ? $x:"phooey"); echo $ternTest; ?> Quote Link to comment https://forums.phpfreaks.com/topic/184218-batch-processing-list-boxes/#findComment-972963 Share on other sites More sharing options...
JustLikeIcarus Posted December 7, 2009 Share Posted December 7, 2009 Indeed it works as well. I knew the parens werent required around the "if" section but they make it look pretty lol. Cool my quote for new things learned each day has been met. Quote Link to comment https://forums.phpfreaks.com/topic/184218-batch-processing-list-boxes/#findComment-972966 Share on other sites More sharing options...
PFMaBiSmAd Posted December 7, 2009 Share Posted December 7, 2009 The code in the first post 'works', so best guess is either the loop that code is in (if any) is not providing expect values in $result_row or the form processing code is not processing it correctly. Quote Link to comment https://forums.phpfreaks.com/topic/184218-batch-processing-list-boxes/#findComment-972975 Share on other sites More sharing options...
thebadbad Posted December 7, 2009 Share Posted December 7, 2009 I notices you had the parens around the whole thing. Since ive never seen them done like that I was just curious if that was also a valid way? Just curious. It's not only valid but required when it's used like that, in the middle of a larger string. Quote Link to comment https://forums.phpfreaks.com/topic/184218-batch-processing-list-boxes/#findComment-972979 Share on other sites More sharing options...
thebadbad Posted December 7, 2009 Share Posted December 7, 2009 The code in the first post 'works', so best guess is either the loop that code is in (if any) is not providing expect values in $result_row or the form processing code is not processing it correctly. It works, as in runs without syntax errors, but the output is a total mess and includes parts of what's supposed to be PHP code. Quote Link to comment https://forums.phpfreaks.com/topic/184218-batch-processing-list-boxes/#findComment-972981 Share on other sites More sharing options...
_spaz Posted December 8, 2009 Author Share Posted December 8, 2009 You had some major syntax issues in your code, namely your quotes. <?php print "<input type='hidden' name='ID[$i]' value='{$result_row['ID']}' />";?> <?php print "<select name='Priority[$i]' >"; ?> <?php print "<option value=''" . (is_null($result_row['Priority']) ?" selected='selected'":null) . "></option>"; ?> <?php print "<option value='10'" . ($result_row['Priority'] == '10'?" selected='selected'":null) . ">10</option>";?> <?php print "<option value='15'" . ($result_row['Priority'] == '15'?" selected='selected'":null) . ">15</option>";?> <?php print "</select>"; ?> Why in the world are you going in and our of PHP like that? This would be much simpler and works just the same: <?php print "<input type='hidden' name='ID[$i]' value='{$result_row['ID']}' /> <select name='Priority[$i]' > <option value=''" . (is_null($result_row['Priority']) ?" selected='selected'":null) . "></option> <option value='10'" . ($result_row['Priority'] == '10'?" selected='selected'":null) . ">10</option> <option value='15'" . ($result_row['Priority'] == '15'?" selected='selected'":null) . ">15</option> </select>"; ?> So I changed your quotes around on the selected, you were using a single quote after the ? and also using them around the ='selected' that was a syntax issue. Also you will notice on the first ternary I use the is_null function as that is how you have to test if a variable is null, you cannot simply do a comparison. Either way that should work for you. Thanks a bunch guys, ill try that out... I'm new to PHP which is why my code looks ugly:) Quote Link to comment https://forums.phpfreaks.com/topic/184218-batch-processing-list-boxes/#findComment-973443 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.