• Resolved yousrakasmi

    (@yousrakasmi)


    Hi,

    I want to display some data “in a table already created in my website” from my database.

    I have already created a part of code to filled my table with the data already stored in my database as follows:

    // creation of my table
    	<div class="my_box3">
    
                	<div class="box_title"><?php echo __("Title"); ?></div>
                    <div class="box_content">
    				<table border="1">
    				<tr><th>A1</th><th>City</th><th>A2</th><th>A3</th><th>A4</th></tr>
    				<?php 
    
    // fill my table with recovered data				$ci=array_filter(get_post_meta(get_the_ID(),'CITY')[0]);
    
    				$ci=array_values($ci);
    				for($i=0;$i<count($ci);$i++)
    				{?>
    				<tr><td><?php echo load_by_id($co[$i],"table","ID",$wpdb)->NAME;?>
    					<?php }?>
    					</table>
    					</div>
    					</div>

    It’s running locally on my PC but when I put In in my cPanel I get this error message:

    Parse error: syntax error, unexpected ‘[‘ in /home/MyFolder

    in this line:
    $ci=array_filter(get_post_meta(get_the_ID(),’CITY’)[0]);

    I already delete the ‘[‘ but it still doesn’t work, all I get is a table with array()!!

    is there another command to replace this!!

    Any help will be appreciated and Thanks in advance

Viewing 3 replies - 1 through 3 (of 3 total)
  • What is the cPanel you refer? You mean Dashboard Post Editor? If so, please be aware it will not accept php by default. It’s recommended to write your php in WordPress PHP Templates

    You can’t have all of that on one line – at least in some PHP versions, or settings. Web hosts are most likely more “secured” than your home setup, so they won’t normalyl be as permissive on issues like this.

    What you need to do is get the value, then apply the filters like this:

    $ci = get_post_meta( get_the_ID(), 'CITY' );
    $ci = array_filter( $ci[0] );

    Or, you can just get the first value like this:

    $ci = array_filter( get_post_meta( get_the_ID(), 'CITY', true ) );

    Thread Starter yousrakasmi

    (@yousrakasmi)

    Many thanks catacaustic,

    Your suggestions have been very useful and now eveythign is working properly.

    Thanks again.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘display results in a table from the database’ is closed to new replies.