DataSpy Posted May 25, 2010 Share Posted May 25, 2010 Basically I'm trying to get a value from a database and use an if elseif else to reassign the variable but I'm getting a 'Use of undefined constant' error. Error Notice: Use of undefined constant Yes - assumed 'Yes' in /opt/lampp/htdocs/xampp/www/test.php on line 137 Code while($row = mysql_fetch_array($result)){ $main_title = $row['main_title']; $romanji = $row['romanji']; $link = $row['link']; $episodes = $row['episodes']; $complete = $row['complete']; $disc_num = $row['disc_num']; $type = $row['type']; $format = $row['format']; $extention = $row['extention']; $fsgroup = $row['fsgroup']; if($complete == "1"){ $complete = Yes; <== this is line 137 } elseif($complete == "2"){ $complete = No; }else { $complete = NA; } This is user enter data and the choices are Yes, No, or NA from a drop down menu Would it be better to: 1. Store Yes, No, NA in the database 2. Store 1,2,3 in the database and use a conditional against them (which is what I'm trying to do now) 3. Have a separate table for Yes, No, and NA Even though I know I won't use it I'm trying to make the database as efficient as possible, it's more of a learning thing. Any help would be greatly appreciated, thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/202890-undefined-constant/ Share on other sites More sharing options...
kenrbnsn Posted May 25, 2010 Share Posted May 25, 2010 Strings need to be enclosed in quotes (either single or double) <?php if($complete == "1"){ $complete = 'Yes'; <== this is line 137 } elseif($complete == "2"){ $complete = 'No'; }else { $complete = 'NA'; } ?> But you really shouldn't be using the same variable: <?php if($complete == "1"){ $complete1 = 'Yes'; <== this is line 137 } elseif($complete == "2"){ $complete1 = 'No'; }else { $complete1 = 'NA'; } ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/202890-undefined-constant/#findComment-1063259 Share on other sites More sharing options...
Psycho Posted May 25, 2010 Share Posted May 25, 2010 Would it be better to: 1. Store Yes, No, NA in the database 2. Store 1,2,3 in the database and use a conditional against them (which is what I'm trying to do now) 3. Have a separate table for Yes, No, and NA 1. For your purposes, I would say yes. Unless there is some functional reason for using 1,2,3 I'd just use the values (see exceptions below). 2. This makes sense if you have some functional use for those values. One option could be to use 0 for false (no), 1 for true (yes) and NULL for N/A. you could then use the value directly in your logic without comaprisons to strings. 3. This makes sense if the list is not static (can be added or removed from) or if you want to allow the application to be used for different languages. Quote Link to comment https://forums.phpfreaks.com/topic/202890-undefined-constant/#findComment-1063265 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.