lauradesigner Posted September 9, 2010 Share Posted September 9, 2010 I want half of the results to to show up with a hyperlink (if I've added the link as a field in my CSV file) and half of the results to show up with no hyperlink. The link URL's are located in field 8 of a database : [8] as seen below. Could anyone help me to figure out how to add an "if" statement perhaps? Something like "if 8 true" then display "<a href"? I did not write this php code I am only modifying it. The csv file is very very straightforward, but this PHP is beyond me. Would appreciate the help! <p><a href="<?=htmlspecialchars($r[8])?>"><?=htmlspecialchars($r[1])?></a><br /> <?=htmlspecialchars($r[2])?><br /> <?=htmlspecialchars($r[3])?><br /> <?=htmlspecialchars($r[4])?><br /> <?=htmlspecialchars($r[5])?><br /> <a href="mailto:<?=htmlspecialchars($r[7])?>"><?=htmlspecialchars($r[7])?></a> </p> Link to comment https://forums.phpfreaks.com/topic/212972-ignore-field-if-no-data-php-and-csv-file/ Share on other sites More sharing options...
schilly Posted September 9, 2010 Share Posted September 9, 2010 <?= ?> is the same as <?php echo ?> so <?=htmlspecialchars($r[2])?> is just <?php echo htmlspecialchars($r[2]); ?> so if field 8 has a link put in a link, if not dont add the link? <p><?=(!empty(htmlspecialchars($r[8]))) ? "<a href=\"" . htmlspecialchars($r[8]) . "\">" . htmlspecialchars($r[1]) . "</a>" : htmlspecialchars($r[1])?><br /> <?=htmlspecialchars($r[2])?><br /> <?=htmlspecialchars($r[3])?><br /> <?=htmlspecialchars($r[4])?><br /> <?=htmlspecialchars($r[5])?><br /> <a href="mailto:<?=htmlspecialchars($r[7])?>"><?=htmlspecialchars($r[7])?></a> </p> That says if field 8 is not empty output field 1 with the link on it else just output field 1. Let me know if that's not what you meant. Link to comment https://forums.phpfreaks.com/topic/212972-ignore-field-if-no-data-php-and-csv-file/#findComment-1109233 Share on other sites More sharing options...
lauradesigner Posted September 9, 2010 Author Share Posted September 9, 2010 I put it in but it doesn't work. This is the error: Fatal error: Can't use function return value in write context in /home/edgecre/www/www/contact.php on line 21 Thanks for the quick reply. Let me know if you have other ideas or a variation on this one. Link to comment https://forums.phpfreaks.com/topic/212972-ignore-field-if-no-data-php-and-csv-file/#findComment-1109247 Share on other sites More sharing options...
schilly Posted September 9, 2010 Share Posted September 9, 2010 bah. try this. syntax error. <p><?=(!empty($r[8])) ? "<a href=\"" . htmlspecialchars($r[8]) . "\">" . htmlspecialchars($r[1]) . "</a>" : htmlspecialchars($r[1])?><br /> <?=htmlspecialchars($r[2])?><br /> <?=htmlspecialchars($r[3])?><br /> <?=htmlspecialchars($r[4])?><br /> <?=htmlspecialchars($r[5])?><br /> <a href="mailto:<?=htmlspecialchars($r[7])?>"><?=htmlspecialchars($r[7])?></a> </p> Link to comment https://forums.phpfreaks.com/topic/212972-ignore-field-if-no-data-php-and-csv-file/#findComment-1109255 Share on other sites More sharing options...
lauradesigner Posted September 9, 2010 Author Share Posted September 9, 2010 that worked great! You are a life saver. Thank you!!! Link to comment https://forums.phpfreaks.com/topic/212972-ignore-field-if-no-data-php-and-csv-file/#findComment-1109266 Share on other sites More sharing options...
schilly Posted September 9, 2010 Share Posted September 9, 2010 welcome =) Link to comment https://forums.phpfreaks.com/topic/212972-ignore-field-if-no-data-php-and-csv-file/#findComment-1109279 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.