php-general Digest 17 Aug 2003 21:17:45 -0000 Issue 2242

Topics (messages 159831 through 159862):

first time using exec() - are getting parse error.
        159831 by: anders thoresson
        159832 by: Chris Hayes
        159836 by: John W. Holmes
        159838 by: anders thoresson

problem with sessions - IE working after session.use_trans_sid enabled.
        159833 by: anders thoresson

mod_php issues with security or stablility?
        159834 by: Lane Vance
        159844 by: Jason Sheets
        159845 by: Gerard Samuel
        159846 by: Wouter van Vliet

Any IMAP portal system
        159835 by: Dasmeet

Re: indexing a folder
        159837 by: John W. Holmes
        159843 by: Cadish
        159848 by: John W. Holmes

Re: Sessions
        159839 by: John W. Holmes
        159841 by: Wouter van Vliet

Re: substr ?
        159840 by: John W. Holmes

Re: How to connect to DB
        159842 by: Miles Thompson

Parsing HTTP_USER_AGENT
        159847 by: AzN
        159853 by: hAj

Re: Validate The Last Day of Month with server's clock????
        159849 by: Nicholas Robinson

Chris->Re: [PHP] Category and sub-category logic
        159850 by: Ryan A

mystical parse error message
        159851 by: oHmEr
        159852 by: Greg Beaver

Discussion: do you consider null a value or strictly a type?
        159854 by: Robert Cummings
        159861 by: Miles Thompson

Efficient structure
        159855 by: Info.Best-IT

Re: shell_exec
        159856 by: John

Semi-Newbie question about arrays
        159857 by: Gremillion

Nestled 'while's or 'for's or 'foreach's -- I'm lost
        159858 by: Verdon vaillancourt
        159859 by: David Otton
        159860 by: Petre Agenbag

Re: imagecreatefromjpeg() problems
        159862 by: J-K

Administrivia:

To subscribe to the digest, e-mail:
        [EMAIL PROTECTED]

To unsubscribe from the digest, e-mail:
        [EMAIL PROTECTED]

To post to the list, e-mail:
        [EMAIL PROTECTED]


----------------------------------------------------------------------
--- Begin Message --- Hi,

I'm trying to call mysqldump from within a php-script, like this:
$backuptime = date("ymdHi");
$backupfile = "un" . $backuptime . ".txt";
exec("mysqldump --opt -u$dbuser -p$dbpassword $dbdatabase $alltables > /web/un/backup/$backupfile");


It works fine on my local Win2k, php 4.3.1, but not on my ISP:s Sun Solaris/php 4.3.2 machine I get a parse error. What am I doing wrong?

Is there a better way to backup my database?

--
anders thoresson

--- End Message ---
--- Begin Message --- At 12:06 17-8-2003, you wrote:
Hi,

I'm trying to call mysqldump from within a php-script, like this:
$backuptime = date("ymdHi");
$backupfile = "un" . $backuptime . ".txt";
exec("mysqldump --opt -u$dbuser -p$dbpassword $dbdatabase $alltables > /web/un/backup/$backupfile");


It works fine on my local Win2k, php 4.3.1, but not on my ISP:s Sun Solaris/php 4.3.2 machine I get a parse error. What am I doing wrong?

Is there a better way to backup my database?

