[PHP] setting the document root path in linux

2007-09-19 Thread tbt

Hi

I'm a newbie to php and I'm using 

require_once($_SERVER['DOCUMENT_ROOT']."/includes/class.announcement.php"); 

to import pages in php. This works fine on a windows environment. However
when I move this application to a linux environment the files dont get
imported properly. This is because in a windows environment 
$_SERVER['DOCUMENT_ROOT'] returns c:/xampp/htdocs etc.
but in a linux environment returns /home/servers etc.

How can this be rectified so that the path is properly picked up in a linux
environment
-- 
View this message in context: 
http://www.nabble.com/setting-the-document-root-path-in-linux-tf4479174.html#a12771923
Sent from the PHP - General mailing list archive at Nabble.com.

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



Re: [PHP] setting the document root path in linux

2007-09-19 Thread Chris

tbt wrote:

Hi

I'm a newbie to php and I'm using 


require_once($_SERVER['DOCUMENT_ROOT']."/includes/class.announcement.php");   

to import pages in php. This works fine on a windows environment. However
when I move this application to a linux environment the files dont get
imported properly. This is because in a windows environment 
$_SERVER['DOCUMENT_ROOT'] returns c:/xampp/htdocs etc.

but in a linux environment returns /home/servers etc.

How can this be rectified so that the path is properly picked up in a linux
environment


Don't rely on document root.

I'm surprised it worked on windows, you were lucky - 90% of the time 
it's not there or not correct anyway.


If it's in the same directory as the current file, do:

require(dirname(__FILE__) . '/includes/class.announcement.php');

__FILE__ is a built in constant that tells you the full path to the 
current file.


dirname() takes the filename out of that and gives you just the current 
directory (see http://www.php.net/dirname ).


Then add the rest of the on the end.

--
Postgresql & php tutorials
http://www.designmagick.com/

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



[PHP] back on bug 42065 , strange behavior with ArrayObject

2007-09-19 Thread Julien Pauli
Hi, at first, read that bug report : http://bugs.php.net/bug.php?id=42065

I would like to say that it doesn't seem to be fixed as it's said.
When I execute the bug 42065 test case, it still fails.

In reality, another code brought me to that bug, please consider this :

'2');

public function getArray()
{
return $this->array;
}

}
$a = new a;
$tab = $a->getArray();
$tab['key'] = 5;
print_r($a);
print_r($tab);

Outputs :
a Object
(
[array] => Array
(
[key] => 2
)

)
Array
(
[key] => 5
)


No problem, that's expected.

Now consider that :

$a = new a;
$tab = new ArrayObject($a->getArray());
$tab['key'] = 5;
print_r($a);
print_r($tab);

Outputs :
a Object
(
[array] => Array
(
[key] => 5
)

)
ArrayObject Object
(
[key] => 5
)


So, the original array, inside the 'a' object has been modified, but it
souldn't have.
This behavior is like the one described in bug 42065
Plateform : Windows
PHP : latest 5.2 snapshot - Apache SAPI.

If you really want the original array not to be modified, you should act
like this :
$tab = new ArrayObject((array)$a->getArray());

Strange isn't it ?


Re: [PHP] back on bug 42065 , strange behavior with ArrayObject

2007-09-19 Thread Chris

Julien Pauli wrote:

Hi, at first, read that bug report : http://bugs.php.net/bug.php?id=42065

I would like to say that it doesn't seem to be fixed as it's said.
When I execute the bug 42065 test case, it still fails.

In reality, another code brought me to that bug, please consider this :


http://www.php.net/manual/en/function.ArrayObject-construct.php#77235

Says it all :)

--
Postgresql & php tutorials
http://www.designmagick.com/

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



Re: [PHP] back on bug 42065 , strange behavior with ArrayObject

2007-09-19 Thread Julien Pauli
Wow, all right ; that's why casting to (array) before passing the variable ,
thus making a copy of it, works.
Thanks for that short but effective answer ;-)

However, except in the comments, this is not said in the original doc.
It should be written
ArrayObject ArrayObject::__construct ( mixed &$input )
shouldn't it ?

2007/9/19, Chris <[EMAIL PROTECTED]>:
>
> Julien Pauli wrote:
> > Hi, at first, read that bug report :
> http://bugs.php.net/bug.php?id=42065
> >
> > I would like to say that it doesn't seem to be fixed as it's said.
> > When I execute the bug 42065 test case, it still fails.
> >
> > In reality, another code brought me to that bug, please consider this :
>
> http://www.php.net/manual/en/function.ArrayObject-construct.php#77235
>
> Says it all :)
>
> --
> Postgresql & php tutorials
> http://www.designmagick.com/
>


Re: [PHP] Try to find a solution, when restart Apache with PHP Script

2007-09-19 Thread Rodolfo De Nadai

Hello James,
in future we will implement the script with cron, i've already talk to 
the support server guys... and i think this would be the best pratice...
But for now i was wondering if there's a workaround... because in the 
moment my boss tell me to not change anything that could delay the 
software more than 1 or 2 days...


So i'm looking for a dirty solution for now...

thanks

James Ausmus escreveu:

On 9/17/07, Rodolfo De Nadai <[EMAIL PROTECTED]> wrote:
  

Hi all...

I'm facing a serious problem with my application. I have a script write
in PHP that starts in Internet Explorer, this script keep on running
until a varible value change on my MySQL database.
The problem is that when i restart Apache, the process child initalized
isn't kill... then the apache can't be start because the script is use
the port 80.



Hi Rodolfo-

I think you are going about this the wrong way. You shoud not have the
PHP script itself execute the forever running task, it should just
trigger the separate starting/stopping of the task. There are several
ways to do this, the first two that spring to mind are:

1. Create a custom init-script in /etc/init.d (or wherever your
distribution has init scripts) that the PHP process triggers with a
start command (/etc/init.d/myprog start). This will require root
privileges for the PHP process (or no-password sudo privileges for
that command).

--or--

2. Have a cron job running as a user that has appropriate permissions.
This cron job should look for the presence of specific files - if it
sees them, it takes the appropriate action, and then deletes the
trigger file. For example, have the cron job watch for the presence of
/tmp/startMyProg.marker - when it sees it, it starts the program and
deletes /tmp/startMyProg.marker. Also have it watch for the presence
of /tmp/stopMyProg.marker, when it sees that, it would stop the
running program, and delete the marker file. At this point, all your
PHP script has to do is create the appropriate file in /tmp (could be
as simple as a exec("touch /tmp/startMyProg.marker") call).

Hope that sends you a workable direction-

James


  


--
* Rodolfo De Nadai *
* Analista de Sistema Jr. - Desenvolvimento *




*Informática de Municípios Associados S.A.*
Seu governo mais inteligente
[EMAIL PROTECTED]   - 
www.ima.sp.gov.br 
Fone: (19) 3739-6000 / Ramal: 1307 


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



[PHP] Undefined class constant

2007-09-19 Thread Puiu Hrenciuc

Hi everyone,

I'm having a hard time dealing with an error that appeared overnight
in one of my PHP script:

Fatal error: Undefined class constant 'self::TYPE_HIDDEN' in 
/#/classes/framework/HTML/HTMLForm.php on line 120


HTMLForm.php snippet:

.
// Creates the HTMLFormFields
foreach ($this->Record->Columns as $_column)
{
// Add only visible columns
if ($_column->IsVisible)
{
// Default field type
$_type=HTMLFormField::ELEMENT_TYPE_TEXT ;

// Adjust default type based on Column type
switch ($_column->Type)
{
	case Column::TYPE_AUTONUMBER: 
   			  $_type=HTMLFormField::ELEMENT_TYPE_HIDDEN ;

  break;

case Column::TYPE_BOOLEAN :
  $_type=HTMLFormField::ELEMENT_TYPE_CHECKBOX ;
  break;
default:
  break;
117:   }
118:
119:// Add the column to the list of fields
120:$this->Fields[$_column->Name]=new 
121:HTMLFormField($this->Name,$_column,$_type);
122:
123:}

}

As you can see there is no refference to any TYPE_HIDDEN constant
at line 120, nor in the HTMLFormField's constructor.

I searched the net, but I just can't find the reason of this.
Can someone please help me ?

Thanks,
Puiu

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



Re: [PHP] Undefined class constant

2007-09-19 Thread T . Lensselink
On Wed, 19 Sep 2007 15:56:22 +0300, Puiu Hrenciuc <[EMAIL PROTECTED]> wrote:
> Hi everyone,
> 
> I'm having a hard time dealing with an error that appeared overnight
> in one of my PHP script:
> 
> Fatal error: Undefined class constant 'self::TYPE_HIDDEN' in
> /#/classes/framework/HTML/HTMLForm.php on line 120
> 
> HTMLForm.php snippet:
> 
> .
> // Creates the HTMLFormFields
> foreach ($this->Record->Columns as $_column)
> {
>   // Add only visible columns
>   if ($_column->IsVisible)
>   {
>   // Default field type
>   $_type=HTMLFormField::ELEMENT_TYPE_TEXT ;
> 
>  // Adjust default type based on Column type
>  switch ($_column->Type)
>  {
>   case Column::TYPE_AUTONUMBER:
> 
> $_type=HTMLFormField::ELEMENT_TYPE_HIDDEN ;
>break;
> 
>   case Column::TYPE_BOOLEAN :
>$_type=HTMLFormField::ELEMENT_TYPE_CHECKBOX ;
>break;
>  default:
>break;
> 117:   }
> 118:
> 119:  // Add the column to the list of fields
> 120:  $this->Fields[$_column->Name]=new
> 121:  HTMLFormField($this->Name,$_column,$_type);
> 122:
> 123:  }
> 
> }
> 
> As you can see there is no refference to any TYPE_HIDDEN constant
> at line 120, nor in the HTMLFormField's constructor.
> 
> I searched the net, but I just can't find the reason of this.
> Can someone please help me ?
> 
> Thanks,
> Puiu

When the error happens. What are the contents of 120: $_column->Name ?

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



[PHP] Page Numbering

2007-09-19 Thread Dan Shirah
Hello all,

I am having a problem with trying to display a set amount of records from my
result.
I have verified that the correct values for my variables are being passed to
the query.
The calculation for the records that should be displayed per page is
correct.
The total number of records returned from my query is correct.
And the calculated number of total pages to be displayed is correct.

So, initially it displays the first 10 results as it should, and has the
pages numbers at the bottom.  The problem is, when I click on a different
page number the same 10 results are ALWAYS displayed.  Even though my $page
variable IS being updated.

Any ideas why my results are not reflecting the page I select?






$id"
?>








Results: 


Select a Page";
// Build Previous Link
if($page > 1){
$prev = ($page - 1);
echo "< ";
}

for($i = 1; $i <= $total_pages; $i++){
if(($page) == $i){
echo "$i ";
} else {
echo "$i ";
}
}
// Build Next Link
if($page < $total_pages){
$next = ($page + 1);
echo "Next>>";
}
echo "";
?>


Re: [PHP] Undefined class constant

2007-09-19 Thread Puiu Hrenciuc

Here are the content for all used variables:

$_this->Name: (string) "FilterForm"
$_column:
StringColumn Object
(
[Table] => Roles
[Name] => RoleName
[Function] => like
[Type] => 4
[Min] =>
[Max] =>
[RegEx] =>
[AllowedValues] => Array
(
)

[IsValid] =>
[IsVisible] => 1
[Sorted] => 0
[Primary] =>
[Foreign] =>
[Negated] =>
[GroupBy] =>
[Aggregate] =>
[_value:protected] =>
)

$_type: (int) 1

T . Lensselink wrote:

On Wed, 19 Sep 2007 15:56:22 +0300, Puiu Hrenciuc <[EMAIL PROTECTED]> wrote:

Hi everyone,

I'm having a hard time dealing with an error that appeared overnight
in one of my PHP script:

Fatal error: Undefined class constant 'self::TYPE_HIDDEN' in
/#/classes/framework/HTML/HTMLForm.php on line 120

