Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Print tables with horizontal output.

Status
Not open for further replies.

joep

Programmer
Jun 4, 2000
15
NL
Hello,<br><br>I want to print the results of a query horizontal in colums instead of the usual rows.<br>'Normally':<br>result 1<br>result 2<br>result 3<br>etc.<br><br>My idea:<br>result 1 ¦ result 2 ¦ result 3 ¦ etc.<br><br>I thought something out like this:<br>&lt;?<br>$sql = &quot;SELECT * FROM access WHERE bla bla bla &quot;;<br>$result = mysql_query($sql);<br>$number = MYSQL_NUMROWS($result);<br>$i = 0;<br><br>echo &quot;&lt;table border=2 bordercolor=red&gt;&lt;tr&gt;&lt;td&gt;&quot;; <br>{<br>while ($i &lt; $number)<br>$pakket = mysql_result($result, $i, pakket);<br>&nbsp;&nbsp;<br>echo &quot;&lt;table border=1&gt;&lt;tr&gt;&lt;td&gt;$pakket&lt;/td&gt;&quot;;<br>if ($i == '1')<br>{echo &quot;&lt;td&gt;&lt;/td&gt;&quot;;}<br><br>if ($i == '2')<br>{echo &quot;&lt;td&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&quot;;}<br><br>echo &quot;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&quot;;<br>}<br>echo &quot;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&quot;;<br>}<br>?&gt;<br><br>But that won't work. Who can help me?<br>Greets,<br><br>Joep
 
Try it like this<br><br>print (&quot;&lt;TD&gt;&lt;font size='2'&gt;$blah blah&lt;/font&gt;&lt;/TD&gt;\n&quot;);<br><br>print (&quot;&lt;TD&gt;&lt;font size='2'&gt;$blah blah&lt;/font&gt;&lt;/TD&gt;\n&quot;);<br><br>Rhyan
 
There is a much easier way Try this<br>//Set this number to be the number of cells across that you want<br>$cols = 4;<br>$counter = 1;<br><br>$sql = &quot;SELECT * FROM access WHERE bla bla bla &quot;;<br>$result = mysql_query($sql);<br><br>print '&lt;table&gt;&lt;tr&gt;';<br>while ($myrow = mysql_fetch_array($result)) {<br>&nbsp;&nbsp;if (is_int($counter / $cols)) {<br>&nbsp;&nbsp;&nbsp;&nbsp;print '&lt;td&gt;'. $myrow[&quot;fieldname&quot;] .'&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;';<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;else {<br>&nbsp;&nbsp;&nbsp;&nbsp;print '&lt;td&gt;'. $myrow[&quot;fieldname&quot;] .'&lt;/td&gt;';<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>$counter++;<br>}<br>print '&lt;/tr&gt;&lt;/table&gt;';
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top