Today's Posts Follow Us On Twitter! TFL Members on Twitter  
Forum search: Advanced Search  
Navigation
Marketplace
  Members Login:
Lost password?
  Forum Statistics:
Forum Members: 24,254
Total Threads: 80,792
Total Posts: 566,472
There are 1432 users currently browsing (tf).
 
  Our Partners:
 
  TalkFreelance     Design and Development     Programming     PHP and MySQL :

Building my table

Thread title: Building my table
Closed Thread    
    Thread tools Search this thread Display Modes  
08-27-2007, 11:38 PM
#1
Haris is offline Haris
Status: Request a custom title
Join date: Dec 2005
Location:
Expertise:
Software:
 
Posts: 2,741
iTrader: 9 / 100%
 

Haris is on a distinguished road

  Old  Building my table

PHP Code:
<table border="1" cellspacing="1" cellpadding="5">
    <tr>
        <th>Questions</th>
        <th>Your Answer</th>
        <?php
        
foreach($closest as $key => $value){
            
$sql_name mysql_query("SELECT * FROM candidates where id ='$key'");
            
$name[] = mysql_fetch_assoc($sql_name);
        }
        
        foreach(
$name as $key => $value){
            echo 
"<th>".$value['name']."</th>";
        }
        
?>
    </tr>
    <?php
        $sql_question 
mysql_query("SELECT * FROM questions");
        while(
$row mysql_fetch_assoc($sql_question)){
            echo 
"<tr>";
            echo 
"<td>".$row['question']."<td>";
            echo 
"</tr>";
        }

        foreach(
$user_answer as $key => $value){
            foreach(
$value as $answer){
                echo 
"<tr>";
                echo 
"<td>".$answer."</td>";
                echo 
"</tr>";
            }
        }
        
    
?>
</table>
How can I build my table on the following patten.

HTML Code:
<table border="1" cellspacing="" cellpadding="5">
    <tr>
        <th>Questions</th>
        <th>Your Answer</th>
        <th>Obama</th>
        <th>Clinton</th>
        <th>Cox</th>
    </tr>
    <tr>
        <td>Are you for or against drilling for energy and oil</td>
        <td>For</td>
        <td>Against</td>
        <td>For</td>
        <td>For</td>
    </tr>
    <tr>
        <td>Are you for or against Embyronic Stem Cells</td>
        <td>For</td>
        <td>For</td>
        <td>For</td>
        <td>For</td>
    </tr>
    <tr>
        <td>Are you for or against death penatly</td>
        <td>Against</td>
        <td>Against</td>
        <td>For</td>
        <td>Against</td>
    </tr>
    <tr>
        <td>Are you for or against education for all childrens</td>
        <td>Against</td>
        <td>Against</td>
        <td>Against</td>
        <td>Against</td>
    </tr>
    <tr>
        <td>Are you for or against same-sex marriage</td>
        <td>For</td>
        <td>Against</td>
        <td>Against</td>
        <td>For</td>
    </tr>
</table>
$closest =
PHP Code:
Array
(
    [
4] => 2
    
[3] => 2
    
[2] => 2

$name =
PHP Code:
Array
(
    [
0] => Array
        (
            [
id] => 4
            
[name] => Brownback
        
)

    [
1] => Array
        (
            [
id] => 3
            
[name] => Biden
        
)

    [
2] => Array
        (
            [
id] => 2
            
[name] => Clinton
        
)


$user_answer =
PHP Code:
Array
(
    [
0] => Array
        (
            [
0] => 1
            
[1] => 2
            
[2] => 2
            
[3] => 1
            
[4] => 2
        
)


I want to base the table on the HTML above but I cannot create it. How would I go about doing it?

Closed Thread    


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

  Posting Rules  
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump:
 
  Contains New Posts Forum Contains New Posts   Contains No New Posts Forum Contains No New Posts   A Closed Forum Forum is Closed