Re: Simple MySQL sample code runs out of memory

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Maybe this..
HTH,

<?php
...

$result = mysql_query( $qry, $db_conn ) or  die( mysql_error() . "\n" );

$num_rows = mysql_numrows($result);
if(!$result || ($num_rows <= 0)){
   echo "Error displaying info";
}
else if($num_rows > 0){
   for($i=0; $i<$num_rows; $i++){
      $c = mysql_result($result,$i,"contract");

      echo sprintf( "|%13d |%7d |\n", $c, $i );
   }
}

?>

Best,
Karl



On Oct 27, 2011, at 6:59 PM, php@xxxxxxxxxxxxx wrote:

<?php

require_once( '../include/mysql_funcs.php' );

$db_host = $test_db_host;
$db_user = $test_db_user;
$db_name = $test_db_name;
$db_pwd  = $test_db_pwd;

if (!($db_conn = mysql_connect( $db_host, $db_user, $db_pwd )))
       die( "Can't connect to MySQL server\n" );

if (!mysql_select_db( $db_name, $db_conn ))
       die( "Can't connect to database $db_name\n" );

$qry = "select * from test_table order by contract";

if ($result = mysql_query( $qry, $db_conn )) {

       $row = mysql_fetch_array( $result );
       while ($row) {
               $c = $row[ 'contract' ];
               $n = 0;
               while ($row && ($c == $row[ 'contract' ])) {
                       $n++;
                       $row = mysql_fetch_array( $result );
               }
               echo sprintf( "|%13d |%7d |\n", $c, $n );
       } // while

} else {

       die( mysql_error() . "\n" );

}

?>

Karl DeSaulniers
Design Drumm
http://designdrumm.com


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux