lingo5 Posted April 12, 2010 Share Posted April 12, 2010 Hi, I have this query to display results in one column and multiple rows: $query_asociados_RS = "SELECT * FROM t_empresas ORDER BY E_nombre ASC"; $asociados_RS = mysql_query($query_asociados_RS, $amat_connect) or die(mysql_error()); $row_asociados_RS = mysql_fetch_assoc($asociados_RS); $totalRows_asociados_RS = mysql_num_rows($asociados_RS); $queryString_asociados_RS = ""; if (!empty($_SERVER['QUERY_STRING'])) { $params = explode("&", $_SERVER['QUERY_STRING']); $newParams = array(); foreach ($params as $param) { if (stristr($param, "pageNum_asociados_RS") == false && stristr($param, "totalRows_asociados_RS") == false) { array_push($newParams, $param); } } if (count($newParams) != 0) { $queryString_asociados_RS = "&" . htmlentities(implode("&", $newParams)); } } $queryString_asociados_RS = sprintf("&totalRows_asociados_RS=%d%s", $totalRows_asociados_RS, $queryString_asociados_RS); ?> It works fine, but I need to display the results in 6 columns and multiple rows. I don't know how to do this, so any help would be very much appreciated. Thanks all. Link to comment https://forums.phpfreaks.com/topic/198289-help-with-results-in-multiple-columns/ Share on other sites More sharing options...
Ken2k7 Posted April 12, 2010 Share Posted April 12, 2010 I have no idea what you're talking about. You need to be more specific. The query only returns however many columns you have in the table. If you want to return 6 columns, what are the columns for? Your post is just not specific enough and it doesn't give us any information regarding what your issue. I can be a wise guy and just write a query that returns 6 columns with result, but I doubt they are the result you're looking for. So please elaborate. Link to comment https://forums.phpfreaks.com/topic/198289-help-with-results-in-multiple-columns/#findComment-1040422 Share on other sites More sharing options...
lingo5 Posted April 12, 2010 Author Share Posted April 12, 2010 Hi Ken, sorry about that. What that query returns is 1 row for each registry on the DB like this: associate 1 associate 2 associate 3 etc.... I would like the rsults to show like this: associate 1 | associate 2 | associate 3 associate 4 | associate 5 | associate 6 etc... Is this any clearer now?. Thanks Link to comment https://forums.phpfreaks.com/topic/198289-help-with-results-in-multiple-columns/#findComment-1040431 Share on other sites More sharing options...
Ken2k7 Posted April 12, 2010 Share Posted April 12, 2010 Well, that's a display problem, not a query problem. Let's say the results of the query is stored in the variable $results. Then you can loop through it as such: <table><tr> <?php $cols_per_row = 3; $count = 1; while ($result = mysql_fetch_assoc($results)) { if ($count == $cols_per_row) { $count = 1; echo "</tr><tr>"; } $value = $results['col_name']; if (empty(trim($value))) $value = " "; echo sprintf("<td>%s</td>", $value); $count++; } while ($count < $cols_per_row) echo "<td> </td>"; ?> </tr></table> Does that make some sense? Link to comment https://forums.phpfreaks.com/topic/198289-help-with-results-in-multiple-columns/#findComment-1040436 Share on other sites More sharing options...
lingo5 Posted April 12, 2010 Author Share Posted April 12, 2010 Thanks Ken2k7 , but me being very new to php I don't really know where I should place the code you suggest. Please could you help me with it? Link to comment https://forums.phpfreaks.com/topic/198289-help-with-results-in-multiple-columns/#findComment-1040442 Share on other sites More sharing options...
Ken2k7 Posted April 12, 2010 Share Posted April 12, 2010 lingo5, it's not a copy and paste. My sample code is to demonstrate how it would be done. If you understand how the code works, you should be able to replicate the same effect in your code. Link to comment https://forums.phpfreaks.com/topic/198289-help-with-results-in-multiple-columns/#findComment-1040444 Share on other sites More sharing options...
lingo5 Posted April 12, 2010 Author Share Posted April 12, 2010 at the moment this is how I display my results: <?php do { ?> <table width="100%" border="0" cellpadding="11" cellspacing="0" class="asociadoBottomBorder"> <tr<?php > <td width="21%" align="left" valign="middle" class="BodyText" ><div align="left"><a href="detalle_asociados.php?id_E=<?php echo $row_asociados_RS['id_E']; ?>"><img src="uploads/<?php echo $row_asociados_RS['E_logo']; ?>" alt="" width="150" border="1" /></a></div></td> <td width="79%" height="60" align="left" valign="middle" class="BodyText"><a href="detalle_asociados.php?id_E=<?php echo $row_asociados_RS['id_E']; ?>" class="nombreFichaAsociado"><?php echo $row_asociados_RS['E_nombre']; ?></a></td> </tr> </table> <?php } while ($row_asociados_RS = mysql_fetch_assoc($asociados_RS)); ?></td> </tr> ?> Link to comment https://forums.phpfreaks.com/topic/198289-help-with-results-in-multiple-columns/#findComment-1040446 Share on other sites More sharing options...
lingo5 Posted April 16, 2010 Author Share Posted April 16, 2010 Thanks Ken2k7, but I don't quite understand how to use that code. Could you please have a look at the codeI use at the moment to display the results and help me implement the one you suggested? am really stuck with this. Thanks again. Link to comment https://forums.phpfreaks.com/topic/198289-help-with-results-in-multiple-columns/#findComment-1042987 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.