Page 1 of 1

Retriving and Display Data in groups

Posted: Thu Jul 12, 2007 7:27 am
by gtcol
Good day to all!
I have a query to retrieve bulk number of rows. I want to display them all in groups of 20 rows in a page. I did that in MySql using Limit by clause. I am currently workin with MSSql. Could anybody suggest how we can achieve that in MSSQL. I appreciate any suggestions or ideas on this. I am on PHP 5.2, MSSQL 2000.

Thanks,
gtcol

Posted: Thu Jul 12, 2007 7:31 am
by feyd
I believe MSSQL uses "TOP."

Posted: Thu Jul 12, 2007 12:28 pm
by gtcol
Thanks Feyd, I will check with TOP and let you know the output.

Regards,
gtcol

Retrieve and Display Data in groups

Posted: Wed Jul 18, 2007 12:05 pm
by gtcol
Hello Feyd & all,
I found a work around for grouping the rows and displaying in different pages. But i'm stuck in another issue here. It seems pretty tiny but I just can't track the bug here. What I am trying to do is jump to the next page where i am supposed to see records 11 to 20. But I can't just pass the query value. I have pasted the test script here which should pass the query value to itself when I click "Next" or "Prev" and display the same records. REGISTER_GLOBAL is turned off. Does it matter anyway, in this case? Please ignore the radio button thing here. Thanking for all your tips and tricks,
gtcol

Code: Select all

<?php
include("../includes/connect.php");

$sc=$_GET['s_butt'];
if(isset($sc)) $sc=1;
$Query=$_GET['cname'];
if($sc==1){
      if(!isset($Query)) $Query="";
      if($Query==""){
                    $Sql="SELECT Name FROM Customers";
      } else {
            $Sql="SELECT Name FROM Customers WHERE Name LIKE '%$Query%'";
      }
      $Sql=trim($Sql,"AND");
      $Sql_rows=mssql_query($Sql, $connection);
      $NumRows = mssql_num_rows($Sql_rows);
      $Pages=$NumRows/10;
      $Pages=ceil($Pages);
      echo "$NumRows recods, $Pages page/s found";
?>
<table border="0" width="100%" height="30" cellspacing="0" cellpadding="0">
                  <form method="GET" action="test_se.php?sc=<?php echo $sc;?>&Query=<?php echo $Query;?>">
                      	      <tr><td align="left"><a href="test_se.php?sc=1&Query=<?php echo $Query;?>">Prev</a></td>
              	                  <td align="left"><a href="test_se.php?sc=1&Query=<?php echo $Query;?>">Next</a></td></tr>
                              <tr><td class="gtBody" align="left" width="10%"></td><td class="gtBody" align="left" width="90%">Search for:</td></tr>
                        <tr><td class="gtBody" align="left" width="10%"></td><td class="gtBody" align="left" width="90%">Name:</td></tr>
                        <tr><td class="gtBody" align="left" width="10%"></td>
                        <td align="left" width="90%"><input type="textbox" name="cname" size="14" value="<?php echo $Query;?>"></td></tr>
                        <tr><td class="gtBody" align="left" width="10%"></td><td><input type="submit" value="Go" name="s_butt"></td</tr>
                     </form>
                    </table>
<?php
      //include("test_se.htm");
$x=0;
      While($Rows=mssql_fetch_array($Sql_rows)){
	$x=$x+1;
	$Con=$Rows[0];
        echo "<tr><td><input type=\"radio\" value=\"',$x,'\"> </td><td>",$x,"</td><td>",$Con,"</td></tr>";
	}
	//echo "</table>";
        } else {
          ?>
          <table border="0" width="100%" height="30" cellspacing="0" cellpadding="0">
                  <form method="GET" action="test_se.php?sc=<?php echo $sc;?>&Query=<?php echo $Query;?>">
                              <tr><td class="gtBody" align="left" width="10%"></td><td class="gtBody" align="left" width="90%">Search for:</td></tr>
                        <tr><td class="gtBody" align="left" width="10%"></td><td class="gtBody" align="left" width="90%">Name:</td></tr>
                        <tr><td class="gtBody" align="left" width="10%"></td>
                        <td align="left" width="90%"><input type="textbox" name="cname" size="14" value="<?php echo $Query;?>"></td></tr>
                        <tr><td class="gtBody" align="left" width="10%"></td><td><input type="submit" value="Go" name="s_butt"></td</tr>
                     </form>
                    </table>

<?php
}
?>