Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm a beginner in both PHP & MySql and I 've been working with the multiple checkboxes function for days. At first nothing seem to to work but nonetheless, it has finally given the result but I can't seem to create a table out of it

And here is the php page:

<?php


if(isset($_REQUEST['submit']))
{       
    $str = ' 1=1 ';     

    if( count($_POST['field']) > 0 )
    {       
        $field =  implode(',',$_POST['field']);     
        $str.= ' AND company_field LIKE '.$field.'';
    }

    if( count($_POST['size']) > 0 )
    {           
        $size =  implode(',',$_POST['size']); 
        $str.= ' AND company_size LIKE '.$size.'';
    }

    $run = "SELECT * FROM company WHERE 1=1 AND company_field LIKE '$field' AND company_size LIKE '$size'";
    echo $run;
    $result = mysql_query($run);

while ($row = mysql_fetch_array($result)){

    $company_name = $row[0];
    $company_field = $row[1];
    $company_size = $row[2];

?>
<tr align = 'center'>
<th><?php echo $company_name; ?></th>
<td><?php echo $company_field; ?></td>
<td><?php echo $company_size; ?></td>
</tr>
<?php }?>
<?php } ?>  

But I can't create a table and I don't know why.

share|improve this question
1  
sidenote: since you're new to php and mysql, avoid the habit of using deprecated functions, avoid using msql_ functions, use the improved one mysqli_ and use prepared statements. link –  user1978142 Jun 27 at 12:35
    
Thanks, I will have a look through it. –  SlashBunny Jun 27 at 12:45
    
I don't understand the logic of your code. –  Strawberry Jun 27 at 12:45

1 Answer 1

up vote 1 down vote accepted

To properly create a table you need the <table> tags like so:

<table>
    <tr align = 'center'>
        <th><?php echo $company_name; ?></th>
        <td><?php echo $company_field; ?></td>
        <td><?php echo $company_size; ?></td>
    </tr>
</table>

If you're making a new row in your "while" you should put the <table> tag BEFORE your loop and the </table> tag AFTER your loop

share|improve this answer
2  
The align attribute of <table> is not supported in HTML5. Use CSS instead. –  halloei Jun 27 at 12:34

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.