freaker87 Posted April 9, 2012 Share Posted April 9, 2012 hi, i have mysql table like table1 table2 ----------------------- ------------------------ | A | B | | 1 | 2 | | C | D | | 3 | 4 | | E | F | ---------------------------- ------------------------ now i want to display them in html table cells(td)... like -------------------------------------------------------------------------------- A | B | 1 | 2 -------------------- C | D | 3 | 4 --------------------- E | F | ---------------------- ok i was trying this it in while looping but unable to do soo........... Quote Link to comment Share on other sites More sharing options...
Psycho Posted April 9, 2012 Share Posted April 9, 2012 Your "mock" data is not of much value. I assume that both tables have at least two columns (i.e. fields) which you are displaying above. So, record 1 in the first table have values of "A" and "B". But, what is not apparent is what the relationship is between the records in table 1 and the records in table 2. Typically you would have a unique primary ID in one table and then use that as a foreign key in another table. Examples: Table 1 id | letter1 | letter2 6 A B 7 C D 8 E F Table 2 letter_id | number1 | number2 6 1 2 7 3 4 It's impossible to provide a solution without more info. Quote Link to comment Share on other sites More sharing options...
freaker87 Posted April 10, 2012 Author Share Posted April 10, 2012 This is my code which i am trying & Psycho i've made my table like you did..... <?php echo '<tr> <th>other1</th> <th>other2</th> <th>other3</th> <th>other4</th> <th>other5</th> <th>other6</th> <th>M.no</th> <th>letter1</th> <th>letter2</th> <th>number1</th> <th>number1</th> <th>Qty</th> </tr>'; $qry = "select * from table"; $result= mysql_query($qry,$link); $nro=mysql_num_rows($result); while($row = mysql_fetch_array($result1)) { $other1 = $row['other1']; $other2 = $row['other2']; $other3 = $row['other3']; $other4 = $row['other4']; $other5 = $row['other5']; $other6 = $row['other6']; $mno = $row['mnubmer']; echo '<tr> <td>'.$other1.'</td> <td>'.$other2.'</td> <td>'.$other3.'</td> <td>'.$other4.'</td> <td>'.$other5.'</td> <td>'.$other6.'</td> <td>'.$mno.'</td>'; $qry1 = "select * from table1"; $result1= mysql_query($qry1,$link); $nro1=mysql_num_rows($result1); $ccnt = 1; while($row1 = mysql_fetch_array($result1)) { $letter1 = $row1['letter1']; $letter2 = $row1['letter2']; $qty = $row1['quality']; if($ccnt == 1) { echo '<td>'.$letter1.'</td> <td>'.$letter2.'</td>'; } else { echo '<tr> <td>'." ".'</td> <td>'." ".'</td> <td>'." ".'</td> <td>'." ".'</td> <td>'." ".'</td> <td>'." ".'</td> <td>'." ".'</td> <td>'.$letter1.'</td> <td>'.$letter2.'</td>'; } $qry2 = "select * from table2"; $result2= mysql_query($qry2,$link); $nro2=mysql_num_rows($result2); $row2 = mysql_fetch_array($result2); while($row2 = mysql_fetch_array($result1)) { $number1 = $row2['number1']; $number2 = $row2['number2']; echo '<td>'.$$number1.'</td> <td>'.$number2.'</td> <td>'.$$qty.'</td></tr>'; $ccnt = 0; } } } echo "</table>"; ?> Here is the image what i want to do..... Quote Link to comment Share on other sites More sharing options...
Muddy_Funster Posted April 10, 2012 Share Posted April 10, 2012 post up accurate table information please, your using select * so all we know is your table names, not your field names. We also need to know keys and relations. You're also running 1 query within the return loop of another - that's just naughty. Quote Link to comment Share on other sites More sharing options...
freaker87 Posted April 10, 2012 Author Share Posted April 10, 2012 <?php echo '<tr> <th>other1</th> <th>other2</th> <th>other3</th> <th>other4</th> <th>other5</th> <th>other6</th> <th>M.no</th> <th>letter1</th> <th>letter2</th> <th>number1</th> <th>number1</th> <th>Qty</th> </tr>'; $qry = "select * from table"; $result= mysql_query($qry,$link); $nro=mysql_num_rows($result); while($row = mysql_fetch_array($result1)) { $other1 = $row['other1']; $other2 = $row['other2']; $other3 = $row['other3']; $other4 = $row['other4']; $other5 = $row['other5']; $other6 = $row['other6']; $mno = $row['mnubmer']; echo '<tr> <td>'.$other1.'</td> <td>'.$other2.'</td> <td>'.$other3.'</td> <td>'.$other4.'</td> <td>'.$other5.'</td> <td>'.$other6.'</td> <td>'.$mno.'</td>'; $qry1 = "select * from table1 where other1='$other1'"; $result1= mysql_query($qry1,$link); $nro1=mysql_num_rows($result1); $ccnt = 1; while($row1 = mysql_fetch_array($result1)) { $letter1 = $row1['letter1']; $letter2 = $row1['letter2']; $qty = $row1['quality']; if($ccnt == 1) { echo '<td>'.$letter1.'</td> <td>'.$letter2.'</td>'; } else { echo '<tr> <td>'." ".'</td> <td>'." ".'</td> <td>'." ".'</td> <td>'." ".'</td> <td>'." ".'</td> <td>'." ".'</td> <td>'." ".'</td> <td>'.$letter1.'</td> <td>'.$letter2.'</td>'; } $qry2 = "select * from table2 where other1='$other1'"; $result2= mysql_query($qry2,$link); $nro2=mysql_num_rows($result2); $row2 = mysql_fetch_array($result2); while($row2 = mysql_fetch_array($result1)) { $number1 = $row2['number1']; $number2 = $row2['number2']; echo '<td>'.$$number1.'</td> <td>'.$number2.'</td> <td>'.$$qty.'</td></tr>'; $ccnt = 0; } } } echo "</table>"; ?> and this is the accurate code i am using and accurate field name Quote Link to comment Share on other sites More sharing options...
Muddy_Funster Posted April 10, 2012 Share Posted April 10, 2012 I was really looking for the results of "DESCRIBE table1" and "DESCRIBE table2" if you would be so kind. Quote Link to comment Share on other sites More sharing options...
caliux Posted April 10, 2012 Share Posted April 10, 2012 try while($row1 = mysql_fetch_array($result1) && $row2 = mysql_fetch_array($result2) ) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.