Jump to content

database paging


sniperscope

Recommended Posts

hi all  !

 

I have a serious problem which i can not solve by my self. My problem is, i want to display db records as

            

1st record 2nd record

3rd record4th record

 

And so far i can get only

 

1st Record

2nd Record

3rd Record

4th Record

 

I will be really appreciate if any one try to solve small(for you) but big(for me) problem.

Link to comment
https://forums.phpfreaks.com/topic/136808-database-paging/
Share on other sites

Here is a sample script. When you execute this script it makes

 

1st Record1st Record

1st Record1st Record

2nd Record2nd Record

2nd Record2nd Record

 

<?php
$host_name = "localhost";
$db = "my_db";
$u_name = "root";
$pass = "root_pass";
$is = mysql_pconnect($host_name, $u_name, $pass) or trigger_error(mysql_error(),E_USER_ERROR); 
?>
<?php
mysql_select_db($db, $is);
$query_Rs = "SELECT name, dimension FROM stone ORDER BY name DESC";
$Rset = mysql_query($query_Rs, $is) or die(mysql_error());
$row_Rs = mysql_fetch_assoc($Rset);
$totalRows = mysql_num_rows($Rset);
?>

<!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=shift_jis" />
<title>Untitled Document</title>
</head>

<body>
<?php do { ?>
  <table width="100%" border="1">
    <tr>
      <td><table width="100%" border="1">
        <tr>
          <td><?php echo $row_Rs['name']; ?></td>
          <td><?php echo $row_Rs['dimension']; ?></td>
        </tr>
      </table></td>
      <td><table width="100%" border="1">
        <tr>
          <td><?php echo $row_Rs['name']; ?></td>
          <td><?php echo $row_Rs['dimension']; ?></td>
        </tr>
      </table></td>
    </tr>
    <tr>
      <td><table width="100%" border="1">
        <tr>
          <td><?php echo $row_Rs['name']; ?></td>
          <td><?php echo $row_Rs['dimension']; ?></td>
        </tr>
      </table></td>
      <td><table width="100%" border="1">
        <tr>
          <td><?php echo $row_Rs['name']; ?></td>
          <td><?php echo $row_Rs['dimension']; ?></td>
        </tr>
      </table></td>
    </tr>
  </table>
  <?php } while ($row_Rs = mysql_fetch_assoc($Rset)); ?>
</body>
</html>
<?php
mysql_free_result($Rset);
?>

Link to comment
https://forums.phpfreaks.com/topic/136808-database-paging/#findComment-714499
Share on other sites

It is because you are outputting each db row in a different table row.

 

Any solution ?

 

I will really regard if you tell me the solution. Because my query return veeeeeeeeery long page. And i want to show 8 records in one page in one table and then paging like NEXT > NEXT....etc

Link to comment
https://forums.phpfreaks.com/topic/136808-database-paging/#findComment-714517
Share on other sites

Try this:

 

Not sure how it will work but try it out and then tell us what happened.

 

<?php
$host_name = "localhost";
$db = "my_db";
$u_name = "root";
$pass = "root_pass";
$is = mysql_pconnect($host_name, $u_name, $pass) or trigger_error(mysql_error(),E_USER_ERROR); 
?>
<?php
mysql_select_db($db, $is);
$query_Rs = "SELECT name, dimension FROM stone ORDER BY name DESC";
$Rset = mysql_query($query_Rs, $is) or die(mysql_error());
$row_Rs = mysql_fetch_assoc($Rset);
$totalRows = mysql_num_rows($Rset);
?>

<!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=shift_jis" />
<title>Untitled Document</title>
</head>

<body>
<div style="width:100%; clear:both; padding:5px;">
<?php do { ?>
  
         <div style="width:250px; margin:5px; border:1px #CCCCCC solid; padding:5px; float:left;">
          <?php echo $row_Rs['name']; ?><br />
          <?php echo $row_Rs['dimension']; ?>
          </div>
        


  <?php } while ($row_Rs = mysql_fetch_assoc($Rset)); ?>
  </div>
</body>
</html>
<?php
mysql_free_result($Rset);
?>

