I want to load contacts from a query, Whilst I have found ways to split by the amount of rows I want the result to be split into two columns as below as well as them being a sort of clickable button.Is it possible to display the query results as described below by the use of HTML or by the query itself? :
Contacts
------------------------------
Albert Smith | Ben Marshall
Benjamin Jones | Chris Jones
I have tried the code below
<?
$rowcount = mysql_num_rows($records);
echo "<div id='column1'>";
$i = 0;
while ($d = mysql_fetch_object($records)) {
echo $d->name;
$i++;
if ($i == floor($rowcount / 2)) {
echo "</div><div id='colums2'>";
}
}
echo "</div>";
?>
But this splits the columns by reaching half of the results in 1 column and the rest in another column
Albert Smith | Benjamin Jones
Ben Marshall | Chris Jones
This is not possible by query itself. You must parse the result with an html <table>
, every two results make a new <tr>
and double <td>
I'm guessing you are conversant with coding: Check this algorithm
loop through your result-set
List item
increment the counter in each loop
ii. check counter value in the loop
Let me know on how it works out. Have fun coding.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.