Question : PHP Print Values of Two Database Fields in One HTML Table

Hello experts,

I would like to compare two different products that exist in a table. At the moment I use two queries for this, one for each product. What I'd like to do is print the results in one table so the it would look like:

num          001       002
name      item1     item2
year       2010      2009
...

In html that would be:
<table>
     <tr>
          <th>num</th>
          <td>001</td>
          <td>002</td>
     </tr>
     <tr>
          <th>name</th>
          <td>item1</td>
          <td>item2</td>
     </tr>
     <tr>
          <th>year</th>
          <td>2010</td>
          <td>2009</td>
     </tr>
...

I can loop through and print two tables but combining them into one is proving tricky. Here's a snippet of code that I use to print one table of values. Any help much appreciated?
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
// Iterate through all items in array.
foreach ($row as $key => $value) {

// Don't show any items that end with '_id'.
if(!preg_match('/_id$/', $key)) {

    // Remove underscore of all field names.
    $key = str_replace("_", " ", $key);
	// Capitalize the first letter of each word.
	$key = ucwords($key);

	// Print results.
	echo '<tr>
	<th>'.$key.'</th>
	<td>';
	// Check if <br /> exists in $value.
	if (preg_match("/\r\n/", $value)) {
	    $new_value = explode("\r\n", $value);
	    echo '<ul class="square">';
	    foreach ($new_value as $n_row => $n_value) {
	        echo '<li>'.$n_value.'</li>';
	    }
	    echo '</ul>';
	} else {
       	    echo nl2br(stripslashes($value));
	}
	echo '</td>
	</tr>';
        }

Answer : PHP Print Values of Two Database Fields in One HTML Table

>>when i give like

System.out.printf( "Welcome to the grade book for\n%s!\n"+courseName );
>>

because it's expecting a parameter, which you're not giving it. See aforementioned docs
Random Solutions  
 
programming4us programming4us