HTMLForm.php snippet:

.
// Creates the HTMLFormFields
foreach ($this->Record->Columns as $_column)
{
// Add only visible columns
if ($_column->IsVisible)
{
// Default field type
$_type=HTMLFormField::ELEMENT_TYPE_TEXT ;

 // Adjust default type based on Column type
 switch ($_column->Type)
 {
case Column::TYPE_AUTONUMBER:
  
$_type=HTMLFormField::ELEMENT_TYPE_HIDDEN ;
   break;

case Column::TYPE_BOOLEAN :
   $_type=HTMLFormField::ELEMENT_TYPE_CHECKBOX ;
   break;
 default:
   break;
117:   }
118:
119:// Add the column to the list of fields
120:$this->Fields[$_column->Name]=new
121:HTMLFormField($this->Name,$_column,$_type);
122:
123:}

}

As you can see there is no refference to any TYPE_HIDDEN constant
at line 120, nor in the HTMLFormField's constructor.

I searched the net, but I just can't find the reason of this.
Can someone please help me ?

Thanks,
Puiu


When the error happens. What are the contents of 120: $_column->Name ?


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



Re: [PHP] Page Numbering

2007-09-19 Thread T . Lensselink
On Wed, 19 Sep 2007 10:05:40 -0400, "Dan Shirah" <[EMAIL PROTECTED]>
wrote:
> Hello all,
> 
> I am having a problem with trying to display a set amount of records from
> my
> result.
> I have verified that the correct values for my variables are being passed
> to
> the query.
> The calculation for the records that should be displayed per page is
> correct.
> The total number of records returned from my query is correct.
> And the calculated number of total pages to be displayed is correct.
> 
> So, initially it displays the first 10 results as it should, and has the
> pages numbers at the bottom.  The problem is, when I click on a different
> page number the same 10 results are ALWAYS displayed.  Even though my
> $page
> variable IS being updated.
> 
> Any ideas why my results are not reflecting the page I select?
> 
> 
>  if(!isset($_GET['page'])){
> $page = 1;
>  } else {
> $page = $_GET['page'];
>  }
>  // Define the number of results per page
>  $max_results = 10;
>  // Figure out the limit for the query based
>  // on the current page number.
>  $from = (($page * $max_results) - $max_results);
>  echo $from."FROM";
>  $page_results = $max_results + $from;
>  echo $page_results."PAGE RESULTS";
>   // Query the table and load all of the records into an array.
>$sql = "SELECT DISTINCT * FROM (
> SELECT TOP $max_results Value1, Value2 FROM (
>  SELECT TOP $page_results Value1,
>  FROM my_table
>  WHERE my_table.column = 'P'
> ) as newtbl order by credit_card_id desc
>) as newtbl2 order by credit_card_id asc";
> 
> print_r ($sql);
>   $result = mssql_query($sql) or die(mssql_error());
>  //print_r ($result);
>   $number_rows = mssql_num_rows($result);
> ?>
>  cellspacing='2'
> bordercolor='#00'>
>  if(!empty($result)) {
>  while ($row = mssql_fetch_array($result)) {
>   $id = $row['credit_card_id'];
>   $dateTime = $row['date_request_received'];
>   //print_r ($id_child);
> ?>
> 
>  align='center'>$id"
> ?>
>  align='center'>
>  align='center'>
>  align='center'>
> 
>   }
> }
> ?>
> 
>  border="0">
> 
>  align='center'>Results:  ?>
> 
> 
>  // Figure out the total number of results in DB:
> $sql_total= "SELECT * FROM my_table WHERE my_table.column = 'P'";
> $tot_result = mssql_query($sql_total) or die(mssql_error());
> $total_results = mssql_num_rows($tot_result) or die(mssql_error());
> // Figure out the total number of pages. Always round up using ceil()
> $total_pages = ceil($total_results / $max_results);
> echo $max_results."Results";
> echo $total_results."Total";
> echo $total_pages."pages";
> // Build Page Number Hyperlinks
> echo "Select a Page";
> // Build Previous Link
> if($page > 1){
> $prev = ($page - 1);
> echo "<
> ";
> }
> 
> for($i = 1; $i <= $total_pages; $i++){
> if(($page) == $i){
> echo "$i ";
> } else {
> echo "$i ";
> }
> }
> // Build Next Link
> if($page < $total_pages){
> $next = ($page + 1);
> echo "Next>>";
> }
> echo "";
> ?>

I think it returns the same 10 records because of TOP $max_results. 
This will always get the first 10 records. Probably better to use LIMIT.

Why are there so much subqueries needed to get the result set?
Why not something like this:

SELECT DISTINCT * FROM my_table WHERE my_table.column = 'p' ORDER BY
credit_card_id DESC LIMIT $page_results, $max_results

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



Re: [PHP] Page Numbering

2007-09-19 Thread Dan Shirah
Becase I am using MSSQL not MYSQL.  MSSQL does not have anything easy to use
like LIMIT in MYSQL. So, to achieve the same functionality you have to use
the subqueries.

Having the largest number as the inner most subquery value tells the query
to retrieve the records that are equal to that number minus 10(my results
per page)

So, if the inner most query has has a value of 30, the outer query will
select records 21-30.

And, it does this just fine because if I echo out my variables I see the
numbers changing. But for whatever reason, the data being displayed is not
changing.


On 9/19/07, T. Lensselink <[EMAIL PROTECTED]> wrote:
>
> On Wed, 19 Sep 2007 10:05:40 -0400, "Dan Shirah" <[EMAIL PROTECTED]>
> wrote:
> > Hello all,
> >
> > I am having a problem with trying to display a set amount of records
> from
> > my
> > result.
> > I have verified that the correct values for my variables are being
> passed
> > to
> > the query.
> > The calculation for the records that should be displayed per page is
> > correct.
> > The total number of records returned from my query is correct.
> > And the calculated number of total pages to be displayed is correct.
> >
> > So, initially it displays the first 10 results as it should, and has the
> > pages numbers at the bottom.  The problem is, when I click on a
> different
> > page number the same 10 results are ALWAYS displayed.  Even though my
> > $page
> > variable IS being updated.
> >
> > Any ideas why my results are not reflecting the page I select?
> >
> >
> >  > if(!isset($_GET['page'])){
> > $page = 1;
> >  } else {
> > $page = $_GET['page'];
> >  }
> >  // Define the number of results per page
> >  $max_results = 10;
> >  // Figure out the limit for the query based
> >  // on the current page number.
> >  $from = (($page * $max_results) - $max_results);
> >  echo $from."FROM";
> >  $page_results = $max_results + $from;
> >  echo $page_results."PAGE RESULTS";
> >   // Query the table and load all of the records into an array.
> >$sql = "SELECT DISTINCT * FROM (
> > SELECT TOP $max_results Value1, Value2 FROM (
> >  SELECT TOP $page_results Value1,
> >  FROM my_table
> >  WHERE my_table.column = 'P'
> > ) as newtbl order by credit_card_id desc
> >) as newtbl2 order by credit_card_id asc";
> >
> > print_r ($sql);
> >   $result = mssql_query($sql) or die(mssql_error());
> >  //print_r ($result);
> >   $number_rows = mssql_num_rows($result);
> > ?>
> >  > cellspacing='2'
> > bordercolor='#00'>
> >  > if(!empty($result)) {
> >  while ($row = mssql_fetch_array($result)) {
> >   $id = $row['credit_card_id'];
> >   $dateTime = $row['date_request_received'];
> >   //print_r ($id_child);
> > ?>
> > 
> >  > align='center'>$id"
> > ?>
> >  > align='center'>
> >  > align='center'>
> >  > align='center'>
> > 
> >  >  }
> > }
> > ?>
> > 
> >  > border="0">
> > 
> >  > align='center'>Results:  > ?>
> > 
> > 
> >  > // Figure out the total number of results in DB:
> > $sql_total= "SELECT * FROM my_table WHERE my_table.column = 'P'";
> > $tot_result = mssql_query($sql_total) or die(mssql_error());
> > $total_results = mssql_num_rows($tot_result) or die(mssql_error());
> > // Figure out the total number of pages. Always round up using ceil()
> > $total_pages = ceil($total_results / $max_results);
> > echo $max_results."Results";
> > echo $total_results."Total";
> > echo $total_pages."pages";
> > // Build Page Number Hyperlinks
> > echo "Select a Page";
> > // Build Previous Link
> > if($page > 1){
> > $prev = ($page - 1);
> > echo "<
> > ";
> > }
> >
> > for($i = 1; $i <= $total_pages; $i++){
> > if(($page) == $i){
> > echo "$i ";
> > } else {
> > echo "$i ";
> > }
> > }
> > // Build Next Link
> > if($page < $total_pages){
> > $next = ($page + 1);
> > echo "Next>>";
> > }
> > echo "";
> > ?>
>
> I think it returns the same 10 records because of TOP $max_results.
> This will always get the first 10 records. Probably better to use LIMIT.
>
> Why are there so much subqueries needed to get the result set?
> Why not something like this:
>
> SELECT DISTINCT * FROM my_table WHERE my_table.column = 'p' ORDER BY
> credit_card_id DESC LIMIT $page_results, $max_results
>
>
>


Re: [PHP] Page Numbering

2007-09-19 Thread T . Lensselink
On Wed, 19 Sep 2007 10:23:58 -0400, "Dan Shirah" <[EMAIL PROTECTED]>
wrote:
> Becase I am using MSSQL not MYSQL.  MSSQL does not have anything easy to
> use
> like LIMIT in MYSQL. So, to achieve the same functionality you have to
use
> the subqueries.
> 
> Having the largest number as the inner most subquery value tells the
query
> to retrieve the records that are equal to that number minus 10(my results
> per page)
> 
> So, if the inner most query has has a value of 30, the outer query will
> select records 21-30.
> 
> And, it does this just fine because if I echo out my variables I see the
> numbers changing. But for whatever reason, the data being displayed is
not
> changing.
> 
> 
> On 9/19/07, T. Lensselink <[EMAIL PROTECTED]> wrote:
>>
>> On Wed, 19 Sep 2007 10:05:40 -0400, "Dan Shirah" <[EMAIL PROTECTED]>
>> wrote:
>> > Hello all,
>> >
>> > I am having a problem with trying to display a set amount of records
>> from
>> > my
>> > result.
>> > I have verified that the correct values for my variables are being
>> passed
>> > to
>> > the query.
>> > The calculation for the records that should be displayed per page is
>> > correct.
>> > The total number of records returned from my query is correct.
>> > And the calculated number of total pages to be displayed is correct.
>> >
>> > So, initially it displays the first 10 results as it should, and has
> the
>> > pages numbers at the bottom.  The problem is, when I click on a
>> different
>> > page number the same 10 results are ALWAYS displayed.  Even though my
>> > $page
>> > variable IS being updated.
>> >
>> > Any ideas why my results are not reflecting the page I select?
>> >
>> >
>> > > > if(!isset($_GET['page'])){
>> > $page = 1;
>> >  } else {
>> > $page = $_GET['page'];
>> >  }
>> >  // Define the number of results per page
>> >  $max_results = 10;
>> >  // Figure out the limit for the query based
>> >  // on the current page number.
>> >  $from = (($page * $max_results) - $max_results);
>> >  echo $from."FROM";
>> >  $page_results = $max_results + $from;
>> >  echo $page_results."PAGE RESULTS";
>> >   // Query the table and load all of the records into an array.
>> >$sql = "SELECT DISTINCT * FROM (
>> > SELECT TOP $max_results Value1, Value2 FROM (
>> >  SELECT TOP $page_results Value1,
>> >  FROM my_table
>> >  WHERE my_table.column = 'P'
>> > ) as newtbl order by credit_card_id desc
>> >) as newtbl2 order by credit_card_id asc";
>> >
>> > print_r ($sql);
>> >   $result = mssql_query($sql) or die(mssql_error());
>> >  //print_r ($result);
>> >   $number_rows = mssql_num_rows($result);
>> > ?>
>> > > > cellspacing='2'
>> > bordercolor='#00'>
>> > > > if(!empty($result)) {
>> >  while ($row = mssql_fetch_array($result)) {
>> >   $id = $row['credit_card_id'];
>> >   $dateTime = $row['date_request_received'];
>> >   //print_r ($id_child);
>> > ?>
>> > 
>> > > > align='center'> href='javascript:editRecord($id)'>$id"
>> > ?>
>> > > > align='center'>
>> > > > align='center'>
>> > > > align='center'>
>> > 
>> > > >  }
>> > }
>> > ?>
>> > 
>> > > > border="0">
>> > 
>> > > > align='center'>Results: > > ?>
>> > 
>> > 
>> > > > // Figure out the total number of results in DB:
>> > $sql_total= "SELECT * FROM my_table WHERE my_table.column = 'P'";
>> > $tot_result = mssql_query($sql_total) or die(mssql_error());
>> > $total_results = mssql_num_rows($tot_result) or die(mssql_error());
>> > // Figure out the total number of pages. Always round up using ceil()
>> > $total_pages = ceil($total_results / $max_results);
>> > echo $max_results."Results";
>> > echo $total_results."Total";
>> > echo $total_pages."pages";
>> > // Build Page Number Hyperlinks
>> > echo "Select a Page";
>> > // Build Previous Link
>> > if($page > 1){
>> > $prev = ($page - 1);
>> > echo " href=\"".$_SERVER['PHP_SELF']."?page=$prev\"><
>> > ";
>> > }
>> >
>> > for($i = 1; $i <= $total_pages; $i++){
>> > if(($page) == $i){
>> > echo "$i ";
>> > } else {
>> > echo "$i
> ";
>> > }
>> > }
>> > // Build Next Link
>> > if($page < $total_pages){
>> > $next = ($page + 1);
>> > echo "Next>>";
>> > }
>> > echo "";
>> > ?>
>>
>> I think it returns the same 10 records because of TOP $max_results.
>> This will always get the first 10 records. Probably better to use LIMIT.
>>
>> Why are there so much subqueries needed to get the result set?
>> Why not something like this:
>>
>> SELECT DISTINCT * FROM my_table WHERE my_table.column = 'p' ORDER BY
>> credit_card_id DESC LIMIT $page_results, $max_results
>>

