php-general Digest 16 Jun 2002 07:50:42 -0000 Issue 1408

Topics (messages 102359 through 102382):

Re: Parsing Text File
        102359 by: Nathan Taylor
        102360 by: Stuart Dallas
        102372 by: Analysis & Solutions

PHP LICENCE
        102361 by: Kevin Waterson

printf()
        102362 by: Gerard Samuel
        102364 by: Danny Shepherd
        102365 by: Gerard Samuel
        102367 by: Danny Shepherd

Determine week
        102363 by: Rosen
        102370 by: John Holmes

Sharing form information
        102366 by: Frank Kicenko
        102368 by: Justin French

Re: Regular expression newbie question, convert this: [::word1 \" word2 \" word3::] to 
: ".word1 " word2 " word3."
        102369 by: Analysis & Solutions
        102380 by: Lance

Re: row pointer
        102371 by: Analysis & Solutions

Passing value between 2 Flash movies
        102373 by: J0s

Re: Apache/2.0.36 + Win98 + PHP4=Error(31)
        102374 by: PHPGeek
        102379 by: Prachait Saxena

Re: Can I use a template with this site?
        102375 by: César Aracena

Re: Can't set a cookie? [SOLVED]
        102376 by: C

Code Structure/Errors
        102377 by: Jason Soza
        102378 by: Pushkar Pradhan
        102381 by: Dan Koken
        102382 by: Jason Soza

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 ---
This is all really straight forward stuff.  Here's some code that will get the file 
parsed to an array, what you do from there is up to you.

<?php

$open =  fopen("file.txt","r+");

while($contents = fgets($open)) {
$line_array[$x] = $contents;
$x++;
}

?>

Note: if you have a precise structure for your lines you can say to read from point a 
to b using substr().  For example, let's say the first name is exactly 3 characters in 
from 0  and exactly 10 characters long so you could do substr($line_array[0], 3, 10);  
This is a really dirty way to handle this and I'm sure there are better ways so poke 
around a bit.  Also if you have your phone number located down to a specific location 
you can use an explode statement to get both area code and main number seperated.


----- Original Message -----
From: Jason D. Williard
Sent: Saturday, June 15, 2002 1:28 PM
To: [EMAIL PROTECTED]
Subject: [PHP] Parsing Text File

I am trying to input data from a text file into a MySQL database and would
like to be able to input the data using a single script.  What's the easiest
way to parse a line, such as below, and turn it into variables to be placed
in the database.  While I can simply place the data in by importing from a
file, it's not quite so easy.  I only need to place some of the data in,
plus I would like to split one of the fields.  Below is an example of a line
from the file, and then the variables that I need to enter.

Here is an example of a line from the file:
Number,City,State,Country,Provider,Isdn,56K,CreateDate,Active,Timezone,ModDa
te,ModNote
403 -770 -4904 ,CALGARY,AB,CAN,T2,Y,Y,Apr 29 2002
12:00:00:000AM,I,GMT-0700,,

As for variables, I need the following:
Split Number into $AreaCode & $Number > 403 & 770-4904
$City
$State
$Country

Thanks for any help.

Jason D. Williard





--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.phpGet more from the Web.  FREE MSN 
Explorer download : http://explorer.msn.com
--- End Message ---
--- Begin Message ---
On Saturday, June 15, 2002 at 9:05:40 PM, Nathan Taylor wrote:
> <?php

> $open =  fopen("file.txt","r+");

> while($contents = fgets($open)) {
> $line_array[$x] = $contents;
> $x++;
> }

?>>

This wheel exists: http://www.php.net/file

<?php
     $line_array = file('file.txt');
?>

-- 
Stuart

--- End Message ---
--- Begin Message ---
> 403 -770 -4904 ,CALGARY,AB,CAN,T2,Y,Y,Apr 29 2002
> 12:00:00:000AM,I,GMT-0700,,

Untested, off the top of my head, code...

$pointer = fopen('./file.csv', 'r');

while ( $Data = fgetcsv($pointer, 500) ) {
   # Do what you need, for example...
   echo 'Their city is: ' . $Data[1];
}

--Dan

-- 
               PHP classes that make web design easier
        SQL Solution  |   Layout Solution   |  Form Solution
    sqlsolution.info  | layoutsolution.info |  formsolution.info
 T H E   A N A L Y S I S   A N D   S O L U T I O N S   C O M P A N Y
 4015 7 Av #4AJ, Brooklyn NY     v: 718-854-0335     f: 718-854-0409
--- End Message ---
--- Begin Message ---
Just how much can the php name be used in applications?

The license says....
  3. The name "PHP" must not be used to endorse or promote products
     derived from this software without prior permission from the
     PHP Group.  This does not apply to add-on libraries or tools
     that work in conjunction with PHP.  In such a case the PHP
     name may be used to indicate that the product supports PHP.

So, we have applications such as phpnuke etc that use the php name
quite freely. Is this ok, or is it a breach of the license?

Can I call my application (written in php) phpAppName??

Is this descriptive that it supports php or is it using the php
name to promote the application??

I would really like some clarity on this.

Kind regards
Kevin
--- End Message ---
--- Begin Message ---
Im trying to make a dynamic printf().
By that I mean ->

function this($foo, $bar)
{
    if (strlen($bar) == '0')
    {
         print($foo);
    }
    else
    {
        printf($foo, $bar);
    }
}

Now it works if there is one argument passed, but it doesn't when there 
is more than one.

$str = 'should';
this('This %s work', $str);  // work

$str = 'is, a';
this('This %s just %s test', $str);  // doesn't work

So I guess, arguments passed to it has to be physical arguments, and not 
represented in a string.
Am I banging my head on a wall with this??
Thanks

-- 
Gerard Samuel
http://www.trini0.org:81/
http://dev.trini0.org:81/


--- End Message ---
--- Begin Message ---
On Sunday 16 June 2002 12:46 am, Gerard Samuel wrote:
> Im trying to make a dynamic printf().
> By that I mean ->
>
> function this($foo, $bar)
> {
>     if (strlen($bar) == '0')
>     {
>          print($foo);
>     }
>     else
>     {
>         printf($foo, $bar);
>     }
> }
>
> Now it works if there is one argument passed, but it doesn't when there
> is more than one.
>
> $str = 'should';
> this('This %s work', $str);  // work
>
> $str = 'is, a';
> this('This %s just %s test', $str);  // doesn't work
>
> So I guess, arguments passed to it has to be physical arguments, and not
> represented in a string.
> Am I banging my head on a wall with this??
> Thanks

Try this :

<?php

function this($string,$params="")
{
        if ($params!="")
        {
                eval("printf(\$string,$params);");
        }
        else
                print $string;

        return;
}

this('Hello, World :)<br />');
this('Hello %s<br />','"World"');
this('Hello %s %s<br />','"Wide", "World"');

?>
--- End Message ---
--- Begin Message ---
Well I figured out a solution.  Using a combination of explode() to 
create an array from $bar,
check to see if $bar is an array and
feed the array to vprintf()....

Gerard Samuel wrote:

> Im trying to make a dynamic printf().
> By that I mean ->
>
> function this($foo, $bar)
> {
>    if (strlen($bar) == '0')
>    {
>         print($foo);
>    }
>    else
>    {
>        printf($foo, $bar);
>    }
> }
>
> Now it works if there is one argument passed, but it doesn't when 
> there is more than one.
>
> $str = 'should';
> this('This %s work', $str);  // work
>
> $str = 'is, a';
> this('This %s just %s test', $str);  // doesn't work
>
> So I guess, arguments passed to it has to be physical arguments, and 
> not represented in a string.
> Am I banging my head on a wall with this??
> Thanks
>

-- 
Gerard Samuel
http://www.trini0.org:81/
http://dev.trini0.org:81/



--- End Message ---
--- Begin Message ---
On Sunday 16 June 2002 1:13 am, Gerard Samuel wrote:

> check to see if $bar is an array and
> feed the array to vprintf()....

Wow, didn't even know that one existed! Might come in handy though :)

Danny.
--- End Message ---
--- Begin Message ---
Hi,
how can I determine dates (start & end ) in one week.
I.e. 30th  week is between 22.07.2002 and 28.07.2002 .




--- End Message ---
--- Begin Message ---
You'll need a combination of date() and mktime().

I'm too lazy to write the exact code right now, but date('w') will
return the day of the week, 0 = Sunday, 6 = Saturday. Then use mktime()
to subtract the number returned from date('w') from the days component,
and you'll have the start of the week. 6 minus the result of date('w'),
added to the day component of mktime(), will give you the end...

HTH,
---John Holmes...


> -----Original Message-----
> From: Rosen [mailto:[EMAIL PROTECTED]]
> Sent: Saturday, June 15, 2002 7:55 PM
> To: [EMAIL PROTECTED]
> Subject: [PHP] Determine week
> 
> Hi,
> how can I determine dates (start & end ) in one week.
> I.e. 30th  week is between 22.07.2002 and 28.07.2002 .
> 
> 
> 
> 
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php


--- End Message ---
--- Begin Message ---
Hi,
Hopefully I didn't send this to the wrong list...:-)
 
I have a couple of questions if you don't mind... the PHP
help files seem to be very vague with respect to html issues.

Questions: How can I get the "selected" info from a selectbox that is in
another form on the same page... I've tried everything I know to be able to
get this. For instance, if a selectbox is part of $f1 and I'm submitting
using $f2, how can I get the selection from the $f1 selectbox and use it in
my $f2?

Also, how can I insert a "textbox" or other items into a cell? The
input_text belongs to $f2 and I need to insert it into a cell. for example
the following doesn't work properly as it inserts it, but on a submit..
again the values don't belong to $f2.

insert($t,$c = cell());
insert($c, input_text(array("name"=>"matrix",
                            "value"=>"$ohms",
                            "size"=>"15",
                            "maxlength"=>"15"))));


