ajplan Posted September 2, 2008 Share Posted September 2, 2008 Hi All, First time posting and a newbie to PHP looking for a little help please. Ive had a little trawl through the forum for similar posts but have not come up with a solution as yet. I have produced a paging output query but would now like to display my results in a column view instead of a straight down row view. I know I need to play with the looping for the query but am having a tough time working it out. Any help would be much appreciated!! Code below.... <?php ini_set("display_errors","2"); ERROR_REPORTING(E_ALL); ?> <?php require_once('Connections/myConn.php'); // INCLUDE AS BELOW WITH U/P TAKEN OUT ?> <?php /* # FileName="Connection_php_mysql.htm" # Type="MYSQL" # HTTP="true" $hostname_myConn = "localhost"; $database_myConn = ""; $username_myConn = ""; $password_myConn = ""; $myConn = mysql_pconnect($hostname_myConn, $username_myConn, $password_myConn) or trigger_error(mysql_error(),E_USER_ERROR); */ ?> <?php /* if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } */ $currentPage = $_SERVER["PHP_SELF"]; $maxRows_Recordset1 = 4; $pageNum_Recordset1 = 0; if (isset($_GET['pageNum_Recordset1'])) { $pageNum_Recordset1 = $_GET['pageNum_Recordset1']; } $startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1; mysql_select_db($database_myConn, $myConn); $query_Recordset1 = "SELECT * FROM events"; $query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1); $Recordset1 = mysql_query($query_limit_Recordset1, $myConn) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); if (isset($_GET['totalRows_Recordset1'])) { $totalRows_Recordset1 = $_GET['totalRows_Recordset1']; } else { $all_Recordset1 = mysql_query($query_Recordset1); $totalRows_Recordset1 = mysql_num_rows($all_Recordset1); } $totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1; $queryString_Recordset1 = ""; if (!empty($_SERVER['QUERY_STRING'])) { $params = explode("&", $_SERVER['QUERY_STRING']); $newParams = array(); foreach ($params as $param) { if (stristr($param, "pageNum_Recordset1") == false && stristr($param, "totalRows_Recordset1") == false) { array_push($newParams, $param); } } if (count($newParams) != 0) { $queryString_Recordset1 = "&" . htmlentities(implode("&", $newParams)); } } $queryString_Recordset1 = sprintf("&totalRows_Recordset1=%d%s", $totalRows_Recordset1, $queryString_Recordset1); ini_set("display_errors","2"); ERROR_REPORTING(E_ALL); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <?php $result = mysql_query($query_Recordset1); //########################################################################## // START COLUMN OUTPUT ##################################################### //########################################################################## // HOW MANY COLUMNS ? $columns = 4; // NUMBER OF ROWS ? $num_rows = mysql_num_rows($result); // START LOOP for($i = 0; $i < $num_rows; $i++) { $row = mysql_fetch_array($result); if($i % $columns == 0) { // IF THERE IS NO REMAINDER START NEW ROW echo '<div style="width: 700px; padding-left: 50px; padding-bottom: 10px;">'; } // REPEAT CONTENT echo "#COLUMN# "; // $row_Recordset1['event_name'] . " # "; if(($i % $columns) == ($columns - 1) || ($i + 1) == $num_rows) { //IF THERE IS A REMAINDER OF 1 END ROW //OR IF THERE IS NOTHING LEFT, END THE ROW echo "</div>"; } // END START LOOP } //########################################################################## // END COLUMN OUTPUT ####################################################### //########################################################################## ?> <?php //########################################################################## // PAGE OUTPUT ####################################################### //########################################################################## ?> <table border="0"> <tr> <td><?php if ($pageNum_Recordset1 > 0) { // Show if not first page ?> <a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, 0, $queryString_Recordset1); ?>">First</a> <?php } // Show if not first page ?> </td> <td><?php if ($pageNum_Recordset1 > 0) { // Show if not first page ?> <a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, max(0, $pageNum_Recordset1 - 1), $queryString_Recordset1); ?>">Previous</a> <?php } // Show if not first page ?> </td> <td><?php if ($pageNum_Recordset1 < $totalPages_Recordset1) { // Show if not last page ?> <a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, min($totalPages_Recordset1, $pageNum_Recordset1 + 1), $queryString_Recordset1); ?>">Next</a> <?php } // Show if not last page ?> </td> <td><?php if ($pageNum_Recordset1 < $totalPages_Recordset1) { // Show if not last page ?> <a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, $totalPages_Recordset1, $queryString_Recordset1); ?>">Last</a> <?php } // Show if not last page ?> </td> </tr> </table> Records <?php echo ($startRow_Recordset1 + 1) ?> to <?php echo min($startRow_Recordset1 + $maxRows_Recordset1, $totalRows_Recordset1) ?> of <?php echo $totalRows_Recordset1 ?> </body> </html> [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/122384-php-column-output/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.