--- In [email protected], James Keeline <[EMAIL PROTECTED]> wrote: > > --- whoisquilty <[EMAIL PROTECTED]> wrote: > > > I'd like to be able to return results from a query in two columns of a > > table. > > > > First result in column 1, row 1. > > Second result in column 2, row 1. > > Third results in column 1, row 2. > > Fourth result in column 2, row 2. > > > > How would I do this? I thought about using if's. > > > > Is there a command to return results with different code for every > > other result? > > > > Jeremy > > Are you concerned with the HTML display of this data or the SQL query? Are > there only four results or is this a simple example? > > In the case of an HTML table, it looks like you would have: > > +--------+---------+ > | First | Second | > +--------+---------+ > + Third | Fourth | > +--------+---------+ > > If so, then you want each result to display in its own <td> element. However, > after every even result, you want to insert a </tr><tr> to drop to the next row > of the HTML table. If this is an arbitrary length then we could be concerned > with an extra open <tr> at the end. > > $db = mysql_connect(...); > $resource = mysql_query(..., $db); > $result = 1; > $html = "<table><tr>"; > while ($data = mysql_fetch_row($resource)) > { > $html .= sprintf("<td>%s</td>", $data[0]); > $html .= ($result++ %2) ? "</tr><tr>" : ""; > } > $html = substr($html, 0, -4); // get rid of last four characters ("<tr>") > print $html; > > Doubtless this will need to be refined for your needs. > > James >
Thanks, James. That's a great start and gives me a good idea of what I need to do.