Dan,

Thanx for the explenation. I should have asked what DB you are using.

So if you wanna select rows from 10 to 20 with a limit of 10 the query will
be
something like this? 

SELECT DISTINCT * FROM (
 SELECT TOP 10 Value1, Value2 FROM (
  SELECT TOP 20 Value1,
 FROM my_table
 WHERE my_table.column = 'P'
 ) as newtbl order by credit_card_id desc
) as newtbl2 order by credit_c

Re: [PHP] Undefined class constant

2007-09-19 Thread T . Lensselink
On Wed, 19 Sep 2007 17:13:02 +0300, Puiu Hrenciuc <[EMAIL PROTECTED]> wrote:
> Here are the content for all used variables:
> 
> $_this->Name: (string) "FilterForm"
> $_column:
> StringColumn Object
> (
>  [Table] => Roles
>  [Name] => RoleName
>  [Function] => like
>  [Type] => 4
>  [Min] =>
>  [Max] =>
>  [RegEx] =>
>  [AllowedValues] => Array
>  (
>  )
> 
>  [IsValid] =>
>  [IsVisible] => 1
>  [Sorted] => 0
>  [Primary] =>
>  [Foreign] =>
>  [Negated] =>
>  [GroupBy] =>
>  [Aggregate] =>
>  [_value:protected] =>
> )
> 
> $_type: (int) 1
> 
> T . Lensselink wrote:
>> On Wed, 19 Sep 2007 15:56:22 +0300, Puiu Hrenciuc <[EMAIL PROTECTED]>
> wrote:
>>> Hi everyone,
>>>
>>> I'm having a hard time dealing with an error that appeared overnight
>>> in one of my PHP script:
>>>
>>> Fatal error: Undefined class constant 'self::TYPE_HIDDEN' in
>>> /#/classes/framework/HTML/HTMLForm.php on line 120
>>>
>>> HTMLForm.php snippet:
>>>
>>> .
>>> // Creates the HTMLFormFields
>>> foreach ($this->Record->Columns as $_column)
>>> {
>>> // Add only visible columns
>>> if ($_column->IsVisible)
>>> {
>>> // Default field type
>>> $_type=HTMLFormField::ELEMENT_TYPE_TEXT ;
>>>
>>>  // Adjust default type based on Column type
>>>  switch ($_column->Type)
>>>  {
>>> case Column::TYPE_AUTONUMBER:
>>>   
>>> $_type=HTMLFormField::ELEMENT_TYPE_HIDDEN ;
>>>break;
>>>
>>> case Column::TYPE_BOOLEAN :
>>>$_type=HTMLFormField::ELEMENT_TYPE_CHECKBOX
> ;
>>>break;
>>>  default:
>>>break;
>>> 117:   }
>>> 118:
>>> 119:// Add the column to the list of fields
>>> 120:$this->Fields[$_column->Name]=new
>>> 121:HTMLFormField($this->Name,$_column,$_type);
>>> 122:
>>> 123:}
>>>
>>> }
>>>
>>> As you can see there is no refference to any TYPE_HIDDEN constant
>>> at line 120, nor in the HTMLFormField's constructor.
>>>
>>> I searched the net, but I just can't find the reason of this.
>>> Can someone please help me ?
>>>
>>> Thanks,
>>> Puiu
>>
>> When the error happens. What are the contents of 120: $_column->Name ?

What happens inside the constructor when you create a new instance of
HTMLFormField?
Maybe the $_type is validated there. Or i'm missing something in this
snippet.

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



Re: [PHP] setting the document root path in linux

2007-09-19 Thread Jim Lucas

tbt wrote:

Hi

I'm a newbie to php and I'm using 


require_once($_SERVER['DOCUMENT_ROOT']."/includes/class.announcement.php");   

to import pages in php. This works fine on a windows environment. However
when I move this application to a linux environment the files dont get
imported properly. This is because in a windows environment 
$_SERVER['DOCUMENT_ROOT'] returns c:/xampp/htdocs etc.

but in a linux environment returns /home/servers etc.

How can this be rectified so that the path is properly picked up in a linux
environment

are you running apache on windows and linux?

if so, setup a .htaccess file that has a line in it that modifies the php 
include path

place that .htaccess at your web root and you won't have to play with paths, 
you would call
require_once 'includes/class.announcement.php';   instead

Fix your include paths and you wont have to worry if the system will have what it should in the 
$_SERVER['DOCUMENT_ROOT'].


--
Jim Lucas

   "Some men are born to greatness, some achieve greatness,
   and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
by William Shakespeare

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



Re: [PHP] Undefined class constant

2007-09-19 Thread Puiu Hrenciuc

Here is the HTMLFormField constructor, it is pretty simple :

   /**
* Creates a new HTMLFormField object
*
* @param string $_formName Name of the form this field belongs to
* @param Column $_column Record object this column derives from
* @param int $_type Type of field, this determines the type of 
HTML element that will be rendered

* @param string $_class Class name for the HTML element
* @param array $_values Array of display values for combos, 
lists, radios
* @param string $_label Label to be displayed next to a radio, 
check box
* @param string $_nullMessage Message that will be displayed 
when a required field was not filled
* @param string $_invalidMessage Message that will be displayed 
when the data entered is invalid
* @param string $_tooShortMessage Message displayed when the 
field value is bellow minimum value or length
* @param string $_tooLongMessage Message displayed when the 
field value is above maximum value or length

*/
   public function 
__construct($_formName,$_column=null,$_type=0,$_class='' 
,$_fieldValues=null,$_label="",$_nullMessage='',$_invalidMessage='',$_tooShortMessage='',$_tooLongMessage='')

   {
   // Copy column's properties and save passed parameters 
into local properties

   if ($_column instanceof Column )
   {
   $this->Name=$_column->Name;
   $this->RegEx=$_column->RegEx;
   $this->Min=$_column->Min;
   $this->Max=$_column->Max;
   $this->Type=$_column->Type;
   $this->Value=$_column->Value;
   }

   $this->FormName=$_formName;
   $this->NullMessage=$_nullMessage;
   $this->InvalidDataMessage=$_invalidMessage;
   $this->TooLongMessage=$_tooShortMessage;
   $this->TooLongMessage=$_tooLongMessage;
   $this->Class=$_class;
   $this->FieldValues=$_fieldValues;
   $this->FieldType=$_type;

   }

Trust me, it doesn't have any logical explanation :)

Puiu

T.Lensselink wrote:

On Wed, 19 Sep 2007 17:13:02 +0300, Puiu Hrenciuc <[EMAIL PROTECTED]> wrote:
  

Here are the content for all used variables:

$_this->Name: (string) "FilterForm"
$_column:
StringColumn Object
(
 [Table] => Roles
 [Name] => RoleName
 [Function] => like
 [Type] => 4
 [Min] =>
 [Max] =>
 [RegEx] =>
 [AllowedValues] => Array
 (
 )

 [IsValid] =>
 [IsVisible] => 1
 [Sorted] => 0
 [Primary] =>
 [Foreign] =>
 [Negated] =>
 [GroupBy] =>
 [Aggregate] =>
 [_value:protected] =>
)

$_type: (int) 1

T . Lensselink wrote:


On Wed, 19 Sep 2007 15:56:22 +0300, Puiu Hrenciuc <[EMAIL PROTECTED]>
  

wrote:


Hi everyone,

I'm having a hard time dealing with an error that appeared overnight
in one of my PHP script:

Fatal error: Undefined class constant 'self::TYPE_HIDDEN' in
/#/classes/framework/HTML/HTMLForm.php on line 120

HTMLForm.php snippet:

.
// Creates the HTMLFormFields
foreach ($this->Record->Columns as $_column)
{
// Add only visible columns
if ($_column->IsVisible)
{
// Default field type
$_type=HTMLFormField::ELEMENT_TYPE_TEXT ;

 // Adjust default type based on Column type
 switch ($_column->Type)
 {
case Column::TYPE_AUTONUMBER:
  
$_type=HTMLFormField::ELEMENT_TYPE_HIDDEN ;
   break;

case Column::TYPE_BOOLEAN :
   $_type=HTMLFormField::ELEMENT_TYPE_CHECKBOX


;


   break;
 default:
   break;
117:   }
118:
119:// Add the column to the list of fields
120:$this->Fields[$_column->Name]=new
121:HTMLFormField($this->Name,$_column,$_type);
122:
123:}

}

As you can see there is no refference to any TYPE_HIDDEN constant
at line 120, nor in the HTMLFormField's constructor.

I searched the net, but I just can't find the reason of this.
Can someone please help me ?

Thanks,
Puiu


When the error happens. What are the contents of 120: $_column->Name ?
  


What happens inside the constructor when you create a new instance of
HTMLFormField?
Maybe the $_type is validated there. Or i'm missing something in this
snippet.


  




Re: [PHP] Page Numbering

2007-09-19 Thread Dan Shirah
Actually, the query you mentioned will select records 11-20 because it
counts 10 records backwards starting with record 20.

print_r($result) onyl returns "Resource id #3" and not the actual data.


