[PHP-DB] Access querys to a csv
Hi all, I am trying to dump an Access db query and form it into a comma delimited file. I get the query ok. I can get it into a table with odbc_result_all. If I print the variable, it shows the first value from the first row... Any hints on the path I should take? Thanks, D -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] printing repeat table headers
It is not easy to design a SQL query that will repeat headers every 33 rows. So this should be done in the PHP code. Why not use a counter, that you increment at every mysql_fetch_array() and test if !( $counter % 33 ) Side remarks: you could also define a CSS class for TH and use TH as headers. Thus you avoid having those unpleasant bgcolor='#ff'. Or use a different TD class for that matter. Also I suppose that the count( $results ) is intended to be used to define the width attribute, but it does not seem to appear in your HTML. HTH Ignatius - Original Message - From: Sam Folk-Williams [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Saturday, February 15, 2003 6:26 PM Subject: [PHP-DB] printing repeat table headers Hi, I'm printing the results of a DB query that gets a 300 row staff directory. All 300 rows appear on one page. The top of the HTML table has basic headers like First Name, Last Name, Email etc, then all 300 rows print underneath the headers. What I would like to do is have those headers repeat every 33 rows, so that as the user scrolls down that can still see the table headers every so often. I feel like this should be easy, but it's giving me a hard time. Any suggestions? My code is below. Thanks, Sam $tableHeaders = tr td class='printRev'bStaff Name/b/td td class='printRev'bOffice Location/b/td td class='printRev'bPrimary Telephone/b/td td class='printRev'bExt/b/td td class='printRev'bEmail/b/td td class='printRev'bDirect Telephone/b/td td class='printRev'bCell/Pager/b/td /tr ; echo table width='850' border='1' cellpadding='1' cellspacing='0' bordercolor='#00'; echo $tableHeaders; while ($row = mysql_fetch_array($result)) { $count = count($result); $staff_id = $row['staff_id']; $staff_fname = $row['staff_fname']; $office_name = $row['office_name']; $staff_lname = $row['staff_lname']; $staff_phone = $row['staff_phone']; $staff_phone2 = $row['staff_phone2']; $staff_email = $row['staff_email']; $office_phone = $row['office_phone']; $ext = $row['ext']; //strip slashes from textfields $staff_fname = stripslashes($staff_fname); $staff_lname = stripslashes($staff_lname); $office_name = stripslashes($office_name); $tableContent = tr td class='print' bgcolor='#ff'$staff_lname, $staff_fname/td td class='print' bgcolor='#ff'$office_namenbsp;/td td class='print' bgcolor='#ff'$office_phonenbsp;/td td class='print' bgcolor='#ff'$extnbsp;/td td class='print' bgcolor='#ff'$staff_emailnbsp;/td td class='print' bgcolor='#ff'$staff_phonenbsp;/td td class='print' bgcolor='#ff'$staff_phone2nbsp;/td /tr; echo $tableContent; } //close while loop echo /table ; -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Help with array
Hello Working with jpGraph Gnatt Graph Sample gnatt files shows data array as follows: $data = array( array(0,Concept,2002-9-1,2002-9-15,blue), array(1,Creative,2002-9-15,2002-9-30,red), array(2,Produce,2002-9-31,2002-10-10,green)): Output $data looks like this: 0: 0 1: Concept 2: 2002-9-1 3: 2002-9-15 4: blue 0: 1 1: Creative 2: 2002-9-15 3: 2002-9-30 4: red 0: 2 1: Produce 2: 2002-9-31 3: 2002-10-10 4: green I want to create this $data array thru mySQL sql The routine I have used on other graphs: $query = order, task ,DATE_FORMAT(start, '%Y-%m-%d'),DATE_FORMAT(end, '%Y-%m-%d'), color FROM timeline WHERE jobnu = 8648 $result = mysql_query ($query); $cpt=0; while($row = mysql_fetch_row($result)) { $data[$cpt]= $row[0].,.$row[1].,.$row[2].,.$row[3].,.$row[4]; $cpt++; } Output $data 0,Concept,2002-9-1,2002-9-15,blue 1,Creative,2002-9-15,2002-9-30,red 2,Produce,2002-9-31,2002-10-10,green etc How can I create the array (in an array ??) show in the sample $data thru my SQL query ?? thanks jrt -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: Help with array
[EMAIL PROTECTED] (John Thorne) writes: $data[$cpt]= $row[0].,.$row[1].,.$row[2].,.$row[3].,.$row[4]; What you need is a two dimensional array. The code above concatenates the $row elements into a string and puts this string into a one dimensional array. the 2D array $foo[3][5] can be seen as: 0 1 2 3 4 +-+-+-+-+-+ 0 | | | | | | +-+-+-+-+-+ 1 | | | | | | +-+-+-+-+-+ 2 | | | | | | +-+-+-+-+-+ and to put stuff into the two dimensions, you need something like $foo[$i][$j] = bar; and iterate over the values $i and $j. -- --Fredrik Why be a man when you can be a success? -- Bertold Brecht -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] PHP IBM-DB2 ODBC CLIError message
I want to transfer a large amount of data(at least 5000 records with 10 fields) from MSAccess to DB2 through PHP_ODBC. When I run my script i get an error message No more Handles(see at the end the exact message). I found this message at hte information Center but it didn't help me much. Also i couldn't find something in the configuration of the database or the ODBC Connection. Can anybody help me? Warning: SQL error: [IBM][CLI Driver] CLI0129E No more handles. SQLSTATE=S1014, SQL state S1014 in SQLExecDirect -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: When to do free()?
Hmmm...still no takers on this one I decided out of curiosity to start liberally adding free() calls whenever I did a db-query(). Unfortunately it seems that the free() call causes it to die. Not quite sure why, but it did. Most of the calls that I use a query() for (as opposed to getAll() or getOne()) are INSERT/UPDATE/DELETE. Is there some reason you shouldn't do a free() after one of those? I'm still baffled. And still don't know if I should be using disconnect() at the end of each of my pages Any thoughts? Thanks, Dave David Chamberlin wrote: Hello, I'm currently using pear DB to abstract out use of my mysql database. Everything is generally working fine, except that it seems that performance seems to degrade the more it is used, then I get my ISP to restart mysql and everything seems to be good again for a while, then it degrades, lather-rinse-repeat. I'm currently one of the only ones using mysql at my ISP, so it seems that whatever I'm doing is causing issues. For the most part I'm not doing anything complex, queries are relatively simple and the dbases are currently pretty small. So while thinking about the issue, one thing that occured to me is that I'm not doing a free() on the query results when I'm done with them. That's mostly because very few of the examples I've seen ever do this, so I assumed it was an optimization that generally wasn't necessary. Furthermore, I figured that after my page got loaded, the connection to the db would be terminated and the resources freed, so the extent of the resource leak would be pretty minimal. Well, now I'm questioning the validity of those assumptions and I'm wondering if I need to start adding liberal use of free(), and I'm wondering to what extent it needs to be done? So first question, for those familiar with pearDB. It seems that certainly after doing a query() I should do a free(). What about getAll() (and related question, is there much difference between doing a query() and getAll())?). The docs seem to indicate a getOne() automatically frees resources, so I don't need to do it there. Next question is, what happens when no one refers to a result any more? Will a destructor get called that automatically frees the result? Or should I make sure to do the free before the reference is lost? How long are resources held if you don't free them? Finally, I assume that when you fetch data from a result that the data is copied and that it's not a reference, right? So as soon as I've done the necessary fetchRows() or whatever, I can safely free the result, right? Any other ideas what might be causing problems for mysql and/or how to track the problems? I believe my ISP is using linux with apache, and a fairly recent PHP and mysql. I can get more details on exact versions if that helps. Also, just as a general note, the basic format for most of my pages is: 1) connect to database 2) do some queries from PHP using pearDB 3) display results I don't specifically call disconnect() when I'm done. Should I? Sorry for the abundance of questions, and thanks for any help. Regards, Dave -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] .htaccess
Hey, this isn't totally a php question, but I would appreciate if anyone has any advice for me. I have a php script that accesses a folder, and displays all the photos inside the folder. I want to use this script to display images that people upload from the anonymous ftp account. I know that when they upload a photo, it goes into the: /home/username/public_ftp/incoming/ folder Is there a way to access the photos in that folder and display them in internet explorer. Someone mentioned using the .htaccess file and adding a line to create an alias for the folder. Can anyone help me out with this? What directory does the .htaccess file have to be in, what do I type in to create the alias for the folder, etc Thanks guys. Matt -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] .htaccess
Hi! Normally one would read that folder with read() and echo all the files makeing hrefs like this: $dir = open('/home/username/public_ftp/incoming/'); while($file = $dir-read()) echo 'a href='.$file.''.$file.'/abr'.\n; Don't forget to make sure, that the path is ok within the href... - .ma Matt [EMAIL PROTECTED] [EMAIL PROTECTED] 17:30 Uhr: Hey, this isn't totally a php question, but I would appreciate if anyone has any advice for me. I have a php script that accesses a folder, and displays all the photos inside the folder. I want to use this script to display images that people upload from the anonymous ftp account. I know that when they upload a photo, it goes into the: /home/username/public_ftp/incoming/ folder Is there a way to access the photos in that folder and display them in internet explorer. Someone mentioned using the .htaccess file and adding a line to create an alias for the folder. Can anyone help me out with this? What directory does the .htaccess file have to be in, what do I type in to create the alias for the folder, etc Thanks guys. Matt -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Virtual Tables
In MySQL, I have noticed that you can't create a virtual table by using the following syntax: select * from (select * from table where agyID=1) where clnID=... Is this correct? Thanks for your time, Philip -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Web Page Caching
Hello, I don't know if this is the right list to send this question to. It appears that the browser caches the result after a PHP page updates the database. I have to manually reload it in order to see the updates. Does anyone know how to overcome this? Thanks, Philip -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Newbie Question - PHP and MSACCESS
Hi, Am using php to open a customer's msaccess file. First time for everything. It's a very small database of less then 25 rows, and will always be this small. Am needing to return all the rows to a web page using php at all times. Very simplistic. Am apparently set up correctly on the DSN, and am able to do an odbc_connect: $connection = odbc_connect(meetings,,); Am able to fetch rows, or so it seems: $result = odbc_do($connection,select * from events where id=$id); odbc_fetch_row($result); Am not understanding how to print() the fields in the rows, one after the next, on the same line, and then do the same with the next record, until all records have been presented. Sorry to be lame. Any help would be gratefully received. -Joe
RE: [PHP-DB] Web Page Caching
Hi Philip Zee, I don't know if this is the right list to send this question to. It appears that the browser caches the result after a PHP page updates the database. I Possible that your browser stored the content of the page as normal html-page. Normaly CGI and dynamic webcontents are not cached in proxies and in browsercaches. Regards, Ruprecht -- Ruprecht Helms IT-Service und Softwareentwicklung Tel/Fax.: +49[0]7621 16 99 16 Homepage: http://www.rheyn.de email: [EMAIL PROTECTED] -- -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: Web Page Caching
[EMAIL PROTECTED] (Philip Zee) writes: I don't know if this is the right list to send this question to. It appears that the browser caches the result after a PHP page updates the database. I have to manually reload it in order to see the updates. Does anyone know how to overcome this? If you put these before any output from your script, that might help. header(Expires: Mon, 26 Jul 1997 05:00:00 GMT);// Date in the past header(Last-Modified: . gmdate(D, d M Y H:i:s) . GMT); // always modified header(Cache-Control: no-store, no-cache, must-revalidate); // HTTP/1.1 header(Cache-Control: post-check=0, pre-check=0, false); header(Pragma: no-cache); // HTTP/1.0 Read about cache control on e.g. http://vancouver-webpages.com/META/ and also check out http://www.php.net/manual/en/function.header.php -- --Fredrik Why be a man when you can be a success? -- Bertold Brecht -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: Help with array
Thanks for the reply I do not under stand how to apply your example $foo[$i][$j] = bar; Graph example array trying to create thru sql: $data = array( array(0,Concept,2002-9-1,2002-9-15,blue), array(1,Creative,2002-9-15,2002-9-30,red), array(2,Produce,2002-9-31,2002-10-10,green)): Output $data looks like this: 0: 0 1: Concept 2: 2002-9-1 3: 2002-9-15 4: blue 0: 1 1: Creative 2: 2002-9-15 3: 2002-9-30 4: red 0: 2 1: Produce 2: 2002-9-31 3: 2002-10-10 4: green SQL: $query = SELECT task, startdate, endend, barcolor FROM timeline WHERE jobnu = 8648; $result = mysql_query ($query); $cpt=0; $rownu =0; while($row = mysql_fetch_row($result)) { $data[$cpt]= $rownu.,.\.$row[0].\.,\.$row[1].\,.\.$row[2].\; $rownu++; $cpt++; Output $data 0,Concept,2002-9-1,2002-9-15,blue 1,Creative,2002-9-15,2002-9-30,red 2,Produce,2002-9-31,2002-10-10,green etc I have tried this: while ($data[]=mysql_fetch_row($result)){} This almot works but for some reason places a blank record at the end or the array. and to put stuff into the two dimensions, you need something like $foo[$i][$j] = bar; and iterate over the values $i and $j. Could you go a step farther in the $foo[$i][$j] please 20 of snow today in New Windsor, MD thanks jrt Fredrik De Vibe [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... [EMAIL PROTECTED] (John Thorne) writes: $data[$cpt]= $row[0].,.$row[1].,.$row[2].,.$row[3].,.$row[4]; What you need is a two dimensional array. The code above concatenates the $row elements into a string and puts this string into a one dimensional array. the 2D array $foo[3][5] can be seen as: 0 1 2 3 4 +-+-+-+-+-+ 0 | | | | | | +-+-+-+-+-+ 1 | | | | | | +-+-+-+-+-+ 2 | | | | | | +-+-+-+-+-+ and to put stuff into the two dimensions, you need something like $foo[$i][$j] = bar; and iterate over the values $i and $j. -- --Fredrik Why be a man when you can be a success? -- Bertold Brecht -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: Help with array
[EMAIL PROTECTED] (John Thorne) writes: [ snip ] $data[$cpt]= $rownu.,.\.$row[0].\.,\.$row[1].\,.\.$row[2].\; This is a string, not an array. Could you go a step farther in the $foo[$i][$j] please $data[$cpt][0] = $rownu; $data[$cpt][1] = $row[0]; $data[$cpt][2] = $row[1]; $data[$cpt][3] = $row[2]; should do what you want, I guess. You can have many dimensions in an array. In your case, you have two. $foo[][] means that each $foo[] contains another array, where the elements of the second dimension can be accessed by $foo[$i][$j] ($i and $j being integers and $foo a 2d array). I don't know how many dimensions you can have in PHP, but I think you can have more than two. A three dimensional one will be an array of arrays of arrays, accessed with e.g. $foo[$i][$j][$k] ($i, $j and $k being integers and $foo a 3d array). Think of it as an index of books in a library. $foo[$i] contains a 2d array of the different sections of the library, $foo[$i][j] contains an array of the book shelves in each section and $foo[$i][$j][$k] is a book. Try to google a bit for multidimensional arrays and get a grip on how they work. :-) -- --Fredrik Why be a man when you can be a success? -- Bertold Brecht -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Odd characters
G'day all, I have a folder with an (Option-F) in the name which PHP processes as Ä. Is there some sort of encoding/unencoding which will handle this character correctly? I've tried URLencoding and htmlspecialchars but I don't really know what to search for in the docs. cheers kim -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] .htaccess
Matt -- ...and then Matt said... % % I have a php script that accesses a folder, and displays all the photos % inside the folder. I want to use this script to display images that people % upload from the anonymous ftp account. I know that when they upload a photo, % it goes into the: % % /home/username/public_ftp/incoming/ folder 1) Just change your script to point to this directory just like it points to any other folder. 2) Is the public_ftp/incoming/ folder available to the browser, or is it outside the DOCUMENT_ROOT tree? If the latter, you will have to serve up the images yourself rather than relying on img... tags to simply point to them. HTH HAND :-D -- David T-G * There is too much animal courage in (play) [EMAIL PROTECTED] * society and not sufficient moral courage. (work) [EMAIL PROTECTED] -- Mary Baker Eddy, Science and Health http://justpickone.org/davidtg/ Shpx gur Pbzzhavpngvbaf Qrprapl Npg! msg18501/pgp0.pgp Description: PGP signature
[PHP-DB] Re: Help with array
$cpt=0; $rownu =1; while($row = mysql_fetch_row($result)) { $data[$cpt][0] = $rownu; $data[$cpt][1] = $row[0]; $data[$cpt][2] = $row[1]; $data[$cpt][3] = $row[2]; $rownu++; $cpt++; This worked perfectly Fredrik.. thank you jrt Fredrik De Vibe [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... [EMAIL PROTECTED] (John Thorne) writes: [ snip ] $data[$cpt]= $rownu.,.\.$row[0].\.,\.$row[1].\,.\.$row[2].\; This is a string, not an array. Could you go a step farther in the $foo[$i][$j] please $data[$cpt][0] = $rownu; $data[$cpt][1] = $row[0]; $data[$cpt][2] = $row[1]; $data[$cpt][3] = $row[2]; should do what you want, I guess. You can have many dimensions in an array. In your case, you have two. $foo[][] means that each $foo[] contains another array, where the elements of the second dimension can be accessed by $foo[$i][$j] ($i and $j being integers and $foo a 2d array). I don't know how many dimensions you can have in PHP, but I think you can have more than two. A three dimensional one will be an array of arrays of arrays, accessed with e.g. $foo[$i][$j][$k] ($i, $j and $k being integers and $foo a 3d array). Think of it as an index of books in a library. $foo[$i] contains a 2d array of the different sections of the library, $foo[$i][j] contains an array of the book shelves in each section and $foo[$i][$j][$k] is a book. Try to google a bit for multidimensional arrays and get a grip on how they work. :-) -- --Fredrik Why be a man when you can be a success? -- Bertold Brecht -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Newbie Question - PHP and MSACCESS
$cnx = odbc_connect( 'DSN' , 'USER', 'PASS' ); if (!$cnx) { ?Could not connect to ODBC? } $cur= odbc_exec( $cnx, SELECT Vehicle.Vehicle_ID, Vehicle.Cust_ID FROM Vehicle ); if (!$cur) { Error_handler( Error in odbc_exec( no cursor returned ) , $cnx ); } // fetch the succesive result rows while( odbc_fetch_row( $cur ) ) { $nbrow++; // Assign results names $Cust_Id= odbc_result($cur,2); $Vehicle_ID= odbc_result($cur,1); #code Here } -Original Message- From: J.M. Cocchini [mailto:[EMAIL PROTECTED]] Sent: Sunday, February 16, 2003 4:01 PM To: [EMAIL PROTECTED] Subject: [PHP-DB] Newbie Question - PHP and MSACCESS Hi, Am using php to open a customer's msaccess file. First time for everything. It's a very small database of less then 25 rows, and will always be this small. Am needing to return all the rows to a web page using php at all times. Very simplistic. Am apparently set up correctly on the DSN, and am able to do an odbc_connect: $connection = odbc_connect(meetings,,); Am able to fetch rows, or so it seems: $result = odbc_do($connection,select * from events where id=$id); odbc_fetch_row($result); Am not understanding how to print() the fields in the rows, one after the next, on the same line, and then do the same with the next record, until all records have been presented. Sorry to be lame. Any help would be gratefully received. -Joe -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: Web Page Caching
This may not be true in your case, but I remember another user on this list claiming a similar thing, and his problem was actually code-related. He had his db update code *AFTER* the results were displayed (ie. doing edit and save on same page). Check your programming logic. Just a note to people out there who may not have much programming experience - try doing all of your server-side processing (or at least db and filesystem calls, etc) before you output any data, this way you can implement error checking etc and still use the header() function, etc. Adam --- Original Message --- Hello, I don't know if this is the right list to send this question to. It appears that the browser caches the result after a PHP page updates the database. I have to manually reload it in order to see the updates. Does anyone know how to overcome this? Thanks, Philip
Re: [PHP-DB] Re: php date manupulation functions
On Sun, Feb 16, 2003 at 08:14:57AM -0800, David Chamberlin wrote: David Elliott wrote: try ? echo date(d,$dbdate).br; echo date(m,$dbdate).br; echo date(y,$dbdate).br; ? I thought date() took a timestamp, not a string. Here's what I do: $timestamp = $dbdate; echo date(d,$timestamp) echo date(m,$timestamp) I did this : $dob= explode('-', $aAns[dob]); This gives me an array of $dob with yy, mm and dd. Thanks to those who replied. Peace -- Rajesh -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php