I am trying to use include_once as I get the Fatal error cannot redeclare function() error, but I cannot figure out how to.
The call_trendy() function is inspired by this famous link: Reference - What does this error mean in PHP? But it seems it's used to call a function outside the file, which is not the case in my issue.
<?php
function trendy($Name, $Price, $percent, $trend){
//used to create the winners and losers table
$link = "https://signal-invest.com/tick/?ticker=";
echo "<tr>
<td><a href=\"$link$Name\" style='color:#616161;' >$Name</a></td>
<td>$Price</td><td style='color: "; echo ($percent < 0 ? '#FF0000' : '#4ca64c'); echo ";'>$percent%</td><td>$trend</td></tr>";}
if (file_exists($trendy)) {
include_once($trendy);
}
$query_uptrend= $con -> prepare(my query, which is irrelevant);
$query_uptrend->execute();
$results_query_uptrend = $query_uptrend->get_result();
echo "<body>";
?>
<div class="table_container_frontpage">
<div class="table_latest" style="box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);">
<table style="border-radius: 0.50rem;">
<tr>
<th>NAME</th>
<th>PRICE TODAY</th>
<th>CHANGE</th>
<th>TREND DAYS IN A ROW</th>
</tr>
<?php
foreach ($results_query_uptrend as $res){
$name = $res["Name"];
$Price = number_format((float)$res['Price'], 2, '.', '');
$percent_diff = number_format((float)$res['PercentDiff'], 2, '.', '');
$trend = $res["uptrend"];
echo trendy($name, $Price, $percent_diff, $trend);
}
?>
</table>
</div>
</div>
<?php
?>
Not entirely sure how to include it and make the below error go away.
Fatal error: Cannot redeclare trendy() (previously declared in /var/www/signal-> invest.com/public_html/wp-content/plugins/insert-php-code-snippet/shortcode-> handler.php(97) : eval()'d code:3) in /var/www/signal-invest.com/public_html/wp-> content/plugins/insert-php-code-snippet/shortcode-handler.php(97) : eval()'d code > on line 3
EDIT: Tried below still returns me the Fatal error
if (file_exists($trendy)) {
include_once($trendy);
}