On 9/19/07, T. Lensselink <[EMAIL PROTECTED]> wrote:
>
> On Wed, 19 Sep 2007 10:23:58 -0400, "Dan Shirah" <[EMAIL PROTECTED]>
> wrote:
> > Becase I am using MSSQL not MYSQL.  MSSQL does not have anything easy to
> > use
> > like LIMIT in MYSQL. So, to achieve the same functionality you have to
> use
> > the subqueries.
> >
> > Having the largest number as the inner most subquery value tells the
> query
> > to retrieve the records that are equal to that number minus 10(my
> results
> > per page)
> >
> > So, if the inner most query has has a value of 30, the outer query will
> > select records 21-30.
> >
> > And, it does this just fine because if I echo out my variables I see the
> > numbers changing. But for whatever reason, the data being displayed is
> not
> > changing.
> >
> >
> > On 9/19/07, T. Lensselink <[EMAIL PROTECTED]> wrote:
> >>
> >> On Wed, 19 Sep 2007 10:05:40 -0400, "Dan Shirah" <[EMAIL PROTECTED]>
> >> wrote:
> >> > Hello all,
> >> >
> >> > I am having a problem with trying to display a set amount of records
> >> from
> >> > my
> >> > result.
> >> > I have verified that the correct values for my variables are being
> >> passed
> >> > to
> >> > the query.
> >> > The calculation for the records that should be displayed per page is
> >> > correct.
> >> > The total number of records returned from my query is correct.
> >> > And the calculated number of total pages to be displayed is correct.
> >> >
> >> > So, initially it displays the first 10 results as it should, and has
> > the
> >> > pages numbers at the bottom.  The problem is, when I click on a
> >> different
> >> > page number the same 10 results are ALWAYS displayed.  Even though my
> >> > $page
> >> > variable IS being updated.
> >> >
> >> > Any ideas why my results are not reflecting the page I select?
> >> >
> >> >
> >> >  >> > if(!isset($_GET['page'])){
> >> > $page = 1;
> >> >  } else {
> >> > $page = $_GET['page'];
> >> >  }
> >> >  // Define the number of results per page
> >> >  $max_results = 10;
> >> >  // Figure out the limit for the query based
> >> >  // on the current page number.
> >> >  $from = (($page * $max_results) - $max_results);
> >> >  echo $from."FROM";
> >> >  $page_results = $max_results + $from;
> >> >  echo $page_results."PAGE RESULTS";
> >> >   // Query the table and load all of the records into an array.
> >> >$sql = "SELECT DISTINCT * FROM (
> >> > SELECT TOP $max_results Value1, Value2 FROM (
> >> >  SELECT TOP $page_results Value1,
> >> >  FROM my_table
> >> >  WHERE my_table.column = 'P'
> >> > ) as newtbl order by credit_card_id desc
> >> >) as newtbl2 order by credit_card_id asc";
> >> >
> >> > print_r ($sql);
> >> >   $result = mssql_query($sql) or die(mssql_error());
> >> >  //print_r ($result);
> >> >   $number_rows = mssql_num_rows($result);
> >> > ?>
> >> >  >> > cellspacing='2'
> >> > bordercolor='#00'>
> >> >  >> > if(!empty($result)) {
> >> >  while ($row = mssql_fetch_array($result)) {
> >> >   $id = $row['credit_card_id'];
> >> >   $dateTime = $row['date_request_received'];
> >> >   //print_r ($id_child);
> >> > ?>
> >> > 
> >> >  >> > align='center'> > href='javascript:editRecord($id)'>$id"
> >> > ?>
> >> >  >> > align='center'>
> >> >  >> > align='center'>
> >> >  >> > align='center'>
> >> > 
> >> >  >> >  }
> >> > }
> >> > ?>
> >> > 
> >> >  >> > border="0">
> >> > 
> >> >  >> > align='center'>Results:  >> > ?>
> >> > 
> >> > 
> >> >  >> > // Figure out the total number of results in DB:
> >> > $sql_total= "SELECT * FROM my_table WHERE my_table.column = 'P'";
> >> > $tot_result = mssql_query($sql_total) or die(mssql_error());
> >> > $total_results = mssql_num_rows($tot_result) or die(mssql_error());
> >> > // Figure out the total number of pages. Always round up using ceil()
> >> > $total_pages = ceil($total_results / $max_results);
> >> > echo $max_results."Results";
> >> > echo $total_results."Total";
> >> > echo $total_pages."pages";
> >> > // Build Page Number Hyperlinks
> >> > echo "Select a Page";
> >> > // Build Previous Link
> >> > if($page > 1){
> >> > $prev = ($page - 1);
> >> > echo " > href=\"".$_SERVER['PHP_SELF']."?page=$prev\"><
> >> > ";
> >> > }
> >> >
> >> > for($i = 1; $i <= $total_pages; $i++){
> >> > if(($page) == $i){
> >> > echo "$i ";
> >> > } else {
> >> > echo "$i
> > ";
> >> > }
> >> > }
> >> > // Build Next Link
> >> > if($page < $total_pages){
> >> > $next = ($page + 1);
> >> > echo " href=\"".$_SERVER['PHP_SELF']."?page=$next\">Next>>";
> >> > }
> >> > echo "";
> >> > ?>
> >>
> >> I think it returns the same 10 records because of TOP $max_results.
> >> This will always get the first 10 records. Probably better to use
> LIMIT.
> >>
> >> Why are there so much subqu

Re: [PHP] Page Numbering

2007-09-19 Thread Dan Shirah
That gives me an array of the 10 records that are being displayed every
single time.

It's like even though the variables in my query are changing correctly from
0,10 to 10,20; the records being displayed are not updating.

The URL is reflecting the changes from page 1 to 2 correctly also.


On 9/19/07, T. Lensselink <[EMAIL PROTECTED]> wrote:
>
> On Wed, 19 Sep 2007 10:48:20 -0400, "Dan Shirah" <[EMAIL PROTECTED]>
> wrote:
> > Actually, the query you mentioned will select records 11-20 because it
> > counts 10 records backwards starting with record 20.
> >
> > print_r($result) onyl returns "Resource id #3" and not the actual data.
> >
> >
> > On 9/19/07, T. Lensselink <[EMAIL PROTECTED]> wrote:
> >>
> >> On Wed, 19 Sep 2007 10:23:58 -0400, "Dan Shirah" <[EMAIL PROTECTED]>
> >> wrote:
> >> > Becase I am using MSSQL not MYSQL.  MSSQL does not have anything easy
> > to
> >> > use
> >> > like LIMIT in MYSQL. So, to achieve the same functionality you have
> to
> >> use
> >> > the subqueries.
> >> >
> >> > Having the largest number as the inner most subquery value tells the
> >> query
> >> > to retrieve the records that are equal to that number minus 10(my
> >> results
> >> > per page)
> >> >
> >> > So, if the inner most query has has a value of 30, the outer query
> > will
> >> > select records 21-30.
> >> >
> >> > And, it does this just fine because if I echo out my variables I see
> > the
> >> > numbers changing. But for whatever reason, the data being displayed
> is
> >> not
> >> > changing.
> >> >
> >> >
> >> > On 9/19/07, T. Lensselink <[EMAIL PROTECTED]> wrote:
> >> >>
> >> >> On Wed, 19 Sep 2007 10:05:40 -0400, "Dan Shirah"
> > <[EMAIL PROTECTED]>
> >> >> wrote:
> >> >> > Hello all,
> >> >> >
> >> >> > I am having a problem with trying to display a set amount of
> > records
> >> >> from
> >> >> > my
> >> >> > result.
> >> >> > I have verified that the correct values for my variables are being
> >> >> passed
> >> >> > to
> >> >> > the query.
> >> >> > The calculation for the records that should be displayed per page
> > is
> >> >> > correct.
> >> >> > The total number of records returned from my query is correct.
> >> >> > And the calculated number of total pages to be displayed is
> > correct.
> >> >> >
> >> >> > So, initially it displays the first 10 results as it should, and
> > has
> >> > the
> >> >> > pages numbers at the bottom.  The problem is, when I click on a
> >> >> different
> >> >> > page number the same 10 results are ALWAYS displayed.  Even though
> > my
> >> >> > $page
> >> >> > variable IS being updated.
> >> >> >
> >> >> > Any ideas why my results are not reflecting the page I select?
> >> >> >
> >> >> >
> >> >> >  >> >> > if(!isset($_GET['page'])){
> >> >> > $page = 1;
> >> >> >  } else {
> >> >> > $page = $_GET['page'];
> >> >> >  }
> >> >> >  // Define the number of results per page
> >> >> >  $max_results = 10;
> >> >> >  // Figure out the limit for the query based
> >> >> >  // on the current page number.
> >> >> >  $from = (($page * $max_results) - $max_results);
> >> >> >  echo $from."FROM";
> >> >> >  $page_results = $max_results + $from;
> >> >> >  echo $page_results."PAGE RESULTS";
> >> >> >   // Query the table and load all of the records into an array.
> >> >> >$sql = "SELECT DISTINCT * FROM (
> >> >> > SELECT TOP $max_results Value1, Value2 FROM (
> >> >> >  SELECT TOP $page_results Value1,
> >> >> >  FROM my_table
> >> >> >  WHERE my_table.column = 'P'
> >> >> > ) as newtbl order by credit_card_id desc
> >> >> >) as newtbl2 order by credit_card_id asc";
> >> >> >
> >> >> > print_r ($sql);
> >> >> >   $result = mssql_query($sql) or die(mssql_error());
> >> >> >  //print_r ($result);
> >> >> >   $number_rows = mssql_num_rows($result);
> >> >> > ?>
> >> >> >  >> >> > cellspacing='2'
> >> >> > bordercolor='#00'>
> >> >> >  >> >> > if(!empty($result)) {
> >> >> >  while ($row = mssql_fetch_array($result)) {
> >> >> >   $id = $row['credit_card_id'];
> >> >> >   $dateTime = $row['date_request_received'];
> >> >> >   //print_r ($id_child);
> >> >> > ?>
> >> >> > 
> >> >> >  >> >> > align='center'> >> > href='javascript:editRecord($id)'>$id"
> >> >> > ?>
> >> >> >  >> >> > align='center'>
> >> >> >  >> >> > align='center'>
> >> >> >  >> >> > align='center'>
> >> >> > 
> >> >> >  >> >> >  }
> >> >> > }
> >> >> > ?>
> >> >> > 
> >> >> >  >> >> > border="0">
> >> >> > 
> >> >> >  >> >> > align='center'>Results:  "$number_rows";
> >> >> > ?>
> >> >> > 
> >> >> > 
> >> >> >  >> >> > // Figure out the total number of results in DB:
> >> >> > $sql_total= "SELECT * FROM my_table WHERE my_table.column = 'P'";
> >> >> > $tot_result = mssql_query($sql_total) or die(mssql_error());
> >> >> > $total_results = mssql_num_rows($tot_result) or
> die(mssql_error());
> >> >> > // Figure out the total number of pages. Always round up using
> > ceil()
> >> >> > $total_pages = ceil($total_results / $max_results);
> >> >> > echo $max_results."Results";

Re: [PHP] Page Numbering

2007-09-19 Thread Dan Shirah
I have my query echoing out. Upon initial display it looks like this:

SELECT DISTINCT * FROM ( SELECT TOP 10 Value1, Value2 FROM ( SELECT TOP 10
Value1, Value2 FROM my_table WHERE my_table.column = 'P' ) as newtbl order
by PKEY desc ) as newtbl2 order by PKEY asc

And then when I click on the link to take it to page 2, it looks like this:

SELECT DISTINCT * FROM ( SELECT TOP 10 Value1, Value2 FROM ( SELECT TOP 20
Value1, Value2 FROM my_table WHERE my_table.column = 'P' ) as newtbl order
by PKEY desc ) as newtbl2 order by PKEY asc

But still the same problem of the displayed results being the same every
time.

