php-general Digest 13 Mar 2009 14:05:44 -0000 Issue 6009
Topics (messages 289970 through 289990):
Re: Daily and Weekly Calendar classes
289970 by: Bastien Koert
Re: non-auto increment question
289971 by: Jim Lucas
Re: [PHP-DEV] How expensive are function_exists() calls?
289972 by: mike
289973 by: Robert Cummings
289974 by: mike
289975 by: Robert Cummings
289978 by: mike
2 forms, same page, 1st is file upload - works in IE, 'dies' in non-IE browsers
289976 by: scubak1w1
289979 by: Micah Gersten
289981 by: Ross McKay
289982 by: Ashley Sheridan
289983 by: 9el
289987 by: haliphax
PHP to create an ERD (sic) on the fly on a web page based on current DB records?
289977 by: scubak1w1
289980 by: Ross McKay
289986 by: haliphax
289990 by: Bastien Koert
php 5.2.8 to 5.2.9 concerns
289984 by: The Doctor
Re: Knowledge Base software - looking for opinions
289985 by: Bob McConnell
Export/Write rows from DBF to CSV
289988 by: Rahul S. Johari
289989 by: Bastien Koert
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 ---
On Thu, Mar 12, 2009 at 9:05 PM, Jason Todd Slack-Moehrle <
[email protected]> wrote:
> Hi All,
>
> Does anyone have classes for creating a nice daily calendar? I can put the
> data in MySQL and be queried, etc.
>
> Something that when I add events to the calendar it puts them in the right
> time slot, etc, etc.
>
> I can do the rest of the coding
>
> Free is best!
>
> -Jason
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
check
www.hotscripts.com
www.phpclasses.org
http://sourceforge.net
--
Bastien
Cat, the other other white meat
--- End Message ---
--- Begin Message ---
PJ wrote:
am resending as this was erroneously ccd to mysql. sorry!
Ashley Sheridan wrote:
On Thu, 2009-02-26 at 11:27 -0500, PJ wrote:
Jerry Schwartz wrote:
Being rather new to all this, I understood from the MySql manual that
the auto_increment is to b e used immediately after an insertion not
intermittently. My application is for administrators (the site owner &
designates) to update the database from and administration directory,
accessed by user/password login... so there's really very little
possibility of 2 people accessing at the same time.
By using MAX + 1 I keep the id number in the $idIn and can reuse it in
other INSERTS
[JS] Are you looking for something like LAST_INSERT_ID()? If you
INSERT a
record that has an auto-increment field, you can retrieve the value
that got
inserted with "SELECT LAST_INSERT_ID()". It is connection-specific, so
you'll always have your "own" value. You can then save it to reuse,
either
as a session variable or (more easily) as a hidden field on your form.
Thanks, Jerry,
You hit the nail on the head.:)
To refine my problem (and reduce my ignorance),here's what is happening
on the form page:
There is a series of INSERTs. The first inserts all the columns of
"book" table except for the id, which I do not specify as it if
auto-insert.
In subsequent tables I have to reference the book.id (for transitional
tables like "book_author"(refers authors to book) etc.
If I understand it correctly, I must retrieve ("SELECT
LAST_INSERT_ID()") after the first INSERT and before the following
insert; and save the id as a string ($id)...e.g. $sql = "SELECT
LAST_INSERT_ID() AS $id"
I need clarification on the "AS $id" - should this be simply id(does
this have to be turned into a value into $id or does $id contain the
value? And how do I retrieve it to use the returned value for the next
$sql = "INSERT ... - in other words, is the id or $id available for the
next directive or do I have to do something like $id = id?
I'm trying to figure this out with some trials but my insert does not
work from a php file - but it works from command-line... that's another
post.
Here's how I mostly do it (albeit simplified):
$query = "INSERT INTO `sometable`(`title`,`content`)
VALUES('$title','$content')";
$result = mysql_query($query);
$autoId = mysql_insert_id($result);
$query = "INSERT INTO `another_table`(`link_id`,`value`)
VALUES($autoId,'$value');
$result = mysql_query($query);
No need to call another query to retrieve the last inserted id, as it is
tied to the last query executed within this session.
Ash
www.ashleysheridan.co.uk
For some reason or other $autoId = mysql_insert_id($result); just does
not work for me... Yet some of the data is inserted correctly...
I did find that it does not work on tables that are empty... so you
can't start with an empty table. I entered data & it still did not work.
I tried on another duplicate database... doesn't work.
I have checked & double checked the database, I have added checks to see
what is returned and the returns are 0 or null - as I get different
responses for slightly different functions.
sessions is on
mysql is 5.1.28
php5
here's what is parsed:
else { $sql1 = "INSERT INTO book
( title, sub_title, descr, comment, bk_cover,
copyright, ISBN, language, sellers )
VALUES
('$titleIN', '$sub_titleIN', '$descrIN',
'$commentIN', '$bk_coverIN', '$copyrightIN',
'$ISBNIN', '$languageIN', '$sellersIN')";
$result1 = mysql_query($sql1, $db);
$autoid = mysql_insert_id($result1);
$sql2 = "INSERT INTO author (first_name, last_name) VALUES
('$first_nameIN', '$last_nameIN')";
$result2 = mysql_query($sql2, $db);
$authorID = mysql_insert_id($result2);
$sql2a = "INSERT INTO book_author (authID, bookID, ordinal)
VALUES ( '$authorID', '$autoid', '1')";
$result2a = mysql_query($sql2a, $db);
$sql2b = "INSERT INTO author (first_name, last_name) VALUES
('$first_name2IN', '$last_name2IN')";
$result2b = mysql_query($sql2b, $db);
$author2ID = mysql_insert_id($result2b);
$sql2c = "INSERT INTO book_author (authID, bookID, ordinal)
VALUES ( '$author2ID', '$autoid', '2')";
$result2c = mysql_query($sql2c, $db);
$sql3 = "INSERT INTO publishers (publisher) VALUES
('$publisherIN')";
$result3 = mysql_query($sql3, $db);
$publisherID = mysql_insert_id($result3);
$sql3a = "INSERT INTO book_publisher (bookID, publishers_id)
VALUES ( '$autoid', '$publisherID' )";
$result3a = mysql_query($sql3a, $db);
foreach($_POST['categoriesIN'] as $category){
$sql4 = "INSERT INTO book_categories (book_id, categories_id)
VALUES ($autoid, $category)";
$result4 = mysql_query($sql4,$db);
}
echo $autoid; // shows: "blank"
echo $authorID; // shows: "blank"
echo $author2ID; // shows: "blank"
echo $publisherID; // shows: "blank"
echo "<br>autoid = $autoid<br>";// shows: autoid = "blank"
echo "authorID = $authorID<br>";// shows: authorID = "blank"
echo "author2ID = $author2ID<br>";// shows: author2ID = "blank"
echo "publisherID = $publisherID<br>";// shows: publisherID =
"blank"
here is what is inserted:
book is correctly inserted
author is correctly inserted
book_author is correctly inserted
book_categories is correctly inserted
book_publisher bookID = 0 publishers_id = 0 (not correct)
publishers is correctly inserted
You need to take a closer look at this page:
http://php.net/manual/en/function.mysql-insert-id.php
Under the parameters section, look at the description of the link_identifier. It talks about the
link_identifier being the database connection handler, not the resulting resource that is returned
from a call to mysql_query().
Change the value you are passing to mysql_insert_id() to be the $db variable instead of the $results
variable and you will probably get the results you are looking for.
Also, reading further tells me that since you did not pass mysql_insert_id() a valid connection
handler, you should have gotten a E_WARNING notice. Did you by chance check your logs for this error?
Honestly, sounds like you need to turn on full error reporting to the screen.
Place the following at the top of your script and you might see the problem a
little clearer.
error_reporting(E_ALL);
ini_set('display_errors', 1);
This will make it so that every error is reported to the screen and not just
logged.
--
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
--- End Message ---
--- Begin Message ---
For templating ideas ...
Would bytecode caches (APC) be able to work properly with this:
function print_something($args, $output = 'html') {
switch($output) {
'iphone':
print_something_iphone($args);
break;
default:
print_something_html($args);
break;
}
}
or something like this:
function print_something($args, $output = 'html') {
if(function_exists('print_something_'.$output)) {
call_user_func('print_something_'.$output);
}
}
On Wed, Mar 4, 2009 at 12:45 PM, mike <[email protected]> wrote:
> On Wed, Mar 4, 2009 at 4:01 AM, Jochem Maas <[email protected]> wrote:
>> ..not an internals question me thinks ... redirecting to generals mailing
>> list
>
> Actually, I do think it is somewhat internals related.
>
> I want to know from the internals/experts angle if this is a good
> function to be relying on, or if it is one of those things like the
> "@" operator which I've been told is "expensive" and to me is one of
> those things to stay away from.
>
> Now if this breaks opcode caches like APC, I will have to find another way.
>
> Also - I write procedural, not OOP. So that won't help here.
>
> Would creating functions such as
>
> output_foo_html()
> output_foo_rss()
> output_foo_json()
>
> Then depending on the output, using something like this? Would this be
> breaking opcode caches as well then?
>
> if(function_exists('output_foo_'.$format)) {
> call_user_func('output_foo_'.$format);
> } else {
> output_foo_html();
> }
>
--- End Message ---
--- Begin Message ---
On Thu, 2009-03-12 at 21:55 -0700, mike wrote:
> For templating ideas ...
>
> Would bytecode caches (APC) be able to work properly with this:
>
> function print_something($args, $output = 'html') {
> switch($output) {
> 'iphone':
> print_something_iphone($args);
> break;
> default:
> print_something_html($args);
> break;
> }
> }
>
>
> or something like this:
>
> function print_something($args, $output = 'html') {
> if(function_exists('print_something_'.$output)) {
> call_user_func('print_something_'.$output);
> }
> }
I thought we covered a question just like this a week ago... yes this
will not pose a problem for a bytecode cache.
Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP
--- End Message ---
--- Begin Message ---
On Thu, Mar 12, 2009 at 10:10 PM, Robert Cummings <[email protected]> wrote:
> I thought we covered a question just like this a week ago... yes this
> will not pose a problem for a bytecode cache.
Apologies. I saw an example of some OOP thing from internals before it
moved to -general.
So even using call_user_func() with dynamic functions won't break the
usefulness of APC?
--- End Message ---
--- Begin Message ---
On Thu, 2009-03-12 at 22:27 -0700, mike wrote:
> On Thu, Mar 12, 2009 at 10:10 PM, Robert Cummings <[email protected]>
> wrote:
>
> > I thought we covered a question just like this a week ago... yes this
> > will not pose a problem for a bytecode cache.
>
> Apologies. I saw an example of some OOP thing from internals before it
> moved to -general.
>
> So even using call_user_func() with dynamic functions won't break the
> usefulness of APC?
The only thing that should defeat the usefulness of a bytecode cache is
the use of eval since the cache has no reference point upon which to
determine if the eval'd code has been previously compiled and has
changed since.
Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP
--- End Message ---
--- Begin Message ---
On Thu, Mar 12, 2009 at 10:35 PM, Robert Cummings <[email protected]> wrote:
> The only thing that should defeat the usefulness of a bytecode cache is
> the use of eval since the cache has no reference point upon which to
> determine if the eval'd code has been previously compiled and has
> changed since.
I guess I considered something like
call_user_func($some variables) was somewhat equivalent of an eval...
--- End Message ---
--- Begin Message ---
Hello,
Banging my head against this one...
Briefly:
- I have two forms on the same page
- both forms are: action="<?php print $_SERVER['PHP_SELF']; ?>"
method="post"
- both forms gave unique ids
- both forms have a hidden file of the type <input type="hidden"
name="_add_new_module_details" value="1" /> which is checked directly below
the form with an "if(array_key_exists('_add_new_module_details', $_POST))
{ ...}" method
- first form is a file upload
- 2nd form is a details submit
- submit button on 2nd form is only 'turned on' (via AJAX) once the user
has uploaded file file
- 2nd form validated fields contents, via an onsubmit
- after 2nd form successuly submitted, head off back to another page
In Internet Destroyer, the page works just fine (i.e., both forms fire as
expected)
In the non-IE browsers I have tried (Firefox, Chrome, Opera), the first form
uploads the file properly, the 2nd form's submit is 'turned on' by AJAX -
BUT the submit button on the 2nd form doesn't seem to do anything - i.e.,
the onsubmit is not being triggered, etc, etc
help! <smile>
Thanks in advance:
GREG
--- End Message ---
--- Begin Message ---
scubak1w1 wrote:
> Hello,
>
> Banging my head against this one...
>
> Briefly:
> - I have two forms on the same page
> - both forms are: action="<?php print $_SERVER['PHP_SELF']; ?>"
> method="post"
> - both forms gave unique ids
> - both forms have a hidden file of the type <input type="hidden"
> name="_add_new_module_details" value="1" /> which is checked directly below
> the form with an "if(array_key_exists('_add_new_module_details', $_POST))
> { ...}" method
> - first form is a file upload
> - 2nd form is a details submit
> - submit button on 2nd form is only 'turned on' (via AJAX) once the user
> has uploaded file file
> - 2nd form validated fields contents, via an onsubmit
> - after 2nd form successuly submitted, head off back to another page
>
> In Internet Destroyer, the page works just fine (i.e., both forms fire as
> expected)
>
> In the non-IE browsers I have tried (Firefox, Chrome, Opera), the first form
> uploads the file properly, the 2nd form's submit is 'turned on' by AJAX -
> BUT the submit button on the 2nd form doesn't seem to do anything - i.e.,
> the onsubmit is not being triggered, etc, etc
>
> help! <smile>
>
> Thanks in advance:
> GREG
>
>
>
Have you checked the Javascript error console in Firefox?
--
Micah
--- End Message ---
--- Begin Message ---
On Thu, 12 Mar 2009 18:39:38 -0600, scubak1w1 wrote:
>[...]
>In the non-IE browsers I have tried (Firefox, Chrome, Opera), the first form
>uploads the file properly, the 2nd form's submit is 'turned on' by AJAX -
>BUT the submit button on the 2nd form doesn't seem to do anything - i.e.,
>the onsubmit is not being triggered, etc, etc
How do you "turn on" your submit button? (for that matter, how do you
"turn it off"?)
Have you checked Firefox's log to see if you have JavaScript errors?
--
Ross McKay, Toronto, NSW Australia
"Let the laddie play wi the knife - he'll learn"
- The Wee Book of Calvin
--- End Message ---
--- Begin Message ---
On Fri, 2009-03-13 at 02:06 -0500, Micah Gersten wrote:
> scubak1w1 wrote:
> > Hello,
> >
> > Banging my head against this one...
> >
> > Briefly:
> > - I have two forms on the same page
> > - both forms are: action="<?php print $_SERVER['PHP_SELF']; ?>"
> > method="post"
> > - both forms gave unique ids
> > - both forms have a hidden file of the type <input type="hidden"
> > name="_add_new_module_details" value="1" /> which is checked directly below
> > the form with an "if(array_key_exists('_add_new_module_details', $_POST))
> > { ...}" method
> > - first form is a file upload
> > - 2nd form is a details submit
> > - submit button on 2nd form is only 'turned on' (via AJAX) once the user
> > has uploaded file file
> > - 2nd form validated fields contents, via an onsubmit
> > - after 2nd form successuly submitted, head off back to another page
> >
> > In Internet Destroyer, the page works just fine (i.e., both forms fire as
> > expected)
> >
> > In the non-IE browsers I have tried (Firefox, Chrome, Opera), the first
> > form
> > uploads the file properly, the 2nd form's submit is 'turned on' by AJAX -
> > BUT the submit button on the 2nd form doesn't seem to do anything - i.e.,
> > the onsubmit is not being triggered, etc, etc
> >
> > help! <smile>
> >
> > Thanks in advance:
> > GREG
> >
> >
> >
>
> Have you checked the Javascript error console in Firefox?
>
> --
> Micah
>
It sounds like a script error rather than a PHP error. Use Firebug which
will show you the HTML as it is updated by Javascript, so you can see
where the problem is. I'm willing to bet that the Javascript code you
are using is IE only.
Ash
www.ashleysheridan.co.uk
--- End Message ---
--- Begin Message ---
> It sounds like a script error rather than a PHP error. Use Firebug which
> will show you the HTML as it is updated by Javascript, so you can see
> where the problem is. I'm willing to bet that the Javascript code you
> are using is IE only.
>
> Yeah, php is never browser specific. It is rendered to HTML before browser
can see it. So all browsers will react the same with PHP. But will differ on
the client sides like JavaScript.
--- End Message ---
--- Begin Message ---
On Fri, Mar 13, 2009 at 3:18 AM, 9el <[email protected]> wrote:
>> It sounds like a script error rather than a PHP error. Use Firebug which
>> will show you the HTML as it is updated by Javascript, so you can see
>> where the problem is. I'm willing to bet that the Javascript code you
>> are using is IE only.
>>
>> Yeah, php is never browser specific. It is rendered to HTML before browser
> can see it. So all browsers will react the same with PHP. But will differ on
> the client sides like JavaScript.
Also--INCLUDE YOUR CODE. Listing everything you do in pseudocode will
do you absolutely no good for a problem like this, as it is no doubt a
syntax error or a browser-javascript-compatibility issue. If we can't
see the code, we can't point out the problem.
Anyway, yeah--if it works in IE and not in FF, then it has nothing to
do with PHP (directly). Change your JS.
--
// Todd
--- End Message ---
--- Begin Message ---
Hello,
Seeking some advice on how to create an ERD (sic) graphically on the page on
the fly when the page is 'called'...
That is, I have a backend PostgreSQL database that I am getting data from
and putting data into via web page/s and PHP...
I would like to be able to show graphically to the web site admins the
relationships between the pimary key contents of one table to all its
foreign keys in the daughter table in a form of a simple entity relationship
diagram.
That is, a graphic showing (say) all of the PKs listed in the mother table,
all of the more voluminous (sic) FKs listed in another table - and
"connecting lines."
This is to aid the admin users that are used to conceptualiazing this sort
of thing...
Obscure question I know...
But any thoughts?
Regards & TIA:
GREG...
--- End Message ---
--- Begin Message ---
On Thu, 12 Mar 2009 18:47:40 -0600, scubak1w1 wrote:
>Seeking some advice on how to create an ERD (sic) graphically on the page on
>the fly when the page is 'called'...
>[...]
Maybe GraphViz?
http://graphviz.org/
--
Ross McKay, Toronto, NSW Australia
"Let the laddie play wi the knife - he'll learn"
- The Wee Book of Calvin
--- End Message ---
--- Begin Message ---
On Thu, Mar 12, 2009 at 7:47 PM, scubak1w1 <[email protected]> wrote:
> Hello,
>
> Seeking some advice on how to create an ERD (sic) graphically on the page on
> the fly when the page is 'called'...
>
> That is, I have a backend PostgreSQL database that I am getting data from
> and putting data into via web page/s and PHP...
>
> I would like to be able to show graphically to the web site admins the
> relationships between the pimary key contents of one table to all its
> foreign keys in the daughter table in a form of a simple entity relationship
> diagram.
>
> That is, a graphic showing (say) all of the PKs listed in the mother table,
> all of the more voluminous (sic) FKs listed in another table - and
> "connecting lines."
>
> This is to aid the admin users that are used to conceptualiazing this sort
> of thing...
PHPMyAdmin does exactly this sort of thing, as do a lot of SQL
workbench programs. I'm sure there is one out there that will handle
PostgreSQL. My advice to you is not to reinvent the wheel. If they're
admin users, do you really need to wrap it up in a self-contained
webpage for them, or could you just show them using an administrative
tool that can handle ERD?
--
// Todd
--- End Message ---
--- Begin Message ---
On Fri, Mar 13, 2009 at 9:37 AM, haliphax <[email protected]> wrote:
> On Thu, Mar 12, 2009 at 7:47 PM, scubak1w1 <[email protected]> wrote:
> > Hello,
> >
> > Seeking some advice on how to create an ERD (sic) graphically on the page
> on
> > the fly when the page is 'called'...
> >
> > That is, I have a backend PostgreSQL database that I am getting data from
> > and putting data into via web page/s and PHP...
> >
> > I would like to be able to show graphically to the web site admins the
> > relationships between the pimary key contents of one table to all its
> > foreign keys in the daughter table in a form of a simple entity
> relationship
> > diagram.
> >
> > That is, a graphic showing (say) all of the PKs listed in the mother
> table,
> > all of the more voluminous (sic) FKs listed in another table - and
> > "connecting lines."
> >
> > This is to aid the admin users that are used to conceptualiazing this
> sort
> > of thing...
>
> PHPMyAdmin does exactly this sort of thing, as do a lot of SQL
> workbench programs. I'm sure there is one out there that will handle
> PostgreSQL. My advice to you is not to reinvent the wheel. If they're
> admin users, do you really need to wrap it up in a self-contained
> webpage for them, or could you just show them using an administrative
> tool that can handle ERD?
>
>
> --
> // Todd
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
there is a version of phpmyadmin for postgre. phppgadmin is available from
sourceforge.net
--
Bastien
Cat, the other other white meat
--- End Message ---
--- Begin Message ---
In 5.2.9 I was seeing
/usr/local/lib/php/includes/XBT/class/pstgrs_DB.php(70) : Warning - pg_query():
supplied argument is not a valid PostgreSQL link resource
/usr/local/lib/php/includes/XBT/class/pstgrs_DB.php(70) : Warning - pg_query()
[<a href='function.pg-query'>function.pg-query</a>]: Query failed: ERROR:
insert
or update on table "tour_times" violates foreign key constraint
"ttm_rac_fk"
/usr/local/lib/php/includes/XBT/class/pstgrs_DB.php(70) : Warning - pg_query()
[<a href='function.pg-query'>function.pg-query</a>]: Query failed: ERROR:
insert
or update on table "tour_times" violates foreign key constraint
"ttm_rac_fk"
/usr/local/lib/php/includes/XBT/class/pstgrs_DB.php(72) : Fatal error - Call to
undefined function pg_affected_rows()
for Postgres 8.1 latest .
This is not the case in 5.2.8
What is going on?
I used
./configure \
--with-apxs2 \
--enable-embed=shared \
--enable-fastcgi \
--enable-force-cgi-redirect \
--enable-debug \
--with-openssl=/usr \
--with-zlib=/usr \
--with-bz2=/usr \
--enable-calendar \
--enable-ftp \
--with-openssl-dir=/usr \
--with-zlib-dir=/usr \
--with-pdo-pgsql=/usr/local/pgsql/bin \
--with-pgsql=/usr/local/pgsql \
--enable-shared --disable-static
to build both libphp5.so modules .
--
Member - Liberal International This is [email protected]
Ici [email protected] God, Queen and country! Beware Anti-Christ rising!
Never Satan President Republic!
Point to http://tv.cityonahillproductions.com/
--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
--- End Message ---
--- Begin Message ---
From: haliphax
> On Thu, Mar 12, 2009 at 3:44 PM, Paul M Foster
<[email protected]> wrote:
>> On Thu, Mar 12, 2009 at 12:55:54PM -0700, mike wrote:
>>
>>> http://puresw.com/products/lore/ - paid
>>> http://www.knowledgebase-script.com/ - paid
>>> http://68kb.com/ - free
>>>
>>> Free is good.
>>>
>>> Just needs to be basic, nothing crazy.
>>>
>>> A Wiki -almost- meets the needs but a) I hate wikis and b) they
don't
>>> match up 100%
>>
>> Out of curiosity, why do you dislike wikis?
>
> It may be the lack of access permissions in a lot of the wiki systems
> out there right now... though some of them have an access control
> layer (such as TWiki).
Dokuwiki <http://wiki.splitbrain.org/wiki:dokuwiki> has an optional ACL
layer for access control. There are also several options for
authentication back ends. We used it in a grass roots project for over a
year before management decide it was a good idea and bought a site
license for Confluence as the official company wide knowledge base. I
was trying to get the LDAP interface working with Active Directory when
they informed me it was going to be phased out.
Bob McConnell
--- End Message ---
--- Begin Message ---
Ave,
I'm trying to retrieve data from a DBF database and write it to a CSV
file in a comma delimited format. I'm able to get the data and write
it to CSV, but it only writes the last row/record ... not all the
records. I know I don't have the correct code and I'm hoping someone
can help me...
_____________
#CREATE CSV
$date = date('mdy');
$_file = 'CSV/TransferData_'.$date.'.csv';
$_fp = @fopen( $_file, 'w' );
#SELECT DBF TO OPEN - READ ONLY
$db = dbase_open("mydata.dbf", 0);
#PULL UP RECORD
if ($db) {
$record_numbers = dbase_numrecords($db);
for ($i = 1; $i <= $record_numbers; $i++) {
$row = dbase_get_record_with_names($db, $i);
#WRITE ROWS TO VARIABLE
$_csv_data = trim($row['PHONE']).",".trim($row['DATE']).","."\n";
<-- THIS is where my problem is! This only writes the last row!!
}
}
#WRITE TO CSV
@fwrite( $_fp, $_csv_data );
@fclose( $_fp );
_____________
Thanks!
---
Rahul Sitaram Johari
Founder, Internet Architects Group, Inc.
[Email] [email protected]
[Web] http://www.rahulsjohari.com
--- End Message ---
--- Begin Message ---
On Fri, Mar 13, 2009 at 9:56 AM, Rahul S. Johari <
[email protected]> wrote:
> Ave,
>
> I'm trying to retrieve data from a DBF database and write it to a CSV file
> in a comma delimited format. I'm able to get the data and write it to CSV,
> but it only writes the last row/record ... not all the records. I know I
> don't have the correct code and I'm hoping someone can help me...
>
> _____________
> #CREATE CSV
> $date = date('mdy');
> $_file = 'CSV/TransferData_'.$date.'.csv';
> $_fp = @fopen( $_file, 'w' );
>
> #SELECT DBF TO OPEN - READ ONLY
> $db = dbase_open("mydata.dbf", 0);
> #PULL UP RECORD
> if ($db) {
> $record_numbers = dbase_numrecords($db);
> for ($i = 1; $i <= $record_numbers; $i++) {
> $row = dbase_get_record_with_names($db, $i);
>
> #WRITE ROWS TO VARIABLE
> $_csv_data =
> trim($row['PHONE']).",".trim($row['DATE']).","."\n"; <-- THIS is where my
> problem is! This only writes the last row!!
> }
> }
>
> #WRITE TO CSV
> @fwrite( $_fp, $_csv_data );
> @fclose( $_fp );
> _____________
>
> Thanks!
>
> ---
> Rahul Sitaram Johari
> Founder, Internet Architects Group, Inc.
>
> [Email] [email protected]
> [Web] http://www.rahulsjohari.com
>
>
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
You are overwriting the variable ($csv_data) that holds the row, add a
period (concatenator) operator to build the up the data
#WRITE ROWS TO VARIABLE
$_csv_data .=
trim($row['PHONE']).",".trim($row['DATE']).","."\n";
<-- THIS is where my problem is! This only writes the last row!!
--
Bastien
Cat, the other other white meat
--- End Message ---