larsbrimmer Posted February 1, 2009 Share Posted February 1, 2009 I get an error with this. I guess I don't understand how to string the HTML and PHP together. <?php $List1 .= "<option value='{$row['ID']} if(!(strcmp($row['ID'],$row['ID'])))echo"selected">{$row['Title']}</option>\n"; ?> -lars Link to comment https://forums.phpfreaks.com/topic/143352-help-with-basic-php-syntax/ Share on other sites More sharing options...
ashishag67 Posted February 1, 2009 Share Posted February 1, 2009 You can try this <option value="<?php echo $row['ID'];?>" <?php if(!strcmp($row['ID'], $row['ID'])) echo "selected";?>><?php echo $row['Title'];?></option> Hope this works for you. Cheers Link to comment https://forums.phpfreaks.com/topic/143352-help-with-basic-php-syntax/#findComment-751845 Share on other sites More sharing options...
larsbrimmer Posted February 1, 2009 Author Share Posted February 1, 2009 Not sure I can do all that in the middle of this. <?php while ($row = mysql_fetch_assoc($result)) { $List1 .= "<option value='{$row['ID']} if(!(strcmp($row['ID'],$row['ID'])))(echo'selected'>{$row['Title']}</option>\n"; } ?> Link to comment https://forums.phpfreaks.com/topic/143352-help-with-basic-php-syntax/#findComment-751856 Share on other sites More sharing options...
corbin Posted February 1, 2009 Share Posted February 1, 2009 "<option value='{$row['ID']}" . (!(strcmp($row['ID'],$row['ID']))) ? 'selected' : '' . ">{$row['Title']}</option>\n"; That's a ternary clause in there by the way. Edit: Oh by the way, comparing something to itself doesn't make much sense to me. Link to comment https://forums.phpfreaks.com/topic/143352-help-with-basic-php-syntax/#findComment-751858 Share on other sites More sharing options...
larsbrimmer Posted February 1, 2009 Author Share Posted February 1, 2009 I was comparing the id so the drop down value would stay selected after the on click. Link to comment https://forums.phpfreaks.com/topic/143352-help-with-basic-php-syntax/#findComment-751863 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.