On 9/19/07, Dan Shirah <[EMAIL PROTECTED]> wrote:
>
> That gives me an array of the 10 records that are being displayed every
> single time.
>
> It's like even though the variables in my query are changing correctly
> from 0,10 to 10,20; the records being displayed are not updating.
>
> The URL is reflecting the changes from page 1 to 2 correctly also.
>
>
> On 9/19/07, T. Lensselink <[EMAIL PROTECTED]> wrote:
> >
> > On Wed, 19 Sep 2007 10:48:20 -0400, "Dan Shirah" <[EMAIL PROTECTED] >
> > wrote:
> > > Actually, the query you mentioned will select records 11-20 because it
> > > counts 10 records backwards starting with record 20.
> > >
> > > print_r($result) onyl returns "Resource id #3" and not the actual
> > data.
> > >
> > >
> > > On 9/19/07, T. Lensselink <[EMAIL PROTECTED]> wrote:
> > >>
> > >> On Wed, 19 Sep 2007 10:23:58 -0400, "Dan Shirah" <[EMAIL PROTECTED]
> > >
> > >> wrote:
> > >> > Becase I am using MSSQL not MYSQL.  MSSQL does not have anything
> > easy
> > > to
> > >> > use
> > >> > like LIMIT in MYSQL. So, to achieve the same functionality you have
> > to
> > >> use
> > >> > the subqueries.
> > >> >
> > >> > Having the largest number as the inner most subquery value tells
> > the
> > >> query
> > >> > to retrieve the records that are equal to that number minus 10(my
> > >> results
> > >> > per page)
> > >> >
> > >> > So, if the inner most query has has a value of 30, the outer query
> > > will
> > >> > select records 21-30.
> > >> >
> > >> > And, it does this just fine because if I echo out my variables I
> > see
> > > the
> > >> > numbers changing. But for whatever reason, the data being displayed
> > is
> > >> not
> > >> > changing.
> > >> >
> > >> >
> > >> > On 9/19/07, T. Lensselink <[EMAIL PROTECTED]> wrote:
> > >> >>
> > >> >> On Wed, 19 Sep 2007 10:05:40 -0400, "Dan Shirah"
> > > <[EMAIL PROTECTED]>
> > >> >> wrote:
> > >> >> > Hello all,
> > >> >> >
> > >> >> > I am having a problem with trying to display a set amount of
> > > records
> > >> >> from
> > >> >> > my
> > >> >> > result.
> > >> >> > I have verified that the correct values for my variables are
> > being
> > >> >> passed
> > >> >> > to
> > >> >> > the query.
> > >> >> > The calculation for the records that should be displayed per
> > page
> > > is
> > >> >> > correct.
> > >> >> > The total number of records returned from my query is correct.
> > >> >> > And the calculated number of total pages to be displayed is
> > > correct.
> > >> >> >
> > >> >> > So, initially it displays the first 10 results as it should, and
> > > has
> > >> > the
> > >> >> > pages numbers at the bottom.  The problem is, when I click on a
> > >> >> different
> > >> >> > page number the same 10 results are ALWAYS displayed.  Even
> > though
> > > my
> > >> >> > $page
> > >> >> > variable IS being updated.
> > >> >> >
> > >> >> > Any ideas why my results are not reflecting the page I select?
> > >> >> >
> > >> >> >
> > >> >> >  > >> >> > if(!isset($_GET['page'])){
> > >> >> > $page = 1;
> > >> >> >  } else {
> > >> >> > $page = $_GET['page'];
> > >> >> >  }
> > >> >> >  // Define the number of results per page
> > >> >> >  $max_results = 10;
> > >> >> >  // Figure out the limit for the query based
> > >> >> >  // on the current page number.
> > >> >> >  $from = (($page * $max_results) - $max_results);
> > >> >> >  echo $from."FROM";
> > >> >> >  $page_results = $max_results + $from;
> > >> >> >  echo $page_results."PAGE RESULTS";
> > >> >> >   // Query the table and load all of the records into an array.
> > >> >> >$sql = "SELECT DISTINCT * FROM (
> > >> >> > SELECT TOP $max_results Value1, Value2 FROM (
> > >> >> >  SELECT TOP $page_results Value1,
> > >> >> >  FROM my_table
> > >> >> >  WHERE my_table.column = 'P'
> > >> >> > ) as newtbl order by credit_card_id desc
> > >> >> >) as newtbl2 order by credit_card_id asc";
> > >> >> >
> > >> >> > print_r ($sql);
> > >> >> >   $result = mssql_query($sql) or die(mssql_error());
> > >> >> >  //print_r ($result);
> > >> >> >   $number_rows = mssql_num_rows($result);
> > >> >> > ?>
> > >> >> >  > >> >> > cellspacing='2'
> > >> >> > bordercolor='#00'>
> > >> >> >  > >> >> > if(!empty($result)) {
> > >> >> >  while ($row = mssql_fetch_array($result)) {
> > >> >> >   $id = $row['credit_card_id'];
> > >> >> >   $dateTime = $row['date_request_received'];

Re: [PHP] Page Numbering

2007-09-19 Thread Ben
I found the easiest solution is to use the 'Pager' package in pear
http://pear.php.net/package/Pager
Ben

On Wednesday 19 Sep 2007 15:45, T.Lensselink wrote:
> On Wed, 19 Sep 2007 10:23:58 -0400, "Dan Shirah" <[EMAIL PROTECTED]>
> wrote:
> > Becase I am using MSSQL not MYSQL.  MSSQL does not have anything easy to
> > use
> > like LIMIT in MYSQL. So, to achieve the same functionality you have to
> use
> > the subqueries.
> > 
> > Having the largest number as the inner most subquery value tells the
> query
> > to retrieve the records that are equal to that number minus 10(my results
> > per page)
> > 
> > So, if the inner most query has has a value of 30, the outer query will
> > select records 21-30.
> > 
> > And, it does this just fine because if I echo out my variables I see the
> > numbers changing. But for whatever reason, the data being displayed is
> not
> > changing.
> > 
> > 
> > On 9/19/07, T. Lensselink <[EMAIL PROTECTED]> wrote:
> >>
> >> On Wed, 19 Sep 2007 10:05:40 -0400, "Dan Shirah" <[EMAIL PROTECTED]>
> >> wrote:
> >> > Hello all,
> >> >
> >> > I am having a problem with trying to display a set amount of records
> >> from
> >> > my
> >> > result.
> >> > I have verified that the correct values for my variables are being
> >> passed
> >> > to
> >> > the query.
> >> > The calculation for the records that should be displayed per page is
> >> > correct.
> >> > The total number of records returned from my query is correct.
> >> > And the calculated number of total pages to be displayed is correct.
> >> >
> >> > So, initially it displays the first 10 results as it should, and has
> > the
> >> > pages numbers at the bottom.  The problem is, when I click on a
> >> different
> >> > page number the same 10 results are ALWAYS displayed.  Even though my
> >> > $page
> >> > variable IS being updated.
> >> >
> >> > Any ideas why my results are not reflecting the page I select?
> >> >
> >> >
> >> >  >> > if(!isset($_GET['page'])){
> >> > $page = 1;
> >> >  } else {
> >> > $page = $_GET['page'];
> >> >  }
> >> >  // Define the number of results per page
> >> >  $max_results = 10;
> >> >  // Figure out the limit for the query based
> >> >  // on the current page number.
> >> >  $from = (($page * $max_results) - $max_results);
> >> >  echo $from."FROM";
> >> >  $page_results = $max_results + $from;
> >> >  echo $page_results."PAGE RESULTS";
> >> >   // Query the table and load all of the records into an array.
> >> >$sql = "SELECT DISTINCT * FROM (
> >> > SELECT TOP $max_results Value1, Value2 FROM (
> >> >  SELECT TOP $page_results Value1,
> >> >  FROM my_table
> >> >  WHERE my_table.column = 'P'
> >> > ) as newtbl order by credit_card_id desc
> >> >) as newtbl2 order by credit_card_id asc";
> >> >
> >> > print_r ($sql);
> >> >   $result = mssql_query($sql) or die(mssql_error());
> >> >  //print_r ($result);
> >> >   $number_rows = mssql_num_rows($result);
> >> > ?>
> >> >  >> > cellspacing='2'
> >> > bordercolor='#00'>
> >> >  >> > if(!empty($result)) {
> >> >  while ($row = mssql_fetch_array($result)) {
> >> >   $id = $row['credit_card_id'];
> >> >   $dateTime = $row['date_request_received'];
> >> >   //print_r ($id_child);
> >> > ?>
> >> > 
> >> >  >> > align='center'> > href='javascript:editRecord($id)'>$id"
> >> > ?>
> >> >  >> > align='center'>
> >> >  >> > align='center'>
> >> >  >> > align='center'>
> >> > 
> >> >  >> >  }
> >> > }
> >> > ?>
> >> > 
> >> >  >> > border="0">
> >> > 
> >> >  >> > align='center'>Results:  >> > ?>
> >> > 
> >> > 
> >> >  >> > // Figure out the total number of results in DB:
> >> > $sql_total= "SELECT * FROM my_table WHERE my_table.column = 'P'";
> >> > $tot_result = mssql_query($sql_total) or die(mssql_error());
> >> > $total_results = mssql_num_rows($tot_result) or die(mssql_error());
> >> > // Figure out the total number of pages. Always round up using ceil()
> >> > $total_pages = ceil($total_results / $max_results);
> >> > echo $max_results."Results";
> >> > echo $total_results."Total";
> >> > echo $total_pages."pages";
> >> > // Build Page Number Hyperlinks
> >> > echo "Select a Page";
> >> > // Build Previous Link
> >> > if($page > 1){
> >> > $prev = ($page - 1);
> >> > echo " > href=\"".$_SERVER['PHP_SELF']."?page=$prev\"><
> >> > ";
> >> > }
> >> >
> >> > for($i = 1; $i <= $total_pages; $i++){
> >> > if(($page) == $i){
> >> > echo "$i ";
> >> > } else {
> >> > echo "$i
> > ";
> >> > }
> >> > }
> >> > // Build Next Link
> >> > if($page < $total_pages){
> >> > $next = ($page + 1);
> >> > echo "Next>>";
> >> > }
> >> > echo "";
> >> > ?>
> >>
> >> I think it returns the same 10 records because of TOP $max_results.
> >> This will always get the first 10 records. Probably better to use LIMIT.
> >>
> >> Why are there so much subqueries needed to get the result set?
> >> Why not something like this:
> >>
> >> SELECT DISTINCT * FROM my_table WHERE my_table.column = 'p' O

Re: [PHP] Page Numbering

2007-09-19 Thread T . Lensselink
On Wed, 19 Sep 2007 10:48:20 -0400, "Dan Shirah" <[EMAIL PROTECTED]>
wrote:
> Actually, the query you mentioned will select records 11-20 because it
> counts 10 records backwards starting with record 20.
> 
> print_r($result) onyl returns "Resource id #3" and not the actual data.
> 
> 
> On 9/19/07, T. Lensselink <[EMAIL PROTECTED]> wrote:
>>
>> On Wed, 19 Sep 2007 10:23:58 -0400, "Dan Shirah" <[EMAIL PROTECTED]>
>> wrote:
>> > Becase I am using MSSQL not MYSQL.  MSSQL does not have anything easy
> to
>> > use
>> > like LIMIT in MYSQL. So, to achieve the same functionality you have to
>> use
>> > the subqueries.
>> >
>> > Having the largest number as the inner most subquery value tells the
>> query
>> > to retrieve the records that are equal to that number minus 10(my
>> results
>> > per page)
>> >
>> > So, if the inner most query has has a value of 30, the outer query
> will
>> > select records 21-30.
>> >
>> > And, it does this just fine because if I echo out my variables I see
> the
>> > numbers changing. But for whatever reason, the data being displayed is
>> not
>> > changing.
>> >
>> >
>> > On 9/19/07, T. Lensselink <[EMAIL PROTECTED]> wrote:
>> >>
>> >> On Wed, 19 Sep 2007 10:05:40 -0400, "Dan Shirah"
> <[EMAIL PROTECTED]>
>> >> wrote:
>> >> > Hello all,
>> >> >
>> >> > I am having a problem with trying to display a set amount of
> records
>> >> from
>> >> > my
>> >> > result.
>> >> > I have verified that the correct values for my variables are being
>> >> passed
>> >> > to
>> >> > the query.
>> >> > The calculation for the records that should be displayed per page
> is
>> >> > correct.
>> >> > The total number of records returned from my query is correct.
>> >> > And the calculated number of total pages to be displayed is
> correct.
>> >> >
>> >> > So, initially it displays the first 10 results as it should, and
> has
>> > the
>> >> > pages numbers at the bottom.  The problem is, when I click on a
>> >> different
>> >> > page number the same 10 results are ALWAYS displayed.  Even though
> my
>> >> > $page
>> >> > variable IS being updated.
>> >> >
>> >> > Any ideas why my results are not reflecting the page I select?
>> >> >
>> >> >
>> >> > > >> > if(!isset($_GET['page'])){
>> >> > $page = 1;
>> >> >  } else {
>> >> > $page = $_GET['page'];
>> >> >  }
>> >> >  // Define the number of results per page
>> >> >  $max_results = 10;
>> >> >  // Figure out the limit for the query based
>> >> >  // on the current page number.
>> >> >  $from = (($page * $max_results) - $max_results);
>> >> >  echo $from."FROM";
>> >> >  $page_results = $max_results + $from;
>> >> >  echo $page_results."PAGE RESULTS";
>> >> >   // Query the table and load all of the records into an array.
>> >> >$sql = "SELECT DISTINCT * FROM (
>> >> > SELECT TOP $max_results Value1, Value2 FROM (
>> >> >  SELECT TOP $page_results Value1,
>> >> >  FROM my_table
>> >> >  WHERE my_table.column = 'P'
>> >> > ) as newtbl order by credit_card_id desc
>> >> >) as newtbl2 order by credit_card_id asc";
>> >> >
>> >> > print_r ($sql);
>> >> >   $result = mssql_query($sql) or die(mssql_error());
>> >> >  //print_r ($result);
>> >> >   $number_rows = mssql_num_rows($result);
>> >> > ?>
>> >> > > >> > cellspacing='2'
>> >> > bordercolor='#00'>
>> >> > > >> > if(!empty($result)) {
>> >> >  while ($row = mssql_fetch_array($result)) {
>> >> >   $id = $row['credit_card_id'];
>> >> >   $dateTime = $row['date_request_received'];
>> >> >   //print_r ($id_child);
>> >> > ?>
>> >> > 
>> >> > > >> > align='center'>> > href='javascript:editRecord($id)'>$id"
>> >> > ?>
>> >> > > >> > align='center'>
>> >> > > >> > align='center'>
>> >> > > >> > align='center'>
>> >> > 
>> >> > > >> >  }
>> >> > }
>> >> > ?>
>> >> > 
>> >> > > >> > border="0">
>> >> > 
>> >> > > >> > align='center'>Results: > >> > ?>
>> >> > 
>> >> > 
>> >> > > >> > // Figure out the total number of results in DB:
>> >> > $sql_total= "SELECT * FROM my_table WHERE my_table.column = 'P'";
>> >> > $tot_result = mssql_query($sql_total) or die(mssql_error());
>> >> > $total_results = mssql_num_rows($tot_result) or die(mssql_error());
>> >> > // Figure out the total number of pages. Always round up using
> ceil()
>> >> > $total_pages = ceil($total_results / $max_results);
>> >> > echo $max_results."Results";
>> >> > echo $total_results."Total";
>> >> > echo $total_pages."pages";
>> >> > // Build Page Number Hyperlinks
>> >> > echo "Select a Page";
>> >> > // Build Previous Link
>> >> > if($page > 1){
>> >> > $prev = ($page - 1);
>> >> > echo "> > href=\"".$_SERVER['PHP_SELF']."?page=$prev\"><
>> >> > ";
>> >> > }
>> >> >
>> >> > for($i = 1; $i <= $total_pages; $i++){
>> >> > if(($page) == $i){
>> >> > echo "$i ";
>> >> > } else {
>> >> > echo " href=\"".$_SERVER['PHP_SELF']."?page=$i\">$i
>> > ";
>> >> > }
>> >> > }
>> >> > // Build Next Link
>> >> > if($page < $total_pages){
>> >> > $next = ($page + 1);
>

Re: [PHP] Page Numbering

2007-09-19 Thread Zoltán Németh
2007. 09. 19, szerda keltezéssel 11.08-kor Dan Shirah ezt írta:
> I have my query echoing out. Upon initial display it looks like this:
> 
> SELECT DISTINCT * FROM ( SELECT TOP 10 Value1, Value2 FROM ( SELECT TOP 10
> Value1, Value2 FROM my_table WHERE my_table.column = 'P' ) as newtbl order
> by PKEY desc ) as newtbl2 order by PKEY asc
> 
> And then when I click on the link to take it to page 2, it looks like this:
> 
> SELECT DISTINCT * FROM ( SELECT TOP 10 Value1, Value2 FROM ( SELECT TOP 20
> Value1, Value2 FROM my_table WHERE my_table.column = 'P' ) as newtbl order
> by PKEY desc ) as newtbl2 order by PKEY asc
> 
> But still the same problem of the displayed results being the same every
> time.

I know almost nothing about mssql but a quick googling for 'mssql select
bottom' gave me this:

http://forums.belution.com/en/sql/000/123/74.shtml

maybe you could use a query like that

greets
Zoltán Németh

> 
> On 9/19/07, Dan Shirah <[EMAIL PROTECTED]> wrote:
> >
> > That gives me an array of the 10 records that are being displayed every
> > single time.
> >
> > It's like even though the variables in my query are changing correctly
> > from 0,10 to 10,20; the records being displayed are not updating.
> >
> > The URL is reflecting the changes from page 1 to 2 correctly also.
> >
> >
> > On 9/19/07, T. Lensselink <[EMAIL PROTECTED]> wrote:
> > >
> > > On Wed, 19 Sep 2007 10:48:20 -0400, "Dan Shirah" <[EMAIL PROTECTED] >
> > > wrote:
> > > > Actually, the query you mentioned will select records 11-20 because it
> > > > counts 10 records backwards starting with record 20.
> > > >
> > > > print_r($result) onyl returns "Resource id #3" and not the actual
> > > data.
> > > >
> > > >
> > > > On 9/19/07, T. Lensselink <[EMAIL PROTECTED]> wrote:
> > > >>
> > > >> On Wed, 19 Sep 2007 10:23:58 -0400, "Dan Shirah" <[EMAIL PROTECTED]
> > > >
> > > >> wrote:
> > > >> > Becase I am using MSSQL not MYSQL.  MSSQL does not have anything
> > > easy
> > > > to
> > > >> > use
> > > >> > like LIMIT in MYSQL. So, to achieve the same functionality you have
> > > to
> > > >> use
> > > >> > the subqueries.
> > > >> >
> > > >> > Having the largest number as the inner most subquery value tells
> > > the
> > > >> query
> > > >> > to retrieve the records that are equal to that number minus 10(my
> > > >> results
> > > >> > per page)
> > > >> >
> > > >> > So, if the inner most query has has a value of 30, the outer query
> > > > will
> > > >> > select records 21-30.
> > > >> >
> > > >> > And, it does this just fine because if I echo out my variables I
> > > see
> > > > the
> > > >> > numbers changing. But for whatever reason, the data being displayed
> > > is
> > > >> not
> > > >> > changing.
> > > >> >
> > > >> >
> > > >> > On 9/19/07, T. Lensselink <[EMAIL PROTECTED]> wrote:
> > > >> >>
> > > >> >> On Wed, 19 Sep 2007 10:05:40 -0400, "Dan Shirah"
> > > > <[EMAIL PROTECTED]>
> > > >> >> wrote:
> > > >> >> > Hello all,
> > > >> >> >
> > > >> >> > I am having a problem with trying to display a set amount of
> > > > records
> > > >> >> from
> > > >> >> > my
> > > >> >> > result.
> > > >> >> > I have verified that the correct values for my variables are
> > > being
> > > >> >> passed
> > > >> >> > to
> > > >> >> > the query.
> > > >> >> > The calculation for the records that should be displayed per
> > > page
> > > > is
> > > >> >> > correct.
> > > >> >> > The total number of records returned from my query is correct.
> > > >> >> > And the calculated number of total pages to be displayed is
> > > > correct.
> > > >> >> >
> > > >> >> > So, initially it displays the first 10 results as it should, and
> > > > has
> > > >> > the
> > > >> >> > pages numbers at the bottom.  The problem is, when I click on a
> > > >> >> different
> > > >> >> > page number the same 10 results are ALWAYS displayed.  Even
> > > though
> > > > my
> > > >> >> > $page
> > > >> >> > variable IS being updated.
> > > >> >> >
> > > >> >> > Any ideas why my results are not reflecting the page I select?
> > > >> >> >
> > > >> >> >
> > > >> >> >  > > >> >> > if(!isset($_GET['page'])){
> > > >> >> > $page = 1;
> > > >> >> >  } else {
> > > >> >> > $page = $_GET['page'];
> > > >> >> >  }
> > > >> >> >  // Define the number of results per page
> > > >> >> >  $max_results = 10;
> > > >> >> >  // Figure out the limit for the query based
> > > >> >> >  // on the current page number.
> > > >> >> >  $from = (($page * $max_results) - $max_results);
> > > >> >> >  echo $from."FROM";
> > > >> >> >  $page_results = $max_results + $from;
> > > >> >> >  echo $page_results."PAGE RESULTS";
> > > >> >> >   // Query the table and load all of the records into an array.
> > > >> >> >$sql = "SELECT DISTINCT * FROM (
> > > >> >> > SELECT TOP $max_results Value1, Value2 FROM (
> > > >> >> >  SELECT TOP $page_results Value1,
> > > >> >> >  FROM my_table
> > > >> >> >  WHERE my_table.column = 'P'
> > > >> >> > ) as newtbl order by credit_card_id desc
> > > >> >> >) 

