0

Hello everyone,
I used session and the id of the selected checkbox are passed to another page currently.
now I do another query based on the ID of the selected checkbox.
I want to display the fields from the selected result in columns like this
http://www.bluenile.co.uk/diamond_co...OMPARISON_STEP

I did this

<?
	foreach($acb as $key => $value)
	    {
	    echo 'The value of $_SESSION['."'".$key."'".'] is '."'".$value."'".' <br />';
		//print out the values
	 
			$query = "SELECT * from lesson WHERE lessonID ='".$value."'" ;
			$result = mysql_query( $query, $con); 
	        $result_array = mysql_fetch_array($result);
	//echo $query;
	// for each pice of info saved in array, display it to users
	echo '<table>';
	foreach($result_array as $key => $value)
	//while($row = mysql_fetch_array($result_array))
	{
			if (!is_int($key))
			{
	 
		echo '<tr><td>Lesson ID</td><td>'.$result_array['lessonID'].'</td></tr>';
		echo '<tr><td>Year</td><td>'.$result_array['year'].'</td></tr>';
		echo '<tr><td>Subject</td><td>'.$result_array['subject'].'</td></tr>';
		echo '<tr><td>Learning Area</td><td>'.$result_array['learningArea'].'</td></tr>';
		echo '<tr><td>Topic</td><td>'.$result_array['topic'].'</td></tr>';
		echo '<tr><td>Learning Outcome</td><td>'.$result_array['LO'].'</td></tr>';
			}
	}
	echo '</table>';
      }
	?>

the result returned like this

Lesson ID 52
Year 4
Subject ICT
Learning Area Computer Systems
Topic Hardware
Learning Outcome Storage
Lesson ID 52
Year 4
Subject ICT
Learning Area Computer Systems
Topic Hardware
Learning Outcome Storage
Lesson ID 52
Year 4
Subject ICT
Learning Area Computer Systems
Topic Hardware
Learning Outcome Storage

it is loops for several times before showing the next records from the selected checkbox (also several times).
I want to have them displayed in columns like the example above.
can anyone help?
thankyou

3
Contributors
5
Replies
6
Views
7 Years
Discussion Span
Last Post by tulipputih
0

It displayed exactly as you defined it. If you want the data in columns, then don't use a <tr><td> before every field, just use <td>. Every time you echo a <tr> you get a new line.

0
if (mysql_num_rows($result) > 0) { 
    // yes 
    // print them one after another 
    echo "<table cellpadding=10 border=1>"; 
    while($row = mysql_fetch_row($result)) { 
        echo "<tr>"; 
        echo "<td>".$row[0]."</td>"; 
        echo "<td>" . $row[1]."</td>"; 
        echo "<td>".$row[2]."</td>"; 
        echo "</tr>"; 
    } 
    echo "</table>"; 
}

Dont assign everytime the headings

Edited by rajarajan07: n/a

0

thank you rajarajan,
i changed the code according to your suggestion,
but there is no data displayed now.
if two checkboxes is selected, there will be three columns
(1st the field, 2nd -the records of the 1st checkbox, 3rd-the records of the 2st checkbox.
any suggestions?
thank you

0

Result is returned as in my previous posting.
the thing is just to display the result in comparable table like here http://www.bluenile.co.uk/diamond_co...OMPARISON_STEP

now the fields name is displayed in the left column, it 's right but it's looping so many times. I just want to make it once.
the results are they but they looping together with the fields name. I want the result to be presented side by side.
Any suggestions?
thank you

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.