Thanks.



--- End Message ---
--- Begin Message ---
on 16/06/02 10:42 AM, Frank Kicenko ([EMAIL PROTECTED]) wrote:

> I have a couple of questions if you don't mind... the PHP
> help files seem to be very vague with respect to html issues.
> 
> Questions: How can I get the "selected" info from a selectbox that is in
> another form on the same page... I've tried everything I know to be able to
> get this. For instance, if a selectbox is part of $f1 and I'm submitting
> using $f2, how can I get the selection from the $f1 selectbox and use it in
> my $f2?

Anything do with PHP AFTER it's reached the browser (ie, dynamically doing
stuff with pull-downs) is a JavaScript-type issue.  PHP happen on the server
BEFORE it reaches the browser.


> Also, how can I insert a "textbox" or other items into a cell? The
> input_text belongs to $f2 and I need to insert it into a cell. for example
> the following doesn't work properly as it inserts it, but on a submit..
> again the values don't belong to $f2.
> 
> insert($t,$c = cell());
> insert($c, input_text(array("name"=>"matrix",
> "value"=>"$ohms",
> "size"=>"15",
> "maxlength"=>"15"))));


What????? I don't understand.


Justin French

--- End Message ---
--- Begin Message ---
Hi Lance:

On Sun, Jun 16, 2002 at 01:31:45AM +0800, Lance wrote:
> 
> i was developing an application that will read in the content of a html 
> file. and within this html file contains php variables which will be 
> replaced using the eval() function with its required value. and within 
> this html, i want to be able to run php functions.
> ... snip ...
> eval("\$rs = \"<span class=\"normal\">".date("m d 
> y")."$phpVar</span>\";");

Why not merge your PHP and HTML straight up like this?

<span class="normal"><?php echo date('m d y') . $phpVar; ?></span>

Then, just have the whole HTML file parsed as PHP.

--Dan

-- 
               PHP classes that make web design easier
        SQL Solution  |   Layout Solution   |  Form Solution
    sqlsolution.info  | layoutsolution.info |  formsolution.info
 T H E   A N A L Y S I S   A N D   S O L U T I O N S   C O M P A N Y
 4015 7 Av #4AJ, Brooklyn NY     v: 718-854-0335     f: 718-854-0409
--- End Message ---
--- Begin Message ---
hi dan,

its because the html text is from user input. and i dont wanna spend too 
much time educating them on coding with php. sometime its a pain trying 
to get them to understand the codes. so i just wanna give them some 
simple commands in php whereby they can happily insert date formats on a 
page. something like what phpBB did on the [url] thingie.

lance

Analysis & Solutions wrote:
> Hi Lance:
> 
> On Sun, Jun 16, 2002 at 01:31:45AM +0800, Lance wrote:
> 
>>i was developing an application that will read in the content of a html 
>>file. and within this html file contains php variables which will be 
>>replaced using the eval() function with its required value. and within 
>>this html, i want to be able to run php functions.
>>... snip ...
>>eval("\$rs = \"<span class=\"normal\">".date("m d 
>>y")."$phpVar</span>\";");
> 
> 
> Why not merge your PHP and HTML straight up like this?
> 
> <span class="normal"><?php echo date('m d y') . $phpVar; ?></span>
> 
> Then, just have the whole HTML file parsed as PHP.
> 
> --Dan
> 

--- End Message ---
--- Begin Message ---
Zac:

> foreach($kywrd as $val) {
>  $fndWrds .= "wrd = '$val' OR ";
> }

FYI, a simpler way to do that...

$fndWrds = "wrd IN ('" . implode("','", $kywrd) . "')";

That aside, w/o completely analyzing your entire set of code, it sounds 
like John is on the right track with putting a unique index on the wrd 
column.

Enjoy,

--Dan

-- 
               PHP classes that make web design easier
        SQL Solution  |   Layout Solution   |  Form Solution
    sqlsolution.info  | layoutsolution.info |  formsolution.info
 T H E   A N A L Y S I S   A N D   S O L U T I O N S   C O M P A N Y
 4015 7 Av #4AJ, Brooklyn NY     v: 718-854-0335     f: 718-854-0409
--- End Message ---
--- Begin Message ---
Hi,

Does anyboy know how to pass values between 2 Flash movies.

Thanks.

JS


--- End Message ---
--- Begin Message ---
It does work: jwynia.myvnc.com/phpinfo.php. Is experimental, but it does 
work on Windows.

Chris Garaffa wrote:
> Prachait,
> If I recall correctly, PHP 4.x doesn't work with Apache 2... Actually, no
> Apache 1.x modules do, because of the new apxs architechture. Apache 2
> support is planned for the 4.3 release (someone correct me if I'm wrong).
> On UNIX, I compiled with a -apxs2=[path] option to the configure script, but
> I'm not sure on Windows...
> 
> Chris Garaffa
> 
> On 6/15/02 10:24 AM, "Prachait Saxena" <[EMAIL PROTECTED]> wrote:
> 
> 
>>Hello !!!
>>
>>I am using Apache/2.0.36 (Win32) DAV/2 on Win98.
>>my server  is running very fine when i use PHP4 as a interpreter.
>>but as i use " LoadModule  " to use PHP4 as a modules i am getting the
>>error as
>>(31) A device attached to the system is not functioning:
>>
>>This error also come when i try to load SSL
>>I also tried to run server on Win 2k. Same error :(
>>
>>
>>Can any one help me out. why this error is comming ?
>>
>>Or where i am wrong ?
>>
>>Thanks is advance
>>Prachait Saxena
>>WebMaster [SitesOnTesting.Com]
>>
>>If you do for other's ! Other's will do for you !!
>>Visit me at http://www.sitesontesting.com/prachait
>>
>>
>>
> 
> 

--- End Message ---
--- Begin Message ---
Hi
I had downloaded new PHP 4.2.1 from www.php.net and add its modules in
Apache
Now It is working very fine.

But Same Problem in SSL and Perl, So can any one tell me where can i get
modules for this


Thanks in Advance
Prachait

Phpgeek <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> It does work: jwynia.myvnc.com/phpinfo.php. Is experimental, but it does
> work on Windows.
>
> Chris Garaffa wrote:
> > Prachait,
> > If I recall correctly, PHP 4.x doesn't work with Apache 2... Actually,
no
> > Apache 1.x modules do, because of the new apxs architechture. Apache 2
> > support is planned for the 4.3 release (someone correct me if I'm
wrong).
> > On UNIX, I compiled with a -apxs2=[path] option to the configure script,
but
> > I'm not sure on Windows...
> >
> > Chris Garaffa
> >
> > On 6/15/02 10:24 AM, "Prachait Saxena" <[EMAIL PROTECTED]>
wrote:
> >



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

I don't know if I'm getting the hole idea of what you're looking for,
but here's something. I'm using a schema that was written by Ying Zhang
for the "myMarket" PHP application which is like this:

a) One "main file" which holds all the site's configurations, like DB
settings and golbals (OO Script). It also contains an object that will
call the scripts locations:

[snip]
/* define a generic object */
class object {};

/* setup the configuration object */
$CFG = new object;

$CFG->dbhost = "localhost";
$CFG->dbname = "dbname";
$CFG->dbuser = "dbuser";
$CFG->dbpass = "dbpassword";

$CFG->wwwroot     = "/directory";
$CFG->dirroot     = "/directory";
$CFG->templatedir = "$CFG->dirroot/templates"; // Here's your standard
files
$CFG->libdir      = "$CFG->dirroot/lib"; // Lib for DB & custom handling
$CFG->imagedir    = "$CFG->wwwroot/images";
[snip]

b) When every page is called (i.e. /news/index.php), all the files
required to make that page look like you want to, all the "templates"
are called like this:

include("mainfile.php"); // needed before any else
include("logobanner.php");
include("navbar.php");
include("leftmenu.php");

// HERE'S YOUR PAGE'S CONTENT

include("rightmenu.php");
include("copyright.php");

I'm using this schema every since I found it, 'cause it is teaching me A
LOT and is very handy when I need to change something like the header of
footer of a hole site.

Hope this helps you.

Cesar Aracena
Neuquen, Argentina.

> -----Mensaje original-----
> De: Randum Ian [mailto:[EMAIL PROTECTED]]
> Enviado el: Sábado, 15 de Junio de 2002 04:42 p.m.
> Para: PHP
> Asunto: [PHP] Can I use a template with this site?
> 
> Hi All, Hope you are all well.
> 
> I am coding a website for a client and they involve a series of files:
> 
> logobanner.php
> navbar.php
> leftmenu.php
> main.php
> rightmenu.php
> copyright.php
> 
> These are all just simple HTML files which are placed in a Global dir
> apart
> from main.php which is in the same dir as the index.php file. Is there
a
> way
> where I can have one index.php file which calls all the Global files
and
> only the relevant main.php file? Kind of like a simple template
system?
> 
> For example at the moment I have this for my dir pattern:
> 
> /global/
> -logobanner.php
> -navbar.php
> -leftmenu.php
> -rightmenu.php
> -copyright.php
> /home/
> -index.php
> -main.php
> /news/
> -index.php
> -main.php
> 
> When /news/index.php is called, all the global files are called along
with
> the main.php that is in the News dir, the same for all the others in
their
> respective dirs.
> 
> Am I overlooking an important function or script that can do this
without
> being too complicated?
> 
> Please let me know, Ian.
> ---
> Randum Ian
> DJ / Reviewer / Webmaster, DancePortal (UK) Limited
> [EMAIL PROTECTED]
> http://www.danceportal.co.uk
> DancePortal.co.uk - Global dance music media
> 
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php

--- End Message ---
--- Begin Message ---
I've recently been learning about cookies myself, and had the same problem
with "" vs. 0  (PHP Fast&Easy Web Development showed the "" in their book).

I know that setting the expire parameter to 0 is supposed to kill the cookie
when browser is closed, but I can't seem to make that happen.  I've closed
all browser windows and the mail client, opened a browser again, and the
cookie is still active (let's me get back to a "protected" page).  Only a
full reboot seem to totally clear the cookie.

I've been using the time function instead, which is fine, but I'm just
curious why 0 doesn't seem to work.  Is there something else besides the
browser that could be holding onto the cookie?  I tried closing MSN
Messenger just in case, but it didn't make a difference.

Carol


----- Original Message -----
From: "Ed Lazor" <[EMAIL PROTECTED]>
Newsgroups: php.general
To: "php-general" <[EMAIL PROTECTED]>
Sent: Saturday, June 15, 2002 9:45 AM
Subject: RE: [PHP] Can't set a cookie? [SOLVED]


> Thanks for your help Everyone =)
>
> I needed the 3rd parameter set in order to specify the fourth "/", because
> the cookie is being set by a script located in a sub-directory.  One of
the
> old documents I read said "" would work as the third parameter - and it
did
> on my old servers.  Setting the third parameter to 0 worked on all
servers.
>
> -----Original Message-----
>
> The 3rd parameter is an optional time to expire parameter, if you don't
want
> to set it, leave it out.  setcookie(cookiename,"value");  works fine
>
>
>
****************************************************************************
> This message is intended for the sole use of the individual and entity to
> whom it is addressed, and may contain information that is privileged,
> confidential and exempt from disclosure under applicable law.  If you are
> not the intended addressee, nor authorized to receive for the intended
> addressee, you are hereby notified that you may not use, copy, disclose or
> distribute to anyone the message or any information contained in the
> message.  If you have received this message in error, please immediately
> advise the sender by reply email and delete the message.  Thank you very
> much.
--- End Message ---
--- Begin Message ---
I'm just curious if there's a way to restructure my code so as to avoid
getting "Undefined Variable" errors. I keep getting them and I know they're
nothing to worry about for the most part, I'd like to get rid of them
without turning off error reporting if possible. In the following code, I
get an undefined variable error for $i and for $last_name, is there anything
I can do to actually define them? $last_name is a variable produced by my
MySQL query, $i is just a counter:

while ($row = mysql_fetch_array($result)) {
        extract($row);
        $i++;
        if($i=="1") {
                print "<tr>\n";
                        }

                        if($last_name) {
                                <print stuff here>
                                } else {
                                <print other stuff>
                                }
...
                                if ($i=="5") {
                                             print "</tr>\n";
                                             $i=0;
                                             }
                                }

Thanks!

Jason Soza

--- End Message ---
--- Begin Message ---
Quick soln. is to put a "@" symbol in front of the error generating line.
E.g.@$i++;
actual soln. would be to do some initialization like
$i = 0; outside your while loop and $last_name="";
> I'm just curious if there's a way to restructure my code so as to avoid
> getting "Undefined Variable" errors. I keep getting them and I know they're
> nothing to worry about for the most part, I'd like to get rid of them
> without turning off error reporting if possible. In the following code, I
> get an undefined variable error for $i and for $last_name, is there anything
> I can do to actually define them? $last_name is a variable produced by my
> MySQL query, $i is just a counter:
>
> while ($row = mysql_fetch_array($result)) {
>       extract($row);
>       $i++;
>       if($i=="1") {
>               print "<tr>\n";
>                       }
>
>                       if($last_name) {
>                               <print stuff here>
>                               } else {
>                               <print other stuff>
>                               }
> ...
>                               if ($i=="5") {
>                                            print "</tr>\n";
>                                            $i=0;
>                                            }
>                               }
>
> Thanks!
>
> Jason Soza
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

-Pushkar S. Pradhan

--- End Message ---
--- Begin Message ---
Can simply set $i before the while.

I assume the $last_name is coming from the DB.

Not exactly sure what you want, but hope this helps.
good luck... Dan.
----------------------
$i 
        = 0;
while ($row = mysql_fetch_array($result)) {
        extract($row);
if (($i % 5) == 0) print "<tr>\n";
        $i++;
        @$last_name .= '';
        if($last_name <> '')
        <print stuff here>
         else
        <print other stuff>
...
if (($i % 5) == 0) print "</tr>\n";
}




Jason Soza wrote:

> I'm just curious if there's a way to restructure my code so as to avoid
> getting "Undefined Variable" errors. I keep getting them and I know they're
> nothing to worry about for the most part, I'd like to get rid of them
> without turning off error reporting if possible. In the following code, I
> get an undefined variable error for $i and for $last_name, is there anything
> I can do to actually define them? $last_name is a variable produced by my
> MySQL query, $i is just a counter:
> 
> while ($row = mysql_fetch_array($result)) {
>       extract($row);
>       $i++;
>       if($i=="1") {
>               print "<tr>\n";
>                       }
> 
>                       if($last_name) {
>                               <print stuff here>
>                               } else {
>                               <print other stuff>
>                               }
> ...
>                               if ($i=="5") {
>                                            print "</tr>\n";
>                                            $i=0;
>                                            }
>                               }
> 
> Thanks!
> 
> Jason Soza
> 
> 

--- End Message ---
--- Begin Message ---
Figured it was something simple. Part of the learning process, I suppose.
Thanks for the help!

Jason Soza

-----Original Message-----
From: Dan Koken [mailto:[EMAIL PROTECTED]]
Sent: Saturday, June 15, 2002 11:31 PM
To: [EMAIL PROTECTED]
Subject: [PHP] Re: Code Structure/Errors


Can simply set $i before the while.

I assume the $last_name is coming from the DB.

Not exactly sure what you want, but hope this helps.
good luck... Dan.
----------------------
$i
        = 0;
while ($row = mysql_fetch_array($result)) {
        extract($row);
if (($i % 5) == 0) print "<tr>\n";
        $i++;
        @$last_name .= '';
        if($last_name <> '')
        <print stuff here>
         else
        <print other stuff>
...
if (($i % 5) == 0) print "</tr>\n";
}




Jason Soza wrote:

> I'm just curious if there's a way to restructure my code so as to avoid
> getting "Undefined Variable" errors. I keep getting them and I know
they're
> nothing to worry about for the most part, I'd like to get rid of them
> without turning off error reporting if possible. In the following code, I
> get an undefined variable error for $i and for $last_name, is there
anything
> I can do to actually define them? $last_name is a variable produced by my
> MySQL query, $i is just a counter:
>
> while ($row = mysql_fetch_array($result)) {
>       extract($row);
>       $i++;
>       if($i=="1") {
>               print "<tr>\n";
>                       }
>
>                       if($last_name) {
>                               <print stuff here>
>                               } else {
>                               <print other stuff>
>                               }
> ...
>                               if ($i=="5") {
>                                            print "</tr>\n";
>                                            $i=0;
>                                            }
>                               }
>
> Thanks!
>
> Jason Soza

--- End Message ---

Reply via email to