-2

I am trying to displaying a table generated from MySQL database. In the table I want the first column to have a radio button and the last column to have a clickable icon.

The following is my code so far:

<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
?>

<html>
<head>
  <title></title>
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
</head>
<body>
<?php
$hostname = "localhost";
$username = "root";
$password = "";
$database = "test";
$connect = mysqli_connect($hostname, $username, $password, $database );

$sql = "select image_id as id,substring(`imagename`,-9) as Image, `locationName` as Location, `brandname` as Brand FROM `annotations` where `status`='manual'";
$result = mysqli_query($connect,$sql)or die(mysqli_error());

echo "<table class=table table-responsive style='width:50px'>";
echo "<thead><tr><th>Select</th><th>Image</th><th>Location</th><th>Brand</th><th>Run</th></tr></thead>";

while($row = mysqli_fetch_array($result)) {
    $ID = $row['id'];
    $Image = $row['Image'];
    $Location = $row['Location'];
    $Brand = $row['Brand'];
    echo "<tbody><form><tr>
    <td><div class="radio"><label>
      <input type="radio" id=".$ID." value=".$ID." name="manualTab"/>
    </label></div></td>
    <td>".$Image."</td>
    <td>".$Location."</td>
    <td>".$Brand."</td>
    <td>".$Brand."</td>
    </tr></tbody></form>";

} 

echo "</table>";
mysqli_close($connect);


?>
</body>
</html>

I am able to generate the table without the radio button and I have not even tried to include the icon in the last column yet. However, when I include the lines for Radio button, the table doesn't get generated. I have tried various combinations of this code and none of them were rendering table with radio buttons.

Errors: When I run this on Firefox, i am getting any errors reported. When I run it on Chrome, I am getting a message, HTTP Error 500 This page is not loading. I am not getting any parse error or mysqli errors as construed by some of the admins.

popeye
  • 281
  • 5
  • 20
  • what errors u get? – Mohit Kumar Mar 11 '18 at 13:46
  • @MohitKumar No errors at all. I have these lines at the top of the page....`error_reporting(E_ALL); ini_set('display_errors', 1);` – popeye Mar 11 '18 at 13:47
  • 1
    you should be getting parse errors. you may not be getting them because your query failed and it never reaches the loop. – Funk Forty Niner Mar 11 '18 at 13:49
  • @FunkFortyNiner - Parse errors are raised before any code is executed. – Paul Spiegel Mar 11 '18 at 13:58
  • @PaulSpiegel I tend to think that if their query failed, it wouldn't get as far as to where the php syntax errors are. Their `mysqli_error()` is missing a parameter for it, so that to me says their query failed if no errors are thrown for the php. I added the duplicate for that one also. – Funk Forty Niner Mar 11 '18 at 14:01
  • @FunkFortyNiner I fail to understand how the links provided as duplicates answer my question. When I am searching for answers, as I was not getting parse errors, I wouldn't be looking for the link shared and I was not getting mysqli_error too. I have updated the question with the error_reporting parameters as I have it in my page.... – popeye Mar 11 '18 at 14:07
  • @popeye but rest of radio , icon at last , can you get generated dynamic table data??? – Mohit Kumar Mar 11 '18 at 14:08
  • @MohitKumar Yes of course....The table is getting generated with all the values. No problem at all – popeye Mar 11 '18 at 14:11
  • then according to @chrysovalantis-koutsoumpos demo implement ur code.u do it. – Mohit Kumar Mar 11 '18 at 14:13

1 Answers1

2

Your error is <div class="radio"> It should be <div class='radio'>

Another error is name="manualTab" It should be name='manualTab'

Please enable your errors and try to replicate the following working example.

<table>
  <thead>
    <tr>
      <th>Select</th>
      <th>Data</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>
        <input value="1" id="type_radio_1" name="type_radio" type="radio" />
      </td> 
      <td>
        Data 1
      </td>
    </tr>
    <tr>
      <td>
        <input value="2" id="type_radio_2" name="type_radio" type="radio" />
      </td> 
      <td>
        Data 2
      </td>
    </tr> 
  </tbody>
  • ...thank you...I have seen similar examples here...the problem is I am generating the table dynamically and my variables would vary...hence I am using $ID as it is unique from mysql table. – popeye Mar 11 '18 at 14:01
  • but rest of radio , icon at last , can you get generated dynamic table data??? – Mohit Kumar Mar 11 '18 at 14:05
  • My example is just there in order to visualise the table with the radio button. Try to fix the errors I pointed out and if your query is correct it should be fine. Of course your can have dynamic table (your code of course not the correct way but it will do your job) In order to add an image you need an `` tag with `src` attribute pointing to the location of the image (you probably have it saved in your database) – Chrysovalantis Koutsoumpos Mar 11 '18 at 14:09
  • @ChrysovalantisKoutsoumpos Sorry...I forgot to include in my earlier comment..I have made the changes you suggested...but it is not helping. – popeye Mar 11 '18 at 14:13
  • @ChrysovalantisKoutsoumpos Thank you for providing me the ques...The following worked for me. `
    `
    – popeye Mar 11 '18 at 14:29