Re: [PHP] Page Numbering

2007-09-19 Thread Jim Lucas

Dan Shirah wrote:

Hello all,

I am having a problem with trying to display a set amount of records from my
result.
I have verified that the correct values for my variables are being passed to
the query.
The calculation for the records that should be displayed per page is
correct.
The total number of records returned from my query is correct.
And the calculated number of total pages to be displayed is correct.

So, initially it displays the first 10 results as it should, and has the
pages numbers at the bottom.  The problem is, when I click on a different
page number the same 10 results are ALWAYS displayed.  Even though my $page
variable IS being updated.

Any ideas why my results are not reflecting the page I select?



I would do it like this

This assumes that 'credit_card_id' is unique,

if it is not, then don't worry about reading the rest



--
Jim Lucas

   "Some men are born to greatness, some achieve greatness,
   and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
by William Shakespeare

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



Re: [PHP] Finding next recored in a array

2007-09-19 Thread tedd

At 11:52 AM -0400 9/17/07, brian wrote:

tedd wrote:

Richard Kurth wrote:


$Campaign_array| = array('0','1','3','5','8','15','25');|
I know that I can find the next recored in a array using next. 
What I do not understand is if I know the last number was say 5 
how do I tell the script that that is the current number so I can 
select the next  record



What the next record?

Try:

$array = array('0','1','3','5','8','15','25');
$val = "5";

echo($array[array_search($val, $array)+1]);

Cheers,

tedd


Not quite:

$array = array('0','1','3','5','8','15','25');
$val = "25";

echo($array[array_search($val, $array)+1]);

Notice: Undefined offset: 7 ...

brian


Duh?

You program for that -- you want me to write the entire code?

Cheers,

tedd
--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

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



Re: [PHP] Page Numbering

2007-09-19 Thread Dan Shirah
Whenever the query has the NOT IN included in it, I get the following error:

Warning: mssql_query()
[function.mssql-query]:
message: Incorrect syntax near the keyword 'as'. (severity 15)


