Page 1 of 1

Help on displaying the result in table

Posted: Tue Apr 27, 2010 6:26 am
by aleaf88
Hello, i have a problem to display the result from database. Act i want to display the result like this:

As example i have 30 data...The data will be display in table. The other data will be displayed at the other page (next page)

| data01 | data02 | data03 | data04| data05|
| data06 | data07 | data08 | data09| data10|
| data11 | data12 | data13 | data14| data15|

Next | Last

*data display in table 5x3

I already write the code for this, but it still cant display what i want to.

Code: Select all

<?php require_once('Connections/books.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $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": :D 
      $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 = 10;
$pageNum_Recordset1 = 0;
if (isset($_GET['pageNum_Recordset1'])) {
  $pageNum_Recordset1 = $_GET['pageNum_Recordset1'];
}
$startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;

$var1_Recordset1 = "-1";
if (isset($_GET['txt_fullsearch'])) {
  $var1_Recordset1 = $_GET['txt_fullsearch'];
}
mysql_select_db($database_books, $books);
$query_Recordset1 = sprintf("SELECT genremain.genremain_type, genrespecific.GenreSpecific_Type, bookinfo.Book_ID, bookinfo.Title, bookinfo.Author, bookinfo.Publisher, bookinfo.Year_Publication, bookinfo.Series, bookinfo.ISBN, bookinfo.Image FROM bookinfo Inner Join genremain ON bookinfo.GenreMain = genremain.genremain_id Inner Join genrespecific ON bookinfo.GenreSpecific = genrespecific.GenreSpecific_ID WHERE genremain.genremain_type LIKE %s", GetSQLValueString("%" . $var1_Recordset1 . "%", "text"));
$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
$Recordset1 = mysql_query($query_limit_Recordset1, $books) 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);
?>
<!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><form action="" method="get">
  <p>
    <label>
      <input name="txt_fullsearch" type="text" id="txt_fullsearch" size="50" />
    </label>
    <label>
      <input type="submit" name="btn_search" id="btn_search" value="Submit" />
    </label>
  </p>
</form>
<p>Result	:</p>
<p>Displaying records from <?php echo ($startRow_Recordset1 + 1) ?> to <?php echo min($startRow_Recordset1 + $maxRows_Recordset1, $totalRows_Recordset1) ?> of <?php echo $totalRows_Recordset1 ?></p>
<table border="1" cellpadding="5" cellspacing="5">
<tr>
  <?php
  
  do { 
  
  $i = 0;
  if ($i < 5){
  
  echo '<td><img src="bookCover/'.$row_Recordset1['Image'].'.jpg" width=160 height=190></td>'; 
  
  
  }
  else{
  	echo "</tr><tr>";
	$i = 0;
	
  }
  
  $i++;
	
  }while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); 
  
  ?>

</table>
<p>&nbsp;
<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>
</p>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>

Re: Help on displaying the result in table

Posted: Tue Apr 27, 2010 9:40 pm
by yacahuma
i will suggest, start by just getting the data from the database, and forget about the pager. Then add the html table and then the pager