Link to comment
https://forums.phpfreaks.com/topic/136808-database-paging/#findComment-714524
Share on other sites

And how about if i want to put

 

<table width="200" border="1">
  <tr>
    <td>Product NAME goes here</td>
    <td rowspan="2">Product Dimension goes here</td>
  </tr>
  <tr>
    <td>Product Picture goes here</td>
  </tr>
</table>

Link to comment
https://forums.phpfreaks.com/topic/136808-database-paging/#findComment-714530
Share on other sites

Well, you were using tables, which I find particularly nasty. I used div tags and styled them with CSS to give them structure.

 

<div style="width:100%; clear:both; padding:5px;">

 

This is what I wrapped all the rows inside. It's pretty simple. It keeps the width at 100% and adds some padding to make it neater looking.

 

<div style="width:250px; margin:5px; border:1px #CCCCCC solid; padding:5px; float:left;">

 

Sets the width of each box at 250px, adds a margin to keep the boxes from rubbing up against each other, adds a little border to show you where one starts and another ends, adds some padding and makes each box float to the left. You should probably add a height onto it too, if you want it to look more structured.

 

Try

<div style="width:250px; margin:5px; border:1px #CCCCCC solid; padding:5px; float:left; height:250px;">

 

Mess around with the width and height of the div until you're happy.

Link to comment
https://forums.phpfreaks.com/topic/136808-database-paging/#findComment-714531
Share on other sites

For pictures try:

Not perfect, but it should work fine.

<?php
$host_name = "localhost";
$db = "my_db";
$u_name = "root";
$pass = "root_pass";
$is = mysql_pconnect($host_name, $u_name, $pass) or trigger_error(mysql_error(),E_USER_ERROR); 
?>
<?php
mysql_select_db($db, $is);
$query_Rs = "SELECT name, dimension FROM stone ORDER BY name DESC";
$Rset = mysql_query($query_Rs, $is) or die(mysql_error());
$row_Rs = mysql_fetch_assoc($Rset);
$totalRows = mysql_num_rows($Rset);
?>

<!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=shift_jis" />
<title>Untitled Document</title>
</head>

<body>
<div style="width:100%; clear:both; padding:5px;">
<?php do { ?>
  
         <div style="width:250px; margin:5px; border:1px #CCCCCC solid; padding:5px; float:left;">
          <?php echo $row_Rs['name']; ?><br />
          <?php echo $row_Rs['dimension']; ?><br /><br />
          <div align="center">
          Product Picture goes here.
          </div>
          </div>
        


  <?php } while ($row_Rs = mysql_fetch_assoc($Rset)); ?>
  </div>
</body>
</html>
<?php
mysql_free_result($Rset);
?>

Link to comment
https://forums.phpfreaks.com/topic/136808-database-paging/#findComment-714532
Share on other sites

Try

 

<?php
$host_name = "localhost";
$db = "my_db";
$u_name = "root";
$pass = "root_pass";
$is = mysql_pconnect($host_name, $u_name, $pass) or trigger_error(mysql_error(),E_USER_ERROR); 
?>
<?php
mysql_select_db($db, $is);
$query_Rs = "SELECT name, dimension FROM stone ORDER BY name DESC";
$Rset = mysql_query($query_Rs, $is) or die(mysql_error());
$row_Rs = mysql_fetch_assoc($Rset);
$totalRows = mysql_num_rows($Rset);
?>

<!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=shift_jis" />
<title>Untitled Document</title>
</head>

<body>
<div style="width:100%; padding:5px;">
<?php do { ?>
  
         <div style="width:250px; margin:5px; border:1px #CCCCCC solid; padding:5px; float:left; height:250px;">
          <?php echo $row_Rs['name']; ?><br />
          <?php echo $row_Rs['dimension']; ?><br /><br />
          Product Picture goes here.
          </div>
        


  <?php } while ($row_Rs = mysql_fetch_assoc($Rset)); ?>
  </div>
</body>
</html>
<?php
mysql_free_result($Rset);
?>

Link to comment
https://forums.phpfreaks.com/topic/136808-database-paging/#findComment-714537
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.