I made a script to use mysqldump (in my script the result is send as an email attachment, with a debug option so it tells you what may be wrong. In your case, it is possible that mysqldump is not in the path, or even absent. Read the comments in the script. It needs some time to set up, with all the paths and other settings.
http://www.hieris.info/over/backup/backup.php.txt



--- End Message ---
--- Begin Message --- anders thoresson wrote:
Hi,

I'm trying to call mysqldump from within a php-script, like this:
$backuptime = date("ymdHi");
$backupfile = "un" . $backuptime . ".txt";
exec("mysqldump --opt -u$dbuser -p$dbpassword $dbdatabase $alltables > /web/un/backup/$backupfile");


It works fine on my local Win2k, php 4.3.1, but not on my ISP:s Sun Solaris/php 4.3.2 machine I get a parse error. What am I doing wrong?

Is there a better way to backup my database?


What is the error you get? Print out the command you're trying to run to make sure it looks right. Remember that commands run as the web server user, so ensure that use has permission to run mysqldump. You may need to provide the complete path to mysqldump.


--
---John Holmes...

Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

PHP|Architect: A magazine for PHP Professionals - www.phparch.com





--- End Message ---
--- Begin Message ---
What is the error you get?

Problem solved: it was a combination of permissions and wrong options.


--
anders thoresson

--- End Message ---
--- Begin Message --- Hi,

I've had some problems with Internet Explorer not working on the site I'm building at the moment. At my local system it worked, but not on my ISP. After comparing the session settings, only use_trans_sid differed: enabled at my local system, disabled at remote.

Before I changed anything IE worked only when accessing the site at my local host, while Opera managed to access it both local and from my ISP. After enabling session.use_trans_sid in my .htaccess on my ISP, Internet Explorer can be used even there.

Ok. I've solved my problem, but don't really understand how session.use_trans_sid made the difference?

--
anders thoresson

--- End Message ---
--- Begin Message ---
Hello, 

I work for a large web hosting company and we currently use php.cgi. We are
considering changing to use mod_php. Is anyone aware of any security issues
with using mod_php? Are there any stability issues? Theoretically, could a
customer write php code that could crash Apache? Any other pros or cons to
mod_php vs. php.cgi? 

We have been using php as a cgi for many years and no one seems to remember
why we starting running it as a cgi rather than an Apache module. 

Thanks, Lane

--- End Message ---
--- Begin Message --- mod_php is the recommended installation for Apache. Thousands of people use mod_php with Apache. When I switched to mod_php from CGI I saw a significant performance increase, also you can not use things like Turck MMCache in CGI mode. In short not that I'm aware of, you might google for it but you should be fine. On cavaeat is with CGI PHP can execute as the owner of the script, with mod_php it executes as the web server.

Jason

Lane Vance wrote:

Hello,

I work for a large web hosting company and we currently use php.cgi. We are
considering changing to use mod_php. Is anyone aware of any security issues
with using mod_php? Are there any stability issues? Theoretically, could a
customer write php code that could crash Apache? Any other pros or cons to
mod_php vs. php.cgi?


We have been using php as a cgi for many years and no one seems to remember
why we starting running it as a cgi rather than an Apache module.


Thanks, Lane





--- End Message ---
--- Begin Message --- Jason Sheets wrote:

On cavaeat is with CGI PHP can execute as the owner of the script, with mod_php it executes as the web server.

IMHO, the biggest difference between the two as far as security is concerned in favour for CGI.



--- End Message ---
--- Begin Message ---
It's mostly just a wild guess .. but when I think about linking
php.cgi/mod_php question to Peda's one about sessions, and later being
unable to use php_value in a .htaccess file.. Is it likely that Peda's
server runs php.cgi instead of mod_php?

can somebody confirm this?

Wouter

-----Oorspronkelijk bericht-----
Van: Gerard Samuel [mailto:[EMAIL PROTECTED]
Verzonden: zondag 17 augustus 2003 17:35
Aan: Jason Sheets
CC: [EMAIL PROTECTED]; [EMAIL PROTECTED]
Onderwerp: Re: [PHP] mod_php issues with security or stablility?


Jason Sheets wrote:

> On cavaeat is with CGI PHP can execute as  the owner of the script,
> with mod_php it executes as the web server.

IMHO, the biggest difference between the two as far as security is
concerned in favour for CGI.


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



--- End Message ---
--- Begin Message --- Hi! Is there any PHP Portal system (scripts) that have IMAP/SMTP,
calendar, notebook and other utilities build in to it alongwith other general portal utilities? Any information would be of great help. Thanks
Dasmeet



-- Domainwala.com Domain Names from $7.99 at http://www.domainwala.com




--- End Message ---
--- Begin Message --- Cadish wrote:

How can i index a folder that's not on my server?

With indexing, i mean getting a list of all files in that folder...

http://us2.php.net/manual/en/ref.dir.php


--
---John Holmes...

Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

PHP|Architect: A magazine for PHP Professionals – www.phparch.com





--- End Message ---
--- Begin Message ---
Thanks, but is this also possible for directories not on my server?
Or can i just use these functions?

"John W. Holmes" <[EMAIL PROTECTED]> schreef in bericht
news:[EMAIL PROTECTED]
> Cadish wrote:
>
> > How can i index a folder that's not on my server?
> >
> > With indexing, i mean getting a list of all files in that folder...
>
> http://us2.php.net/manual/en/ref.dir.php
>
> --
> ---John Holmes...
>
> Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/
>
> PHP|Architect: A magazine for PHP Professionals – www.phparch.com
>
>
>
>



--- End Message ---
--- Begin Message --- Cadish wrote:
Thanks, but is this also possible for directories not on my server?
Or can i just use these functions?

Missed that bit, sorry. If the directory is not on your server, then you need to go through FTP.


--
---John Holmes...

Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

PHP|Architect: A magazine for PHP Professionals – www.phparch.com





--- End Message ---
--- Begin Message --- Peda wrote:

Thank you all for your help.

I solved the problem using
session_save_path("/some/dir/") in php script.

Just one thing to note: If you set the session save_path in your file using this method or ini_set, then there will not be any automatic garbage collection. You'll have to do that yourself.


But now I have another question.

Every time when I'm using .htaccess file and try to connect to my site I get
this message:
Internal Server Error
The server encountered an internal error or misconfiguration and was unable
to complete your request.
Please contact the server administrator, and inform them of the time the
error occurred, and anything you might have done that may have caused the
error.

More information about this error may be available in the server error log.


Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.

When I put in .htaccess file:

php_value session.save_path "/full/path/to/your/own/tmp/directory"

as you told me, I get the same message and in my error_log I get this
message:
[Sun Aug 17 12:31:42 2003] [alert] [client 213.240.5.14]
/home2/pena/public_html/.htaccess: Invalid command 'php_value', perhaps
mis-spelled or defined by a module not included in the server configuration

Looks like your ISP will not allow you to set php values in an .htaccess file.


--
---John Holmes...

Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

PHP|Architect: A magazine for PHP Professionals – www.phparch.com





--- End Message ---
--- Begin Message ---
well .. that's odd. I use the same directive multiple times without any
problems. The error tells that it thinks the php module which should provide
this directive is not available. Odd thing is that you can run PHP scripts,
so the PHP module is loaded .. so to speak.

Somebody got a clue on this one? Maybe php was compiled without support for
this directive .. or smth?

Wouter

-----Oorspronkelijk bericht-----
Van: Peda [mailto:[EMAIL PROTECTED]
Verzonden: zondag 17 augustus 2003 8:57
Aan: [EMAIL PROTECTED]
Onderwerp: Re: [PHP] Sessions


Thank you all for your help.

I solved the problem using
session_save_path("/some/dir/") in php script.

But now I have another question.

Every time when I'm using .htaccess file and try to connect to my site I get
this message:
Internal Server Error
The server encountered an internal error or misconfiguration and was unable
to complete your request.
Please contact the server administrator, and inform them of the time the
error occurred, and anything you might have done that may have caused the
error.

More information about this error may be available in the server error log.


Additionally, a 500 Internal Server Error error was encountered while trying
to use an ErrorDocument to handle the request.

When I put in .htaccess file:

php_value session.save_path "/full/path/to/your/own/tmp/directory"

as you told me, I get the same message and in my error_log I get this
message:
[Sun Aug 17 12:31:42 2003] [alert] [client 213.240.5.14]
/home2/pena/public_html/.htaccess: Invalid command 'php_value', perhaps
mis-spelled or defined by a module not included in the server configuration

Thank you again!







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



--- End Message ---
--- Begin Message --- John Taylor-Johnston wrote:

Sorry, scrap that:

if (substr_count($mystring,"¶") >0)

John Taylor-Johnston wrote:


How can I find out if $mystring includes the character "¶"?
Thought substr would do it?
J

strpos() would be better...


--
---John Holmes...

Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

PHP|Architect: A magazine for PHP Professionals – www.phparch.com





--- End Message ---
--- Begin Message ---
Take out the "@" so you can see what error is returned.


Echo your defines to confirm that you are getting what you expect.

Double check that you have the browser set to refresh on every call to a page.

Clear your cache.

Use the header() function to add code at the top of the page to force a refresh.

HTH - Miles

At 04:42 PM 8/16/2003 +0530, murugesan wrote:
Hello all,
        I have some existing php pages already. Now I want to change the DB
to point to another DB.

I have changed the include_path in php.ini file to point to /home/config
Also I changed the constant db_name defined in a file in
/home/config/con.php to point to new DB.

[snip]
<<<<<<<<<
include "con.php"
@mysql_pconnect(db_host,db_user,db_pass);
mysql_select_db (db_name) or die ("could not select db");
<<<<<<<<<<

<<<<<<<<<<<<<<<<<
//contents of con.php

<?php
  define('db_host','localhost');
  define('db_name','newdb') ;
  define('db_user','scott') ;
  define('db_pass','tiger') ;
  define('db_type','mysql') ;
 ?>


<<<<<<<<<<<<<< Also I restarted the apache. But it is still accessing the old DB. What are all the changes that I have to make. other than these changes.

Regards,
Murugesan.


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


--- End Message ---
--- Begin Message ---
Hello:

What I'm trying to do is parse the HTTP_USER_AGENT into formatted text.
Here's an example:

    PHP gets user's browser and OS through with HTTP_USER_AGENT.
    The output should only say: You are running on Windows XP and using IE6!

How would I parse this. One example would be fine. I know I have to do it
for every possibility, right?
Is there a way for me to do it so that, it only outputs the major browsers
such as Mozilla, Opera, Netscape or IE?

Also, what would I do to parse the OS?

Finally, here is the project I'm working on:
http://members.lycos.co.uk/xtrinity/golucky/image.php

I'm trying to make it like Vipersig:
http://www.danasoft.com/vipersig.jpg

Thanks!



--- End Message ---
--- Begin Message ---
Greetinx,

on 2003.08.17 07:29, AzN at [EMAIL PROTECTED] wrote:

> http://www.danasoft.com/vipersig.jpg
> 
Says "I know kung fu.", haha. Strikes me that I'm mistakenly located
somewhere in China instead of Japan. ;P


hAj <http://advancedmeta-metaphorofapagan.net>
||||
|||
|||
||
||
||
||
Seij minus aÇ <http://seijminusac.net>
   = '(music of) a negative scalar dimension w/in desolate silence'
|
|
|
|
|
|
|
gene of Cube <http://geneofcube.net>



--- End Message ---
--- Begin Message ---
And the reason I quoted 'usual' is that my suggestion is more portable.

On Thursday 14 Aug 2003 11:54 am, Ford, Mike [LSS] wrote:
> On 13 August 2003 20:05, Nicholas Robinson wrote:
> > On Wednesday 13 Aug 2003 8:00 pm, Scott Fletcher wrote:
> > > Hi!
> > >
> > >     Here's a trick script.  We know that some months have the last
> > > day which is 30 while other is 31.  As for February, it can be
> > >  either 28 or 29. So, what's the trick in using the php to find out
> > > what is the last day of the month if you want to checked it against
> > > the server's clock to find out the last day of the month.  Suppose
> > > it is this month or 3 months ago or 3 months from now.  Anyone know?
> >
> > The 'usual' trick is to set the date to the first day of the month
> > after the one you want and then subtract one day.
>
> Actually, the "usual" trick is to ask mktime() for the 0th day of the
> following month.  One of the examples on the mktime() page of the manual
> (http://www.php.net/mktime) even illustrates exactly this.
>
> Cheers!
>
> Mike
>
> ---------------------------------------------------------------------
> Mike Ford,  Electronic Information Services Adviser,
> Learning Support Services, Learning & Information Services,
> JG125, James Graham Building, Leeds Metropolitan University,
> Beckett Park, LEEDS,  LS6 3QS,  United Kingdom
> Email: [EMAIL PROTECTED]
> Tel: +44 113 283 2600 extn 4730      Fax:  +44 113 283 3211


--- End Message ---
--- Begin Message ---
Hey,
Sorry I didnt reply, was having some computer problems.
Thanks for the link and the advise, will look into it.
Cheers,
-Ryan


We will slaughter you all! - The Iraqi (Dis)information ministers site
http://MrSahaf.com


----- Original Message ----- 
From: "Chris W. Parker" <[EMAIL PROTECTED]>
To: "David Otton" <[EMAIL PROTECTED]>; "Ryan A"
<[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Friday, August 15, 2003 2:04 AM
Subject: RE: [PHP] Category and sub-category logic


> David Otton <mailto:[EMAIL PROTECTED]>
>     on Thursday, August 14, 2003 4:58 PM said:
>
> > The advantage of doing it this way is that your tree structure is
> > generic and can have many levels. The disadvantage is that you may
> > need many SQL queries to fully traverse the tree (though people
> > rarely want to do this, and sub-selects, clever joins or post-query
> > processing can reduce the overhead).
>
> Which is why you should use the Modified Preorder Tree Traversal method
> instead. With that method you've got one table that defines the
> categories AND their relationships to each other.
>
> Your SQL queries end up looking something like this.
>
> SELECT name
> FROM categories
> WHERE lft >= x
> AND rgt <= y
>
>
>
> Chris.
>
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


--- End Message ---
--- Begin Message ---
does someone know wtf this message means ?

Parse error: parse error, unexpected T_PAAMAYIM_NEKUDOTAYIM

i hope my fbsd box isnt haunted or controled by a daemon...



--- End Message ---
--- Begin Message --- Hi Ohmer,

T_PAAMAYIM_NEKUDOTAYIM is the incomprehensible name given to the :: operator. However, if you use the tokenizer extension like so:

<?php
$a = '<?php name::thing() ?>';
$b = token_get_all($a);
echo(token_name($b[3][0]));
?>

You'll see T_DOUBLE_COLON - a much more descriptive name :).

So, look for an accidental double colon, perhaps in a case statement

switch (blah) {
    case something ::

}

Regards,
Greg

Ohmer wrote:

does someone know wtf this message means ?

Parse error: parse error, unexpected T_PAAMAYIM_NEKUDOTAYIM

i hope my fbsd box isnt haunted or controled by a daemon...




--- End Message ---
--- Begin Message ---
There has been a recent thread on the internals list as to the meaning
and usage of the "null" datatype. Zeev claims, perhaps rightly so, the
following:

Zeev wrote:
>
> null is not a value, was never meant to be a value, and won't be a
> value

Interestingly though, the PHP documentation at

    http://www.php.net/manual/en/language.types.null.php

indicates the following:

    The special NULL value represents that a variable has no value. NULL
    is the only possible value of type NULL. 

Which is obviously contradictory since it claims to be a variable having
no value and yet also claims it is a special value. Also the following
snippet from: 

    http://www.php.net/manual/en/language.operators.assignment.php

seems to also indicate that null is a value -- namely:

    The basic assignment operator is "=". Your first inclination might
    be to think of this as "equal to". Don't. It really means that the
    the left operand gets set to the value of the expression on the
    rights (that is, "gets set to"). 

The above reference might not be obvious, but since you can assign the
null constant, then it says the "left operand gets set to the value
of..." seemingly indicating that null is a value.

Now the point of the discussion is not to indicate who is right or who
is wrong -- that would appear to be a ridiculous argument. I am more
interested in finding out the practices and experience of PHP
developers. I'd like to know how many people treat null as a value, and
how many do not. For instance to you ever assign default values of null
to instance variables, or local variable, or array entries? I know in
practice that I have, and find it quite convenient to represent a
default value.

Cheers,
Rob.
-- 
.---------------------------------------------.
| Worlds of Carnage - http://www.wocmud.org   |
:---------------------------------------------:
| Come visit a world of myth and legend where |
| fantastical creatures come to life and the  |
| stuff of nightmares grasp for your soul.    |
`---------------------------------------------'

--- End Message ---
--- Begin Message --- At 03:20 PM 8/17/2003 -0400, Robert Cummings wrote:
There has been a recent thread on the internals list as to the meaning
and usage of the "null" datatype. Zeev claims, perhaps rightly so, the
following:

Zeev wrote:
>
> null is not a value, was never meant to be a value, and won't be a
> value

Interestingly though, the PHP documentation at

http://www.php.net/manual/en/language.types.null.php

indicates the following:

    The special NULL value represents that a variable has no value. NULL
    is the only possible value of type NULL.

Which is obviously contradictory since it claims to be a variable having
no value and yet also claims it is a special value. Also the following
snippet from:

http://www.php.net/manual/en/language.operators.assignment.php

seems to also indicate that null is a value -- namely:

    The basic assignment operator is "=". Your first inclination might
    be to think of this as "equal to". Don't. It really means that the
    the left operand gets set to the value of the expression on the
    rights (that is, "gets set to").

The above reference might not be obvious, but since you can assign the
null constant, then it says the "left operand gets set to the value
of..." seemingly indicating that null is a value.

Now the point of the discussion is not to indicate who is right or who
is wrong -- that would appear to be a ridiculous argument. I am more
interested in finding out the practices and experience of PHP
developers. I'd like to know how many people treat null as a value, and
how many do not. For instance to you ever assign default values of null
to instance variables, or local variable, or array entries? I know in
practice that I have, and find it quite convenient to represent a
default value.

Cheers,
Rob.
--

Year's ago I was told that NULL means "Don't know", and to take it a little further, one could argue that it represents the state of a variable, rather than its contents. Once a concrete value has been assigned, even if it is a space or a zero, the state of the variable is no longer NULL.


I also think, in discussing NULLs, that we hit a limit of language - we have to refer to this "not knowness" as something. Thus a variable set to NULL is not like an empty bucket, more like a bucket with potential, but if you examine it reveals not " " 's, or 0's, but a benign vacuum.

This is not a value, but it is a convenient shorthand to refer to it as such.

Now, shall we discuss imaginary numbers?

Cheers - Miles


--- End Message ---
--- Begin Message ---
I have multiple types of information to associate to one object.  I have
data structures that store data structures.  What is the best/most efficient
way to structure the data?  A multi-dimensional array?  A container object?

Please Advise...

/T

  


--- End Message ---
--- Begin Message ---
All I want to do is execute a perl script. I do not care about output to
browser. I have used shell_exec, system, exec, and backticks with no
avail.

Here is what i have now in my php page.
shell_exec("perl data/addSite.pl" . " &> /tmp/error " );

I know the perl script executes because a basic print statement in the
perl script is outputted to /tmp/error. However anything else in the
script not having to do with output is not executed. The perl script is
basically supposed to add a file. That is it. The perl script is fine
from command line. All paths are correct and like I said I do not care
about output to the browser for the user. My questions is why does the
perl script execute (and mostly work) but not execute certain pieces of
code when executed from my php page.


--- End Message ---
--- Begin Message --- I'm trying to create a multidimensional array of values to update a Filemaker db. Edits to existing fields end in numbers (the record ID).I'm having a problem, probably obvious to anyone here in setting up the multidimensional array:

$updateEntries = array(); //stores existing db entries
$ord = -1;
$recNum = 0;
foreach ($_POST as $key => $value) {
if ($value != "") {
$lastPartPos = strrchr($key, '_');
$lastPart = substr($lastPartPos, 1);
if (preg_match("/[0-9]+/" , $lastPart)) { //if it's an existing update
$lastpartnum = strrpos($key, '_');
$firstnum = substr($key, 0, $lastpartnum);
$first = str_replace('_', '.', $firstnum); //restore periods to field name and strip off record ID at end
if ($lastPart != $recNum) {
$recNum = $lastPart;
$ord++;
$updateEntries[$ord] = $recNum;
}
$updateEntries[$ord][] = array($first, $value); //populate nested arrays of each entry
etc......


throws:
"PHP Fatal error:  [] operator not supported for strings"

How do I make $updateEntries[$ord] evaluate as an array?

Thanks in advance

RG



--- End Message ---
--- Begin Message ---
Hi, somewhat newbie warning :)

I'm trying to take a paged result set and divide it into two chunks for
displaying on the page. Basically making something that looks like a typical
thumbnail gallery. I'm limiting my result set to 6 records and want to
display it as 2 rows of 3 cells with a record in each cell. I've had no
trouble getting my result set, paging etc. I'm not having much luck
splitting my result into 2 chunks. I've tried nestling 'while' statements
with a number of arguments and either end up with no results or a loop that
seemingly never ends. That lead me to looking at some other apps which
seemed to use a variety of ways to achieve what I want. That lead me to
looking at 'for' and 'foreach' in the php manual. And that lead me to being
more confused than I was before I started ;) Sometimes there's just too many
ways to skin a cat, eh!

Below, I've include a rather lengthy bit of pseudo code that represents
basically where I'm at now. This particular version returns no results,
though I know it's just the nestled while's that are causing this. The
results are there. My research makes me think that I should replace the
nestled while's with 'foreach's. I was kind of hoping that before I spend a
few hours trying to puzzle out how to use the 'foreach's correctly that
somebody would venture an opinion as to whether or not that would be the way
to go.

Thanks in advance for any advice,
Verdon

-- pseudo code --

<?php

$limitPerPage = 6 ;
$initStartLimit = 0;

if (!isset( $startLimit )) {
    $startLimit = $initStartLimit ;
    }

$querylimit = " limit $startLimit,$limitPerPage " ;
$nextStartLimit = $startLimit + $limitPerPage ;
$previousStartLimit = $startLimit - $limitPerPage ;

if ( $sortby != "" ) {
    $sorted = " order by $sortby " ;
    }

$bareQuery = "select * from pieces order by rank";
$queryall = $bareQuery .$sorted .$querylimit;
$resultall = mysql_query ($queryall);
$numberall = mysql_numrows ($resultall);

if ( $numberall == 0) {
    echo "No Records Found !" ;
    } else if ( $numberall > 0) {

    $x = 0;

    echo "<h2>Page of Pieces</h2>";
    
    while ( $x < $numberall ) {
         
        // Retreiving data and putting it in local variables for each row
        $id = mysql_result ($resultall ,$x ,"id");
        $title = mysql_result ($resultall ,$x ,"title");
        $description = mysql_result ($resultall ,$x ,"description");
        $thumb = mysql_result ($resultall ,$x ,"thumb");
        $company = mysql_result ($resultall ,$x ,"company");

        echo "<table cellspacing=\"0\">";
        echo "<tr>";
    
            while ($x >= 0 && $x < 4)
            {    
        
                echo "<td>";
                if ($thumb) {
                    echo "thumbnail with a link";
                    } else {
                    echo "text with a link";
                    }
                echo "<br /><strong>$title</strong>";
                echo "<br />$company";
                echo "<br />$description";
                echo "</td>";
                $x ++;
            }

            echo "</tr>";
            echo "<tr>";

            while ($x > 3 && $x < $numberall)
            {    
        
                echo "<td>";
                if ($thumb) {
                    echo "thumbnail with a link";
                    } else {
                    echo "text with a link";
                    }
                echo "<br /><strong>$title</strong>";
                echo "<br />$company";
                echo "<br />$description";
                echo "</td>";
                $x ++;
            }

            echo "</tr>";
            echo "</table>";
    
            $x ++; 
        } // end while
    echo "</table><br />";
    
    echo "<div class=\"footLinks\">";
    echo "Previous links";
    echo "Next links";
    echo "</div>";

}// end if numberall > 0

?>


--- End Message ---
--- Begin Message ---
On Sun, 17 Aug 2003 15:47:04 -0400, you wrote:

>I'm trying to take a paged result set and divide it into two chunks for
>displaying on the page. Basically making something that looks like a typical
>thumbnail gallery. I'm limiting my result set to 6 records and want to
>display it as 2 rows of 3 cells with a record in each cell. I've had no
>trouble getting my result set, paging etc. I'm not having much luck
>splitting my result into 2 chunks. I've tried nestling 'while' statements
>with a number of arguments and either end up with no results or a loop that
>seemingly never ends. That lead me to looking at some other apps which
>seemed to use a variety of ways to achieve what I want. That lead me to
>looking at 'for' and 'foreach' in the php manual. And that lead me to being
>more confused than I was before I started ;) Sometimes there's just too many
>ways to skin a cat, eh!
>
>Below, I've include a rather lengthy bit of pseudo code that represents
>basically where I'm at now. This particular version returns no results,
>though I know it's just the nestled while's that are causing this. The
>results are there. My research makes me think that I should replace the
>nestled while's with 'foreach's. I was kind of hoping that before I spend a
>few hours trying to puzzle out how to use the 'foreach's correctly that
>somebody would venture an opinion as to whether or not that would be the way
>to go.

$data = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H');
$rowlength = 3;

echo ("<table>");
for ($i = 0; $i < sizeof ($data); $i += $rowlength)
{
        echo ("<tr>");
        for ($j = 0; $j < $rowlength; $j++)
        {
                if (isset ($data[$i+$j]))
                {
                        echo ("<td>{$data[$i+$j]}</td>");
                } else {
                        echo ("<td>&nbsp;</td>");
                }
        }
        echo ("</tr>");
}
echo ("</table>");


--- End Message ---
--- Begin Message ---
OK, Difficult to see from your pseudo code EXACTLY what it is that you
want to do, but I'll take a stab anyway...

Firstly, instead of using your elaborate ways of running through the
result set and extracting the variables, use something like this:

$sql = "whatever";
$result = mysql_query($sql);

echo '<table><tr><td>ID</td>...</tr>

        while ($myrow = mysql_fetch_assoc($result)) {
                extract($myrow);
                //or $id = $myrow[id]; etc.
                ...
                //construct your table here
                echo '<tr><td>'.$id.'</td>...</tr>';
                ...
        }
echo '</table>';


You must also remember that in cases where you do "limit" queries, and
want to "continue" on the next page, you must remember that your result
will NOT contain the "next" page's data. You will need to do another
query with the new "limit" data. It *looks* like this is what you are in
fact attempting in your code, just making sure...

In your case, I would say the easiest is to call the page onto itself.
Ie, your first query will be 
$sql = "whatever limit 0,6";

it will return the (maximum) 6 rows and then, on your "next" link you
should include the data for the next query. Ie, create a link like this:

<a href="same_page.php?limit=x&start=y">Next</a>

Meaning that you call up the same page that you used to display the
first query results, but you pass it different values for the start and
limit numbers in the query ( x,y ).

To recap, one of you biggest mistakes in the pseudo code below is that
you open a the <table> inside the while and close it as well (which is
fine if you want to create a table for each row you display , BUT, you
close the table again AFTER the while, that *could* cause the HTML to
freak out. So, the reason your app is not working is probably not PHP
related, but related to the fact that you are creating erroneous HTML
with your PHP. The pseudo code you are using *should* work, although, as
I stated above, there are easier and more efficient ways of doing the
same thing as per my example...





-----Original Message-----
From: Verdon vaillancourt [mailto:[EMAIL PROTECTED] 
Sent: Sunday, August 17, 2003 9:47 PM
To: 'PHP-General'
Subject: [PHP] Nestled 'while's or 'for's or 'foreach's -- I'm lost

Hi, somewhat newbie warning :)

I'm trying to take a paged result set and divide it into two chunks for
displaying on the page. Basically making something that looks like a
typical
thumbnail gallery. I'm limiting my result set to 6 records and want to
display it as 2 rows of 3 cells with a record in each cell. I've had no
trouble getting my result set, paging etc. I'm not having much luck
splitting my result into 2 chunks. I've tried nestling 'while'
statements
with a number of arguments and either end up with no results or a loop
that
seemingly never ends. That lead me to looking at some other apps which
seemed to use a variety of ways to achieve what I want. That lead me to
looking at 'for' and 'foreach' in the php manual. And that lead me to
being
more confused than I was before I started ;) Sometimes there's just too
many
ways to skin a cat, eh!

Below, I've include a rather lengthy bit of pseudo code that represents
basically where I'm at now. This particular version returns no results,
though I know it's just the nestled while's that are causing this. The
results are there. My research makes me think that I should replace the
nestled while's with 'foreach's. I was kind of hoping that before I
spend a
few hours trying to puzzle out how to use the 'foreach's correctly that
somebody would venture an opinion as to whether or not that would be the
way
to go.

Thanks in advance for any advice,
Verdon

-- pseudo code --

<?php

$limitPerPage = 6 ;
$initStartLimit = 0;

if (!isset( $startLimit )) {
    $startLimit = $initStartLimit ;
    }

$querylimit = " limit $startLimit,$limitPerPage " ;
$nextStartLimit = $startLimit + $limitPerPage ;
$previousStartLimit = $startLimit - $limitPerPage ;

if ( $sortby != "" ) {
    $sorted = " order by $sortby " ;
    }

$bareQuery = "select * from pieces order by rank";
$queryall = $bareQuery .$sorted .$querylimit;
$resultall = mysql_query ($queryall);
$numberall = mysql_numrows ($resultall);

if ( $numberall == 0) {
    echo "No Records Found !" ;
    } else if ( $numberall > 0) {

    $x = 0;

    echo "<h2>Page of Pieces</h2>";
    
    while ( $x < $numberall ) {
         
        // Retreiving data and putting it in local variables for each
row
        $id = mysql_result ($resultall ,$x ,"id");
        $title = mysql_result ($resultall ,$x ,"title");
        $description = mysql_result ($resultall ,$x ,"description");
        $thumb = mysql_result ($resultall ,$x ,"thumb");
        $company = mysql_result ($resultall ,$x ,"company");

        echo "<table cellspacing=\"0\">";
        echo "<tr>";
    
            while ($x >= 0 && $x < 4)
            {    
        
                echo "<td>";
                if ($thumb) {
                    echo "thumbnail with a link";
                    } else {
                    echo "text with a link";
                    }
                echo "<br /><strong>$title</strong>";
                echo "<br />$company";
                echo "<br />$description";
                echo "</td>";
                $x ++;
            }

            echo "</tr>";
            echo "<tr>";

            while ($x > 3 && $x < $numberall)
            {    
        
                echo "<td>";
                if ($thumb) {
                    echo "thumbnail with a link";
                    } else {
                    echo "text with a link";
                    }
                echo "<br /><strong>$title</strong>";
                echo "<br />$company";
                echo "<br />$description";
                echo "</td>";
                $x ++;
            }

            echo "</tr>";
            echo "</table>";
    
            $x ++; 
        } // end while
    echo "</table><br />";
    
    echo "<div class=\"footLinks\">";
    echo "Previous links";
    echo "Next links";
    echo "</div>";

}// end if numberall > 0

?>


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




--- End Message ---
--- Begin Message ---
Hi Jaap!

Thanks for your answer, but I checked phpinfo() and it says: JPG Support
Enabled
Any ideas?

The images are photo-like so png would make them too big.

Best regards
Jan-Kristian Markiewicz


"Jaap Van Ganswijk" <[EMAIL PROTECTED]> skrev i melding
news:[EMAIL PROTECTED]
> At 2003-08-16 14:35 +0200, J-K wrote:
> >I've made a little script to make thumbnails which worked before the
> >summer, but now I get this errormessage:
> >
> ><b>Fatal error</b>:  Call to undefined function:
> >imagecreatefromjpeg() in
> ><b>/usr/local/others/www.stud.users/mark/gfx/create_tn.php</b> on line
> ><b>15</b>
> >
> >First I thought they had done something with the servers, because I
> >haven't touched the code. But I checked the GD-version and got this:
> >      GD Version: bundled (2.0.12 compatible)
> >
> >      Shouldn't version 2.0.12 support imagecreatefromjpeg()?
>
> Only when jpeg support has been compiled into
> the PHP version that is running on your system.
> It doesn't seem to be.
>
> >Is there any way I can get around this?
>
> Try if png support is enabled. But you'd have
> to convert your jpeg's I guess and png's are
> probably much bigger because they are
> non-lossy (?). But it depends on your images
> being photo-like and not drawing-like.
>
> Otherwise you'll have to ask your system
> manager to fix the problem.
>
> BTW. you shouldn't indent paragraphs in emails,
> because it makes quoting them very messy, or
> the person answering your mail has to edit out
> the indentations (as I have done above).
>
> Greetings,
> Jaap
>



--- End Message ---

Reply via email to