On 9/19/07, Jim Lucas <[EMAIL PROTECTED]> wrote:
>
> Dan Shirah wrote:
> > Hello all,
> >
> > I am having a problem with trying to display a set amount of records
> from my
> > result.
> > I have verified that the correct values for my variables are being
> passed to
> > the query.
> > The calculation for the records that should be displayed per page is
> > correct.
> > The total number of records returned from my query is correct.
> > And the calculated number of total pages to be displayed is correct.
> >
> > So, initially it displays the first 10 results as it should, and has the
> > pages numbers at the bottom.  The problem is, when I click on a
> different
> > page number the same 10 results are ALWAYS displayed.  Even though my
> $page
> > variable IS being updated.
> >
> > Any ideas why my results are not reflecting the page I select?
> >
>
> I would do it like this
>
> This assumes that 'credit_card_id' is unique,
>
> if it is not, then don't worry about reading the rest
>
> 
> # Get page number if passed to script
> $page = intval( empty($_GET['page']) ? 1 : $_GET['page'] );
>
> # Set number of rows to display from result set
> $max_results = 10;
>
> # Calculate the number of results that we have already looked at
> $page_results = intval(($page*$max_results)-$max_results);
>
> # Set your ORDER BY criteria.  This needs to be the same for each SQL
> statement
> # This is why I have setup a variable, so no mistakes will be made
> $order_by_criteria = 'credit_card_id';
>
> # Figure out which SQL statement we need to use
> if ( $page === 1 ) {
>
># Query for page 1
> $SQL = "SELECT  TOP {$max_results}
>Value1, Value2
>FROMmy_table
>ORDER BY {$order_by_criteria}";
>
> } else {
>
># Query for page 2 and greater
> $SQL = "SELECT  TOP {$max_results}
>Value1, Value2
>FROMmy_table
>WHERE   credit_card_id NOT IN (
>SELECT  TOP {$page_results}
>credit_card_id
>FROMmy_table
>WHERE   my_table.column = 'P'
>ORDER BY {$order_by_criteria}
>) AS newtbl
>ORDER BY {$order_by_criteria}";
>
> }
>
> ... run your $SQL statement here and work with the results
> ?>
>
> --
> Jim Lucas
>
>"Some men are born to greatness, some achieve greatness,
>and some have greatness thrust upon them."
>
> Twelfth Night, Act II, Scene V
> by William Shakespeare
>
>


Re: [PHP] Page Numbering

2007-09-19 Thread Jim Lucas

Dan Shirah wrote:

Whenever the query has the NOT IN included in it, I get the following error:

Warning: mssql_query()
[function.mssql-query]:
message: Incorrect syntax near the keyword 'as'. (severity 15)





yup, sorry, missed that in the copy/paste  remove the 'AS newtbl' part


   ORDER BY {$order_by_criteria}";

}

... run your $SQL statement here and work with the results
?>



--
Jim Lucas

   "Some men are born to greatness, some achieve greatness,
   and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
by William Shakespeare

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



[PHP] [SOLVED] Page Numbering

2007-09-19 Thread Dan Shirah
Awesome.

I just had to modify the outter query:

