-2

I'm new to Web development programming , and i'm trying to insert a PHP variable into a HTML table with divs, but it's showing me blank

                    <div class="panel-body">
                        <div class="table-responsive">
                            <table class="table table-striped table-bordered table-hover" id="dataTables-example">
                                <thead>

                                    <tr>
                                        <th>sdads</th>
                                        <th>Browser</th>
                                        <th>Platform(s)</th>
                                        <th>Engine version</th>
                                        <th>CSS grade</th>
                                     </tr>

                                </thead>

That's not the full code.

If i wanted to put a PHP variable where <th>sdads</th> is, how i could do that? I tried this: <th><?php echo $test; ?></th>, but it didn't work (the variable is declared on the start of the code by $test="test";

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
sygamers
  • 57
  • 1
  • 1
  • 8
  • Did you assign anything to $test? Does your filename ends with .php? ex: `index.php` – Takoyaro Jun 29 '16 at 17:12
  • 2
    Please, inspect the page and check if there is something that you aren't seeing. Is the file named `something.php?` (Check if the extension is `.php`) – FirstOne Jun 29 '16 at 17:13
  • What do you mean by 'it didn't work' ? Any error or this doesn't work as expected ? What do you have and what are you expecting ? – Hearner Jun 29 '16 at 17:13
  • yes, i did, on the beginning of the tag; – sygamers Jun 29 '16 at 17:14
  • Can you show us all of your file content? Probably you don't set anything into $test variable before you use it. – zajonc Jun 29 '16 at 17:14
  • What was the output when you added the PHP snippet? – Sujeet Sinha Jun 29 '16 at 17:17
  • I can't post full code(exceed limit), but now i tried to declare variable before the encho and the th still empty, the text just disappeared on that column. – sygamers Jun 29 '16 at 17:22

2 Answers2

0

Try

<div class="panel-body">
                    <div class="table-responsive">
                        <table class="table table-striped table-bordered table-hover" id="dataTables-example">
                            <thead>

                                <tr>
                                    <th><?php echo $test; ?></th>
                                    <th>Browser</th>
                                    <th>Platform(s)</th>
                                    <th>Engine version</th>
                                    <th>CSS grade</th>
                                 </tr>

                            </thead>

There is only one reason that it will not work. you have problem with PHP installations or you have error reporting turned off.

Change PHP.ini or if you are a begginer just Download latest xmap and install it

Rishabh Gusain
  • 683
  • 1
  • 6
  • 23
0

Have you tried to code below way? it works fine in my envionment. And must be you have to save the file using .php extension. Thanks.

    <?php $test = 'sdads'; ?>
    <div class="panel-body">
    <div class="table-responsive">
    <table class="table table-striped table-bordered table-hover" id="dataTables-example">
    <thead>

        <tr>
            <th><?php echo $test; ?></th>
            <th>Browser</th>
            <th>Platform(s)</th>
            <th>Engine version</th>
            <th>CSS grade</th>
         </tr>

    </thead>
Asif Uddin
  • 419
  • 6
  • 16