Jump to content

odbc_fetch_row Return to numaric value !


simzam

Recommended Posts

Hello !

mysql_fetch_row ()  return value

Returns an numerical array of strings that corresponds to the fetched row, or FALSE if there are no more rows.

http://php.net/manual/en/function.mysql-fetch-row.php

 

i wanted to convert odbc_fetch_row()  returns value to numerical value as it Returns

True or false only

http://www.php.net/manual/en/function.odbc-fetch-row.php

 

possible to do it ? any way i can return value to numerical array

as 

$numrec=odbc_fetch_row($qryresult);

should return to numerical array

 

::)

 

thanks

Link to comment
https://forums.phpfreaks.com/topic/222066-odbc_fetch_row-return-to-numaric-value/
Share on other sites

im trying to convert this code to use for ms access database as this code works with mysql but im trying to convert for ms access

 

source http://phpbuilder.com/columns/rod20001214.php3?page=3

<?php

function pagenav() {
    global $limit,$offset,$numpage,$where;
    if ($where) {
        $safewhere=urlencode($where);
    }
    echo "
    <TABLE CELLPADDING=0 BORDER=0 CELLSPACING=5 WIDTH=100>
    <TR>
        <TD ALIGN=RIGHT>";

        if ($offset>=$limit) {
            $newoff=$offset-$limit;
            
            echo "<A HREF=\"$PHP_SELF?offset=$newoff&where=$safewhere\">
                <-- PREV</A>
                </TD>";
        } else {
            echo "<-- PREV";
        }

        echo "<TD ALIGN=CENTER>   ";

        for ($i=1;$i<=$numpage;$i++) {
            if ((($i-1)*$limit)==$offset) {
                print "$i ";
            } else {
                $newoff=($i-1)*$limit;

                echo "<A HREF=\"$PHP_SELF?offset=$newoff&where=$safewhere\">
                    $i</A> ";
            }
        }
        echo "  </TD>
        <TD ALIGN=LEFT>";
        if ($offset!=$limit*($numpage-1)) {
            $newoff=$offset+$limit;
            echo "<A HREF=\"$PHP_SELF?offset=$newoff&where=$safewhere\">
                NEXT--></A>
                </TD>";
        }else{
            echo "NEXT--></TD>";
        }
        echo "</TR>
    </TABLE>";

} // END FUNCTION

// set this to the number of results you wish on each page
$limit=20;

// if no offset has been passed, offset should be 0
if (!$offset) $offset=0;

if (!$where) {
    if (empty($one) || empty($two)) {
        // some error handling as $one and/or
        //$two not passed to initial page
    }
    $where="$one|$two";
}

// NOTE: if a pipe (|) may be in the value
// of $one or $two, use a different delimiter
$data=explode('|',$where);
$query_where="where one='$data[0]' AND two='$data[1]'";

$result=mysql_query("select count(*) from tablename $query_where");

list($numrec)=mysql_fetch_row($result);

#calc num pages
$numpage=intval($numrec/$limit);

if ($numrec%$limit) {
    $numpage++; // add one page if remainder
}

$result=mysql_query ("select * from tablename $query_where limit $offset,$limit");

//<!-- HTML headers and other non-relevent stuff -->

if ($numpage>1) {
    pagenav();
    print "<P>";
}
//<!-- result display loop -->
if ($numpage>1) {
    pagenav();
    print "<P>";
}

?>

i manage to solve  ms access paging problem this code works like charm

but 1 problem for me in this code it shows all pages links like  <<Back 1 2 3 4 5 6 7 8 9 10 and go on Next>> how to set these link pages set to 10  pages and after clicking next button it shows 20 to 30  other wise every thing works gr8 for me

 

here is issue

for($i=1; $i<=$Num_Pages; $i++){
if($i != $Page)
{
	echo "[ <a href='$_SERVER[sCRIPT_NAME]?Page=$i'>$i</a> ]";
}

 

 

<html>
<head>
<title> </title>
</head>
<body>
<?
$objConnect = odbc_connect("mydatabase","","") or die("Error Connect to Database");
$strSQL = "SELECT * FROM mytable ORDER BY ID ASC";
$objExec = odbc_exec($objConnect, $strSQL) or die ("Error Execute [".$strSQL."]");
$Num_Rows = 0;
while(odbc_fetch_row($objExec))$Num_Rows++; // Count Record

$Per_Page = 20;   // Per Page

$Page = $_GET["Page"];
if(!$_GET["Page"])
{
$Page=1;
}

$Prev_Page = $Page-1;
$Next_Page = $Page+1;

$Page_Start = (($Per_Page*$Page)-$Per_Page)+1;

if($Num_Rows<=$Per_Page)
{
$Num_Pages =1;
}
else if(($Num_Rows % $Per_Page)==0)
{
$Num_Pages =($Num_Rows/$Per_Page) ;
}
else
{
$Num_Pages =($Num_Rows/$Per_Page)+1;
$Num_Pages = (int)$Num_Pages;
}
$Page_End = $Per_Page * $Page;
if($Page_End > $Num_Rows)
{
$Page_End = $Num_Rows;
}
?>
<table border="1">
  <tr>
    <th> <div align="center">ID </div></th>
    <th > <div align="center">title </div></th>

  </tr>
<?
for($i=$Page_Start;$i<=$Page_End;$i++)
{
$objResult = odbc_fetch_array($objExec,$i);
?>
  <tr>
    <td><div align="center"><?=$objResult["ID"];?></div></td>
    <td><?=$objResult["title"];?></td>

  </tr>
<?
}
?>
</table>

<br>
Total <?= $Num_Rows;?> Record : <?=$Num_Pages;?> Page :
<?
if($Prev_Page)
{
echo " <a href='$_SERVER[sCRIPT_NAME]?Page=$Prev_Page'><< Back</a> ";
}


for($i=1; $i<=$Num_Pages; $i++){
if($i != $Page)
{

	echo "[ <a href='$_SERVER[sCRIPT_NAME]?Page=$i'>$i</a> ]";
}
else
{
echo "<b> $i </b>";
}
}
if($Page!=$Num_Pages)
{
echo "<a href ='$_SERVER[sCRIPT_NAME]?Page=$Next_Page'> Next>></a> ";
}

odbc_close($objConnect);
?>
</body>
</html>

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.