$SQL = "SELECT  TOP {$max_results}
   Value1, Value2
   FROMmy_table
   WHERE   credit_card_id NOT IN (

To read:

$SQL = "SELECT  TOP {$max_results}
   Value1, Value2
   FROMmy_table
   WHERE   my_table.column = 'P'
   AND credit_card_id NOT IN (

And it works like a champ.

Thank you very much to everyone that helped me on this!



On 9/19/07, Jim Lucas <[EMAIL PROTECTED]> wrote:
>
> Dan Shirah wrote:
> > Whenever the query has the NOT IN included in it, I get the following
> error:
> >
> > Warning: mssql_query()
> > [function.mssql-query<
> http://develop1/credit%20card%20processing/Process/function.mssql-query>]:
> > message: Incorrect syntax near the keyword 'as'. (severity 15)
> >
> >>
> >>  >>
> >> # Get page number if passed to script
> >> $page = intval( empty($_GET['page']) ? 1 : $_GET['page'] );
> >>
> >> # Set number of rows to display from result set
> >> $max_results = 10;
> >>
> >> # Calculate the number of results that we have already looked at
> >> $page_results = intval(($page*$max_results)-$max_results);
> >>
> >> # Set your ORDER BY criteria.  This needs to be the same for each SQL
> >> statement
> >> # This is why I have setup a variable, so no mistakes will be made
> >> $order_by_criteria = 'credit_card_id';
> >>
> >> # Figure out which SQL statement we need to use
> >> if ( $page === 1 ) {
> >>
> >># Query for page 1
> >> $SQL = "SELECT  TOP {$max_results}
> >>Value1, Value2
> >>FROMmy_table
> >>ORDER BY {$order_by_criteria}";
> >>
> >> } else {
> >>
> >># Query for page 2 and greater
> >> $SQL = "SELECT  TOP {$max_results}
> >>Value1, Value2
> >>FROMmy_table
> >>WHERE   credit_card_id NOT IN (
> >>SELECT  TOP {$page_results}
> >>credit_card_id
> >>FROMmy_table
> >>WHERE   my_table.column = 'P'
> >>ORDER BY {$order_by_criteria}
> >>) AS newtbl
>
> yup, sorry, missed that in the copy/paste  remove the 'AS newtbl' part
>
> >>ORDER BY {$order_by_criteria}";
> >>
> >> }
> >>
> >> ... run your $SQL statement here and work with the results
> >> ?>
>
>
> --
> Jim Lucas
>
>"Some men are born to greatness, some achieve greatness,
>and some have greatness thrust upon them."
>
> Twelfth Night, Act II, Scene V
> by William Shakespeare
>
>


Re: [PHP] [SOLVED] Page Numbering

2007-09-19 Thread Jim Lucas

Dan Shirah wrote:

Awesome.

I just had to modify the outter query:

$SQL = "SELECT  TOP {$max_results}
   Value1, Value2
   FROMmy_table
   WHERE   credit_card_id NOT IN (

To read:

$SQL = "SELECT  TOP {$max_results}
   Value1, Value2
   FROMmy_table
   WHERE   my_table.column = 'P'
   AND credit_card_id NOT IN (

And it works like a champ.

Thank you very much to everyone that helped me on this!



On 9/19/07, Jim Lucas <[EMAIL PROTECTED]> wrote:

Dan Shirah wrote:

Whenever the query has the NOT IN included in it, I get the following

error:

Warning: mssql_query()
[function.mssql-query<

http://develop1/credit%20card%20processing/Process/function.mssql-query>]:

message: Incorrect syntax near the keyword 'as'. (severity 15)



yup, sorry, missed that in the copy/paste  remove the 'AS newtbl' part


   ORDER BY {$order_by_criteria}";

}

... run your $SQL statement here and work with the results
?>


--
Jim Lucas

   "Some men are born to greatness, some achieve greatness,
   and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
by William Shakespeare






just noticed that I missed that where clause in the page 1 query also.  make 
sure you add that.

--
Jim Lucas

   "Some men are born to greatness, some achieve greatness,
   and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
by William Shakespeare

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



[PHP] Format_number and input_object_tag

2007-09-19 Thread Augusto Morais

Hi,



I have 2 problems.

First: When an user type a number that have comma the numbers after of 
comma doesnt safe.


example:

the user wants save the number:

10,85


I dont know but the symfony just save the number 10. The 85 is ignored.


How i fix it ?


Second problem:


i'm trying format a number in the object_input_tag . How i do it ?



array (

  'size' => 23,
  'control_name' => 'estoque_entrada[preco_unitario]',
)); echo $value ? $value : ' ' ?>


the correct way is change the getPrecoUnitario function in 
actions.class.php ?




thanks




Augusto Morais

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



Re: [PHP] Finding next recored in a array

2007-09-19 Thread brian

tedd wrote:

At 11:52 AM -0400 9/17/07, brian wrote:


tedd wrote:


Richard Kurth wrote:


$Campaign_array| = array('0','1','3','5','8','15','25');|
I know that I can find the next recored in a array using next. What 
I do not understand is if I know the last number was say 5 how do I 
tell the script that that is the current number so I can select the 
next  record




What the next record?

Try:

$array = array('0','1','3','5','8','15','25');
$val = "5";

echo($array[array_search($val, $array)+1]);

Cheers,

tedd



Not quite:

$array = array('0','1','3','5','8','15','25');
$val = "25";

echo($array[array_search($val, $array)+1]);

Notice: Undefined offset: 7 ...

brian



Duh?

You program for that -- you want me to write the entire code?



~sigh~

Grasshopper, the point i was trying to make is that your example 
displays what *not* to do with array_search(). Though a wonderful 
teaching aid in itself, it falls somewhat short of being a reasonable 
solution for the OP.


brian

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



[PHP] Open New URL window

2007-09-19 Thread Andrew Prostko
I am new to PHP and to email lists so I apologize in advance.


What I am trying to do is to take a password from user input, check
it to make sure it is == to something, say “burgers”

My problem is, I do not know how to make the Else statement...
How do I get it to open a new url?
I want it IF yes open this page, else open this page
or
If it is not correct then Say the password is incorrect or
something… 
Else
Open a different webpage

My last attempt:
---











You'll need a password to get in here. We're
tryin' to keep out the 

riff-raff.







Name: 

Email: 

What is the Current Coupon Password?: 


Return to Char-lees





http://www.google.com/","r";;

?>


---

This creates a nice small form with an image to the left.

My problem is, I do not know how to make the Else statement...
How do I get it to open a new url?
I want it IF yes open this page, else open this page

Andrew Prostko
AProstko @ verizon.net
 

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



RE: [PHP] Page Numbering

2007-09-19 Thread Andrew Wilson
What do I have to do to get off this list. Murder someone?
Please take me off the list as I have already tried to unsubscribe several
times.

The email is registered under [EMAIL PROTECTED]  

-Original Message-
From: Jim Lucas [mailto:[EMAIL PROTECTED] 
Sent: Thursday, September 20, 2007 4:03 AM
To: Dan Shirah
Cc: php-general
Subject: Re: [PHP] Page Numbering

Dan Shirah wrote:
> Whenever the query has the NOT IN included in it, I get the following
error:
> 
> Warning: mssql_query()
>
[function.mssql-query]:
> message: Incorrect syntax near the keyword 'as'. (severity 15)
> 
>>
>> >
>> # Get page number if passed to script $page = intval( 
>> empty($_GET['page']) ? 1 : $_GET['page'] );
>>
>> # Set number of rows to display from result set $max_results = 10;
>>
>> # Calculate the number of results that we have already looked at 
>> $page_results = intval(($page*$max_results)-$max_results);
>>
>> # Set your ORDER BY criteria.  This needs to be the same for each SQL 
>> statement # This is why I have setup a variable, so no mistakes will 
>> be made $order_by_criteria = 'credit_card_id';
>>
>> # Figure out which SQL statement we need to use if ( $page === 1 ) {
>>
>># Query for page 1
>> $SQL = "SELECT  TOP {$max_results}
>>Value1, Value2
>>FROMmy_table
>>ORDER BY {$order_by_criteria}";
>>
>> } else {
>>
>># Query for page 2 and greater $SQL = "SELECT  TOP 
>> {$max_results}
>>Value1, Value2
>>FROMmy_table
>>WHERE   credit_card_id NOT IN (
>>SELECT  TOP {$page_results}
>>credit_card_id
>>FROMmy_table
>>WHERE   my_table.column = 'P'
>>ORDER BY {$order_by_criteria}
>>) AS newtbl

yup, sorry, missed that in the copy/paste  remove the 'AS newtbl' part

>>ORDER BY {$order_by_criteria}";
>>
>> }
>>
>> ... run your $SQL statement here and work with the results ?>


--
Jim Lucas

"Some men are born to greatness, some achieve greatness,
and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
 by William Shakespeare

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

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



Re: [PHP] Page Numbering

2007-09-19 Thread Jim Lucas

Andrew Wilson wrote:

What do I have to do to get off this list. Murder someone?
Please take me off the list as I have already tried to unsubscribe several
times.

The email is registered under [EMAIL PROTECTED]  


-Original Message-
From: Jim Lucas [mailto:[EMAIL PROTECTED] 
Sent: Thursday, September 20, 2007 4:03 AM

To: Dan Shirah
Cc: php-general
Subject: Re: [PHP] Page Numbering

Dan Shirah wrote:

Whenever the query has the NOT IN included in it, I get the following

error:

Warning: mssql_query()


[function.mssql-query]:

message: Incorrect syntax near the keyword 'as'. (severity 15)


# Get page number if passed to script $page = intval( 
empty($_GET['page']) ? 1 : $_GET['page'] );


# Set number of rows to display from result set $max_results = 10;

# Calculate the number of results that we have already looked at 
$page_results = intval(($page*$max_results)-$max_results);


# Set your ORDER BY criteria.  This needs to be the same for each SQL 
statement # This is why I have setup a variable, so no mistakes will 
be made $order_by_criteria = 'credit_card_id';


# Figure out which SQL statement we need to use if ( $page === 1 ) {

   # Query for page 1
$SQL = "SELECT  TOP {$max_results}
   Value1, Value2
   FROMmy_table
   ORDER BY {$order_by_criteria}";

} else {

   # Query for page 2 and greater $SQL = "SELECT  TOP 
{$max_results}

   Value1, Value2
   FROMmy_table
   WHERE   credit_card_id NOT IN (
   SELECT  TOP {$page_results}
   credit_card_id
   FROMmy_table
   WHERE   my_table.column = 'P'
   ORDER BY {$order_by_criteria}
   ) AS newtbl


yup, sorry, missed that in the copy/paste  remove the 'AS newtbl' part


   ORDER BY {$order_by_criteria}";

}

... run your $SQL statement here and work with the results ?>



--
Jim Lucas

"Some men are born to greatness, some achieve greatness,
and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
 by William Shakespeare

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


Well, it looks like you are using the wrong email address.

The email address that you used to send this email was from

[EMAIL PROTECTED]

and the email address that you are trying to unsubscribe is

[EMAIL PROTECTED]

which is it?

--
Jim Lucas

   "Some men are born to greatness, some achieve greatness,
   and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
by William Shakespeare

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



Re: [PHP] Open New URL window

2007-09-19 Thread Jim Lucas

Andrew Prostko wrote:

I am new to PHP and to email lists so I apologize in advance.


What I am trying to do is to take a password from user input, check
it to make sure it is == to something, say “burgers”

My problem is, I do not know how to make the Else statement...
How do I get it to open a new url?
I want it IF yes open this page, else open this page
or
If it is not correct then Say the password is incorrect or
something… 
	Else

Open a different webpage

My last attempt:
---











You'll need a password to get in here. We're
tryin' to keep out the 


riff-raff.







Name: 

Email: 

What is the Current Coupon Password?: 


Return to Char-lees





http://www.google.com/","r";;

?>


---

This creates a nice small form with an image to the left.

My problem is, I do not know how to make the Else statement...
How do I get it to open a new url?
I want it IF yes open this page, else open this page

Andrew Prostko
AProstko @ verizon.net
 



You might be in need of the header() function in php



--
Jim Lucas

   "Some men are born to greatness, some achieve greatness,
   and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
by William Shakespeare

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



Re: [PHP] Open New URL window

2007-09-19 Thread Richard S. Crawford
On Wednesday 19 September 2007 15:50:08 Andrew Prostko wrote:
> My problem is, I do not know how to make the Else statement...
> How do I get it to open a new url?
> I want it IF yes open this page, else open this page

Andrew,

try the header() function:



...show your form...

 tag at the very top might 
be sending headers to your browser before your else statement has a chance to 
kick in, generating an error which reads something like, "Headers already 
sent..."  Try moving it to after the conditional, like this:



< BODY onLoad="top.window.focus()" >

...rest of your form...

http://www.daikaijuzine.com)
Personal website: http://www.mossroot.com
http://www.myspace.com/underpope / underpope.livejournal.com
"We are here to help each other get through this thing, whatever it is."
(Kurt Vonnegut, 1922 - 2007)


signature.asc
Description: This is a digitally signed message part.


Re: [PHP] back on bug 42065 , strange behavior with ArrayObject

2007-09-19 Thread Chris

Julien Pauli wrote:
Wow, all right ; that's why casting to (array) before passing the 
variable , thus making a copy of it, works.

Thanks for that short but effective answer ;-)

However, except in the comments, this is not said in the original doc.
It should be written
ArrayObject ArrayObject::__construct ( mixed &$input )
shouldn't it ?


I guess it's time to post a documentation bug :) I'm sure they'd also 
appreciate a patch if possible.


--
Postgresql & php tutorials
http://www.designmagick.com/

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



Re: [PHP] my paging task with PHP does not work. It uses cookie.

2007-09-19 Thread Patrik Hasibuan
Hi Arvid,

thank you very much for your remark. It is useful for me.
===
On Fri, 14 Sep 2007 12:01:40 +0300
"Arvids Godjuks" <[EMAIL PROTECTED]> wrote:

> Don't use SQL_CALC_FOUND ROWS on simple queries, when you have to run a
> simple query on one or two (with join) tables with a simple WHERE. Especialy
> if tables are big. I found out that single SELECT COUNT(id) FROM table is
> far more faster when query has simple WHERE conditions. I use
> SQL_CALC_FOUND_ROWS only with a rather complex queries - that
> SQL_CALC_FOUND_ROWS doesn't affect query execution at all (well, it affects
> ofcourse, but affect is so small, you can't see it).
> 


-- 
Patrik Hasibuan <[EMAIL PROTECTED]>
Junior Programmer

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



Re: [PHP] my paging task with PHP does not work. It uses cookie.

2007-09-19 Thread Patrik Hasibuan
Dear Brian,

My problem is solved. thank you very much for your help.
===
On Wed, 12 Sep 2007 14:04:11 -0400
brian <[EMAIL PROTECTED]> wrote:

> Patrik Hasibuan wrote:
> > Dear my friends...
> > 
> > I am trying to display the content of a table. Each page must content
> > only 5 records maximum. Each page has "Previous" and "Next" buttons
> > (made from anchor).
> > 
> > I dump the primary of the working table and keep it in a cookie. So
> > than the paging task work with the index of cookie array. But the
> > $curguruescomidiklan stays "0" each time I click "Next" button.
> > 
> 
> Patrick, i can't say what the problem is, but i recommend using the PEAR 
> Pager package for this if you have PEAR available. It takes care of a 
> lot of the heavy lifting and is very configurable.
> 
> http://pear.php.net/package/Pager
> 
> This does not require setting any cookies.
> 
> brian
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 
> 


-- 
Patrik Hasibuan <[EMAIL PROTECTED]>
Junior Programmer

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



Re: [PHP] my paging task with PHP does not work. It uses cookie.

2007-09-19 Thread Patrik Hasibuan
Dear mike,

your thread solved my problem.

I really appreciate your help.

Thank you very much.

On Thu, 13 Sep 2007 14:49:29 -0700
mike <[EMAIL PROTECTED]> wrote:

> warning: this is VERY UGLY CODE. i wrote it 3-4 years ago now i think
> and it just keeps working.
> 
> you call it this way:
> 
> # pagination.
> if(isset($_GET['pg'])) {
> $page = intval($_GET['pg']);
> } else {
> $page = 1;
> }
> $page = sprintf("%02d",$page);
> 
> $query = Array(
> 'query' => "SELECT foo FROM bar",
> 'itemsperpage'  => 50,
> 'maxdisplay'=> 20,
> 'linkprefix'=> "$_SERVER[PHP_SELF]?f=$forum_id&pg="
> );
> list($pages,$numpages,$items,$threads) = paginate_sql($page,$query);
> 
> $pages is the html formatted links
> $numpages is the total number of pages
> i dont actually use $items much but i think it just tells you how many
> items (which is the same as itemsperpage... i believe)
> $threads is the mysql rows resource (you can use mysql_fetch_rows on it)
> 
> 
> 
> function paginate_sql(&$thispage,$options) {
> $offset = $options['itemsperpage'] * ($thispage - 1);
> if(isset($options['server'])) {
> $results = db_query(eregi_replace("^SELECT","SELECT
> SQL_CALC_FOUND_ROWS",$options['query'])."LIMIT
> $offset,$options[itemsperpage]",$options['server']);
> $rows = db_query("SELECT FOUND_ROWS()",$options['server']);
> } else {
> $results = db_query(eregi_replace("^SELECT","SELECT
> SQL_CALC_FOUND_ROWS",$options['query'])."LIMIT
> $offset,$options[itemsperpage]");
> $rows = db_query("SELECT FOUND_ROWS()");
> }
> list($totalitems) = db_rows($rows);
> db_free($rows);
> $html = "";
> $numpages = ceil($totalitems / $options['itemsperpage']);
> if(isset($options['maxpages']) && $numpages >
> $options['maxpages']) { $numpages = $options['maxpages']; }
> if($thispage < 1 || $totalitems < $options['itemsperpage']) {
> $thispage = sprintf("%02d",1); }
> if($thispage > $numpages && $numpages > 0) {
> header(sprintf("Location: %s01",
> str_replace("&","&",$options['linkprefix'])));
> exit();
> }
> $start = (ceil($thispage / $options['maxdisplay'])-1) *
> $options['maxdisplay'] + 1;
> if($start == 1) {
> $html .= "«";
> } else {
> $html .= sprintf("«",
> $options['linkprefix'], $start-1);
> }
> if(isset($options['maxdisplay']) && $options['maxdisplay'] !=
> 0 && $numpages > $options['maxdisplay']) {
> $numlist = $options['maxdisplay'] + $start - 1;
> } else {
> $numlist = $numpages + $start - 1;
> }
> if($numlist > $numpages) { $numlist = $numpages; }
> for($x=$start; $x<=$numlist; $x++) {
> if($x == $thispage) {
> $html .= sprintf(" %02d", $x);
> } else {
> $html .= sprintf("  href=\"%s%02d\">%02d", $options['linkprefix'], $x, $x);
> }
> }
> if($numlist == $numpages) {
> $html .= " »";
> } else {
> $html .= sprintf(" »",
> $options['linkprefix'], $numlist+1);
> }
> if($totalitems <= $options['itemsperpage']) { $html = ""; }
> return Array($html,sprintf("%02d",$numpages),$totalitems,$results);
> }
> 
> On 9/13/07, Patrik Hasibuan <[EMAIL PROTECTED]> wrote:
> > Hi Mike,
> >
> > I am intrested for the solution you gave me. But I am confused of the way 
> > in implementing "select FOUND_ROWS()".
> >
> > I wrote another very simple codes as the first step for understanding this 
> > threat:
> >  > $konek=mysql_connect("127.0.0.1","root","mypassword");
> > if ($konek){
> >for ($i=0;$i<2;$i++){
> >$sqlku="select SQL_CALC_FOUND_ROWS id_iklan from lowongan limit 5;";
> >$sqlkupage="select FOUND_ROWS()";
> >$mybd=mysql_select_db("headhunter",$konek);
> >$kueri=mysql_query($sqlku,$konek) or die('MYSQL QUERY ERROR 
> > ['.mysql_errno($konek).'] '.mysql_error($konek));
> >$kueri=mysql_query($sqlkupage,$konek) or die('MYSQL QUERY ERROR 
> > ['.mysql_errno($konek).'] '.mysql_error($konek));
> >while($brs=mysql_fetch_row($kueri)){
> >list($idiklan)=$brs;
> >echo "FirstItem  > href=\"showit.php?id=$idiklan\">$idiklan";
> >}
> >}
> > }else{
> >echo "I can't talk to the server";
> >exit();
> > }
> > ?>
> >
> > I've put nine records into the table of "lowongan", idiklan 1 to 9.
> > Look I get of course only one record, namely the: '9'.
> >
> > This is the output of my codes in my internet browser.
> > ===
> > FirstItem 9
> > FirstItem 9
> > ===
> > The output what I am expecting suppose to be:
> > on the $i=0
> > "
> > FirstItem 1
> > FirstItem 2
> > FirstItem 3
> > FirstItem 4
> > F

RE: [PHP] Open New URL window

2007-09-19 Thread Andrew Prostko

Ok, so I started using the header code that was suggested:

And I get this error: 

Parse error: parse error, unexpected '{' in
/home/char-lee/public_html/beta/1.php on line 3

This is the code:
---

---

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