Re: [PHP-DB] Renaming all pages to .php
Hi David Comments inline... On Thu,Jun 19, 2003 at 08:31:40PM -0700, David Blomstrom wrote : At 09:16 PM 6/19/2003 -0500, Joshua Stein wrote: snip I don't know exactly what you mean, but I just renamed one of my pages (using Dreamweaver) with a .php extension, previewed it in Mozilla, and it worked fine. This is the address displayed in the browser: file:///C:/sites/geosymbols/birds.php However, when I pasted the URL into Internet Explorer. So I linked to the page from page X, previewed page X in IE and clicked the link and was taken to C:\sites\geosymbols\waldman.php That's weird. I never even realized my two browsers displayed localhost links differently - file:///c versus C:, and forward slashes versus back slashes. But I assume that means my server is set up properly. As long as I can preview my pages, I can't complain! * * * * * * * * * * /snip This doesn't mean your server is set up correctly. The file:// scheme or the c:\... means that the browser is reading the file directly from the hard disk. The page is not being served by your web server (which I assume you have setup on your local machine). When the browser reads a file from the hard drive, it will display the contents (if it can), parsing out and rendering HTML as it goes. For example, create a file with a php extension with the following contents:- ?php phpinfo(); ? H1This bit is html/H1 Save this in your webroot. Here we have a page that has both html and php in it. If you view this using the file:// or c:\ methods (as used by dreamweaver's preview by default) you will see the H1 rendered and none of the php code, but the php code will not have executed. Compare that with browsing via http://localhost/mytest.php. You'll find that the php has executed and you have the html rendered out below. When testing pages locally the best way to do it is to have a browser open and explicitly browse to http://localhost/dirname/pagename.php /snip Alright, it sounds like a go. Thanks for all the tips. snip I think you'll find that having every page in a separate folder will create an internal link nightmare. I would be inclined to structure your site in a more standard way and use Apache's rewrite module to create the http://site.com/dirname/ style urls you are talking about. You could also use the rewrite module to allow people to request a page with an htm extension, which is translated into, eg: a page with a php extension, a query string passed to a specfic php page, etc. That way you keep search engines and bookmarkers happy but retain your development freedom. It effectively inserts a configurable layer between the browser and the server where you can manage the type and appearance of urls that apply to the site. ISAPI url rewrite filters are available for IIS if that's your server flavour. Hope this helps. Ronan -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Renaming all pages to .php
Hi Steve Comments inline... On 20 Jun,2003 at 10:06 Steve B. wrote: snip I've heard of a Apache server setting or update that makes for example: .com/shoes.html returns page /index.php?site=shoes or .com/shoes.html returns page /shoes.php /snip See my previous post on this thread ... the module you want is mod_rewrite. If you're a dab hand with regexps you shouldn't have any trouble with it !?!?! ;-) Ronan e: [EMAIL PROTECTED] t: 01903 739 997 w: www.thelittledot.com The Little Dot is a partnership of Ronan Chilvers and Giles Webberley -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] How can I get the number of entries retrieved by aSELECT - FROM
On 12 Jun,2003 at 18:21 Becoming Digital wrote: snip The PHP SELECT FROM below (before snip) listed the expected data. Is there a way to get the digit 3 into a PHP variable $data = mysql_result($result,1,name)); How do I trap or collect or save the digit 3 generated the mysql SELECT COUNT(*) statement below? /snip Or do SELECT COUNT(*) AS mycount ... which will give you a result set with, eg: an array key called 'mycount' that you can grab. Ronan -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Select statement drops 10th digit during table lookup?
On 13 Jun,2003 at 0:48 G E Holt wrote: $resolved=$DB_site-query_first(SELECT * FROM country WHERE '$resolvingip' BETWEEN ip_from AND ip_to); Don't think you should have the '' around the ip number. Does that help? Ronan e: [EMAIL PROTECTED] t: 01903 739 997 w: www.thelittledot.com The Little Dot is a partnership of Ronan Chilvers and Giles Webberley -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Select statement drops 10th digit during table lookup?
Here's how I did it when playing with this... Table definition:- CREATE TABLE ip_list ( ip_from double default NULL, ip_to double default NULL, country_code char(2) default NULL, country_name varchar(100) default NULL, KEY ip_from (ip_from,ip_to,country_code,country_name) ) TYPE=MyISAM; Basic code to query it (takes a parameter 'ip' as GET paramter):- ?php /* IP Lookup script * prints a country code and name for an ip in the $_GET array */ //Vars Constants define(HOST,myhost); define(USER,myuser); define(PASS,mypassword); define(DB,ips); define(IP,$_GET[ip]); // Functions function dbconnect() { if (($conn=mysql_pconnect(HOST,USER,PASS))===false) { die(Couldn't connect to server); } if (!mysql_select_db(DB,$conn)) { die(Couldn't select database); } return $conn; } function dbclose($conn) { if (!mysql_close($conn)) { die(Couldn't close database connection); } return true; } function dosql($SQL) { if (($result=mysql_query($SQL))===false) { die(Couldn't do sql : $SQL); } return $result; } //Core $SQL = SELECT COUNTRY_NAME AS cn, COUNTRY_CODE AS cc FROM ips.ip_list WHERE IP_NUM BETWEEN ip_from AND ip_to; $conn = dbconnect(); $ip = 127.0.0.1; $QSQL = str_replace(IP_NUM,sprintf(%u,ip2long(IP)),$SQL); $result = dosql($QSQL); $data = mysql_fetch_array($result); echo ip:.IP.BR; echo cn:.$data[cn].BR; echo cc:.$data[cc]; dbclose($conn); ? HTH !! Ronan e: [EMAIL PROTECTED] t: 01903 739 997 w: www.thelittledot.com The Little Dot is a partnership of Ronan Chilvers and Giles Webberley -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Time input formatting in PHP-12 hour clock
Hi David Comments inline... On 13 Jun,2003 at 10:26 David Shugarts wrote: snip PHP--I need the user to be able to input a time, then validate it as to whether it is complete (e.g., expresses AM or PM and evaluates correctly), then pass it into an INSERT statement into the time field of a database. /snip How about using a radio button for the AM / PM selection on the form? Then if its PM you can simply adjust the hour figure accordingly to convert to 24hr (add 12 or whatever) and then concatenate a string together for the INSERT, eg: HHMMSS. Validating is just a matter of making sure the numbers are sanea few if then's should do the trick. Alternatively use select dropdowns on the form to only allow a user to choose a valid time. Its up to them to get the RIGHT time, of course !!! If you go the validation route I think I would probably use a little javascript snippet to validate the numbers before the form is submitted. Personal preference really... Does this help at all? Ronan e: [EMAIL PROTECTED] t: 01903 739 997 w: www.thelittledot.com The Little Dot is a partnership of Ronan Chilvers and Giles Webberley -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Total Values with MySQL
Hi Shaun Comments inline... On 02 Jun,2003 at 16:18 shaun shaun wrote: Hi, Is it possible to get MySQL to total the values of a select statement, say 'SELECT ColumnName FROM Table WHERE ColumnName = '1'' Say I have three values in ColumnName all of '1' then can I get MySQL to return 3? Try the SUM() function as in:- SELECT SUM(ColumnName) AS Total FROM Table WHERE ColumnName = '1'; ?? Thanks for your help No problem Ronan e: [EMAIL PROTECTED] t: 01903 739 997 w: www.thelittledot.com The Little Dot is a partnership of Ronan Chilvers and Giles Webberley -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] mysqldump
Hi buttoz Here's how I did it ... function get_script($dbname) { $cmd = /usr/bin/mysqldump -u._DBUSER. -p._DBPASS. ._MDFLAGS. .$dbname; $script = `$cmd`; return $script; } _MDFLAGS is a constant which holds the flags you want to pass to mysqldump ... I commonly use -c and -add-drop-table. _DBUSER and _DBPASS are also constants containing the username and password mysqldump needs to connect to mysql with (funnily enough!!). Note there is NO space between the -p flag and the password. HTH Ronan e: [EMAIL PROTECTED] t: 01903 739 997 w: www.thelittledot.com The Little Dot is a partnership of Ronan Chilvers and Giles Webberley On 31 May,2003 at 12:51 buttoz buttoz wrote: hi, i want to backup mysql database. i use mysqldump command . when i use this command from server (win2000) , command promt its work fine. but when run this command (mysqldump) from php file, it creat backup file but with zero size. what can i do , help me? thanks, zuhear -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] query string
Hi Ian Comments inline... On 01 Jun,2003 at 23:20 Ian Fingold wrote: snip link will look like this fant_stnd3.php?week=1team=silly team but again, my problem is that it's cutting off the team value when there is a space in the string.. /snip Don't allow spaces in the string ? Are we getting team name from a select list ? If so change the values returned. Are the team names typed in ? If so use javascript to replace spaces with underscores. Can you work along those lines ? Ronan e: [EMAIL PROTECTED] t: 01903 739 997 w: www.thelittledot.com The Little Dot is a partnership of Ronan Chilvers and Giles Webberley -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] redirecting to a page
Comments inline ... On 30 May,2003 at 10:25 Hutchins, Richard wrote: snip Redirect(www.mypage.com); /snip You'll need around the url I reckon as in Redirect(www.mypage.com); ;-) Ronan e: [EMAIL PROTECTED] t: 01903 739 997 w: www.thelittledot.com The Little Dot is a partnership of Ronan Chilvers and Giles Webberley -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Operation must use an updateable query
It got me several times, even after I'd worked out the problem Many's the slip twixt database and script !! ;-) Ronan e: [EMAIL PROTECTED] t: 01903 739 997 w: www.thelittledot.com The Little Dot is a partnership of Ronan Chilvers and Giles Webberley On 29 May,2003 at 10:55 Chad Chad wrote: I can't believe it was that simple. Thank You So much Ronan! -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] User auth system
Hi folks Does anyone know of an OS user authentication and management framework (OS cos I want to study the code!!!). I'm in the process of putting together some definitions and specs for an open source php/mysql project and need to develop a robust and flexible user auth / validation system modelled somewhat on the linux permissions model. Does anyone know of a project that has a really good, secure user system? Cheers Ronan e: [EMAIL PROTECTED] t: 01903 739 997 w: www.thelittledot.com The Little Dot is a partnership of Ronan Chilvers and Giles Webberley -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] printing with php
Crikey !! However, this is still server-side, and the impression I got was that the printing was going to be client-side. I may be wrong though, in which case, this seems to do the trick just fine BTW, its also on the PHP site ... printer module. Ronan e: [EMAIL PROTECTED] t: 01903 739 997 w: www.thelittledot.com The Little Dot is a partnership of Ronan Chilvers and Giles Webberley On 28 May,2003 at 15:55 Catta Rodolphe wrote: Good start but in french, hope u know a little of French but it is not hard to understand ! ### tire de : function.printer-set-option.html printer_set_option 6.84.31 printer_set_option()Configure la connexion a` l'imprimante [ Exemples avec printer_set_option ] CVS uniquement bool printer_set_option ( resource handle , int option , mixed value ) printer_set_option modifie les options suivantes pour la connexion a` l'imprimante handle . handle doit e^tre une ressource d'imprimante valide. option peut e^tre l'une des constantes suivantes : * PRINTER_COPIES : indique le nombre de copie a` imprimer. value doit e^tre un entier . * PRINTER_MODE : spe'cifie le type de data (text, raw' ou emf), value doit e^tre une chai^ne de caracte'res . * PRINTER_TITLE : spe'cifie le nom du document, value doit e^tre une chai^ne de caracte'res . * PRINTER_ORIENTATION : spe'cifie l'orientation du papier, value peut e^tre PRINTER_ORIENTATION_PORTRAIT ou PRINTER_ORIENTATION_LANDSCAPE * PRINTER_RESOLUTION_Y : spe'cifie la re'solution en ordonne'es, en DPI, value doit e^tre un entier . * PRINTER_RESOLUTION_X : spe'cifie la re'solution en absisse, en DPI, value doit e^tre un entier . * PRINTER_PAPER_FORMAT : spe'cifie un format de papier pre'de'fini : donnez a` value la valeur de PRINTER_FORMAT_CUSTOM si vous souhaitez utiliser un format de papier personnalise', gra^ce aux constantes PRINTER_PAPER_WIDTH et PRINTER_PAPER_LENGTH . value peut alors e^tre l'une des constantes suivantes : o PRINTER_FORMAT_CUSTOM : vous laisse spe'cifier le format de papier. o PRINTER_FORMAT_LETTER : spe'cifie le format standard letter (8 1/2 par 11 pouces (2.54cm)). o PRINTER_FORMAT_LETTER : spe'cifie le format standard legal (8 1/2 par 14 pouces (2.54cm)). o PRINTER_FORMAT_A3 : spe'cifie le format standard A3 (297 par 420 millime`tres). o PRINTER_FORMAT_A4 : spe'cifie le format standard A4 (210 par 297 millime`tres). o PRINTER_FORMAT_A5 : spe'cifie le format standard A5 (148 par 210 millime`tres). o PRINTER_FORMAT_B4 : spe'cifie le format standard B4 (250 par 354 millime`tres). o PRINTER_FORMAT_B5 : spe'cifie le format standard B5 (182 par 257 millime`tres). o PRINTER_FORMAT_FOLIO : spe'cifie le format standard FOLIO (8 1/2 par 13 pouces (2.54cm)). * PRINTER_PAPER_LENGTH : si PRINTER_PAPER_FORMAT vaut PRINTER_FORMAT_CUSTOM , PRINTER_PAPER_LENGTH spe'cifie une longueur personnalise'e de papier, en millime`tres. value doit e^tre un entier . * PRINTER_PAPER_WIDTH : si PRINTER_PAPER_FORMAT vaut PRINTER_FORMAT_CUSTOM , PRINTER_PAPER_WIDTH spe'cifie une largeur personnalise'e de papier, en millime`tres. value doit e^tre un entier . * PRINTER_SCALE : spe'cifie le facteur de mise a` l'e'chelle du document. La taille physique de la page imprime'e est alors mise a` l'e'chelle avec un facteur e'gal a` value /100. Par exemple, si vous donnez un facteur d'e'chelle de 50, l'impression sera de la moitie' de la taille du document original. value doit e^tre un entier . * PRINTER_BACKGROUND_COLOR : spe'cifie la couleur de fond pour le contexte actuel. value doit e^tre une chai^ne de caracte'res contenant une couleur au format RGB hexade'cimal : par exemple, 005533. * PRINTER_TEXT_COLOR : spe'cifie la couleur du texte pour ce contexte d'imprimante. value doit e^tre une chai^ne de caracte'res contenant une couleur au format RGB hexade'cimal : par exemple, 005533. * PRINTER_TEXT_ALIGN : spe'cifie l'alignement du etxte pour le contexte d'imprimante. value peut e^tre une combinaison, avec l'ope'rateur OR, des constantes suivantes : o PRINTER_TA_BASELINE : le texte sera aligne'e sur la ligne de base. o PRINTER_TA_BOTTOM : le texte sera aligne'e sur la ligne de fond. o PRINTER_TA_TOP : le texte sera aligne'e sur la ligne de haut. o PRINTER_TA_CENTER : le texte sera aligne'e au centre. o PRINTER_TA_LEFT : le texte sera aligne'e a` gauche. o PRINTER_TA_RIGHT : le texte sera aligne'e a` droite. Exemple avec printer_set_option ?php $handle = printer_open(); printer_set_option($handle, PRINTER_SCALE, 75); printer_set_option($handle, PRINTER_TEXT_ALIGN, PRINTER_TA_LEFT); printer_close($handle); ? Ronan Chilvers wrote: Hi Carol I don't think you'll strike lucky here !! PHP is a server-side, not client-side language and therefore doesn't know anything about the client's printer or its settings. You can use PHP to create a page that is formatted nicely and will therefore print well. There are also
Re: [PHP-DB] Operation must use an updateable query
Hi Chad Make sure the webserver has write permissions on the Access database file. Cheers Ronan e: [EMAIL PROTECTED] t: 01903 739 997 w: www.thelittledot.com The Little Dot is a partnership of Ronan Chilvers and Giles Webberley On 28 May,2003 at 23:02 Chad Chad wrote: I am using PHP 4.2.3 on a Window 2K Pro box with Service Pack 3 installed. I am trying to access an MS Access 2000 database through the MS Access ODBC driver. When I try to write to a table, using an INSERT INTO command (see below) I get the following error: Operation must use an updateable query The SQL statement that I am trying to odbc_exec is as follows: INSERT INTO testtab ([user_name],[subject],[comment]) VALUES ('chad','test data','Comment x') This works when I run it as a query in MS Access, and I've been able to get info from the database using SELECT statements. I'm just not sure what the Operation must us and updatable query means. I actually found the same error in the help files for MS Access and this is what it says, but to me it is just as unintelligible as the message: This error occurs when the current query's Update To row includes a field from either a crosstab query or select query in which an aggregate (total) was calculated for the field (using either the Totals row or a domain function in the Field row). To update a field using the aggregate of another field, calculate the aggregate in the update query itself, not a different query. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] printing with php
Hi Carol I don't think you'll strike lucky here !! PHP is a server-side, not client-side language and therefore doesn't know anything about the client's printer or its settings. You can use PHP to create a page that is formatted nicely and will therefore print well. There are also some IE specific CSS properties that you can use to control line breaks, etc. (These may be supported by other 6+ series browsers but I'm not sure). As far as controlling the printer, you're out of luck. You can use JavaScript to start the printing, so that people don't have to go via the menu, but again this isn't well supported in older 4.x series browsers. If anyone knows different I'd be really interested to know about it, but I think you're out of luck!! PHP is good, but it can't do the impossible (unless you have the php_do_impossible.so module installed!!). ;-) Ronan e: [EMAIL PROTECTED] t: 01903 739 997 w: www.thelittledot.com The Little Dot is a partnership of Ronan Chilvers and Giles Webberley On 28 May,2003 at 14:03 carol carol wrote: Hy there, I have a problem... I have a linux server, apache, php, and mysql instaled. I can make all kind of queries but I nedd to printed them (using the browser but not usig file-print-page setup-) in a specified format (like A3, landscape, border=2cm, and all kind of things like that... usin php) Could enyone help? Thanks! -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Double Trouble!
On 25 May,2003 at 17:34 S. Cole wrote: I can't seem to find out why I am getting two copies of the same entry in my database. snip I reckon you're calling the script twice. Can we see the scripts that you call this one from ? /snip === print Pending Payment - Adding to Databasebr; $query = INSERT INTO payments (subscr_id, pmt_date, txn_id, exchange_rate, amt_paid, payment_status, pending_reason, payer_email, snip Ronan e: [EMAIL PROTECTED] t: 01903 739 997 w: www.thelittledot.com The Little Dot is a partnership of Ronan Chilvers and Giles Webberley -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Can't Insert more than 1 record
Hi KJ On 03 Apr,2003 at 22:18 Keven Jones wrote: snip attempt after the 1st fails. I have to delete the existing row in order to add a new record. /snip Sounds like you have auto-incremented unique indices to me - are you always trying to insert with an index of 1 ? Without seeing the code its hard to say snip Anyone know what I am doing incorrectl? KJ /snip -- Ronan e: [EMAIL PROTECTED] t: 01903 739 997 w: www.thelittledot.com The Little Dot is a partnership of Ronan Chilvers and Giles Webberley -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] How to use a Class?
Hi Shantanu To be honest you'd be far better off doing this manually, rather than using someone elses code - quite important bits and pieces of sql and db access logic which you'll need to learn, but On 03 Apr,2003 at 20:18 Shantanu Oak wrote: snip the following code mentioned on the page, $mysearch = new MysqlSearch; $mysearch-setidentifier(MyPrimaryKey); $mysearch-settable(MyTable); $results_array = $mysearch-find($mysearchterms); I am getting the text array() as a result. /snip This is php telling you that the variable is of the array type, ie: it is a variable containing many indexed values. BTW, have you changed the setidentifier() and settable() values to the correct ones for your db ? (just checking). snip Can someone explain to me how to use it and get result. /snip A handy utility function is var_dump(). This will echo out the contents of any variable type. So to display the contents of your $results_array variable you would do:- ?php echo pre; var_dump($results_array); echo/pre; ? That'll show you the contents of the array and what its structure looks like. Displaying it in a controlled form is just a matter of finding out the structure of the array and looping through it using one of php's many many loop constructs / array access functions. Have a read about arrays on www.php.net - they are very useful once you get the hang of them ... ;-) snip Shantanu Oak [EMAIL PROTECTED] http://www.shantanuoak.com Cheers -- Ronan e: [EMAIL PROTECTED] t: 01903 739 997 w: www.thelittledot.com The Little Dot is a partnership of Ronan Chilvers and Giles Webberley -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Creating a directory listing
Hi David Some comments inline ... On 02 Apr,2003 at 10:22 David McGregor wrote: snip I'm trying to do this for a web site. I need to list the contents of each directory on a site to perhaps 4 levels deep (only html files). I've almost got a function going where it starts at the top level and checks each file to see if IT is a directory and if so chdir() to that /snip ?php define(START,/home/ronan/Projects); define(BRK,nbsp;nbsp;nbsp;nbsp;); function getDirFiles($dirPath,$depth=0) { if ($handle = opendir($dirPath)) { while (false !== ($file = readdir($handle))) { // Make sure we aren't using this dir or the dir above us if ($file != . $file != ..) { // Print $file, indented by depth*BRK echo str_repeat(BRK,$depth).trim($dirPath./.$file).br; if (is_dir($dirPath./.$file)) { // If $file is a directory recursively call the function to // list the files for that directory getDirFiles($dirPath./.$file,($depth+1)); } } } // Close the dir handle closedir($handle); } } getDirFiles(START); ? That will give you an indented directory tree listing from the START directory, using BRK to create the indents. This has no directory limit and will simply work through the entire tree. Is that what you're after ? You could build in your search logic pretty easily I think, with an 'if (preg_match()) {}' type structure. This is a modified version of johnpipi at hotmail.com's code at http://www.php.net/manual/en/ref.dir.php snip Thanks for any assistance. Dave /snip -- Ronan e: [EMAIL PROTECTED] t: 01903 739 997 w: www.thelittledot.com The Little Dot is a partnership of Ronan Chilvers and Giles Webberley -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Sharing variable values among PHP files
Coments inline... snip On 01 Apr,2003 at 10:04 Mustafa Ocak wrote: You can store the value in a session variable session_start(); if (isset($_HTTP_SESSION_VARS['your_variable_name'])) { /snip Rather than using isset() you may need to use session_is_registered(). This is specifically for checking the existence of a session variable. I would do something like ?php // need this on all pages where you want to work with // the session var session_start(); // Check for the existence of the session var and create // it if it doesn't exist if (!session_is_registered(ses_username)) { session_register(ses_username); } // Are we getting a form var thru ? if so pop it into the session var if (isset($frm_username)) { $ses_username = $frm_username; } // then in your scripts you can do do_my_amazing_function($ses_username); ? As long as you have session_start() at the beginning of each script, $ses_username is now available across scripts. snip $value=$_HTTP_SESSION_VARS['your_variable_name']; //get the value }else{ $_HTTP_SESSION_VARS['your_variable_name']=new value; } /snip Hope that helps. -- Ronan e: [EMAIL PROTECTED] t: 01903 739 997 w: www.thelittledot.com The Little Dot is a partnership of Ronan Chilvers and Giles Webberley -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Sharing variable values among PHP files
Hi Leif On 01 Apr,2003 at 3:07 Leif K-Brooks wrote: snip Please, please, PLEASE don't give advice! If you don't know the answer, DON'T COMMENT! The method you posted is for register_gkobals on, which it won'tr always (and shouldn't be)! /snip No need to be rude ... its very easy to adjust this code so that it doesn't need register_globals. The logic of the code is the point. I simply offered an alternative way of handling session vars that I feel is cleaner and clearer. Please don't go off the deep end with replies. There's no need. If you felt that you should point out the register_globals issue, then a simple 'Don't forget register_globals needs to be turned on here and it probably isn't' would suffice. While I am not a php guru (as you seem to be) I have been working with it for a long time commercially and do have some experience, so I am occasionally able to offer pointers on people's questions and offer such advice freely, in the hope that it will help. Lets all be adults, shall we ? You don't get any points for flaming. We're here to learn not fight. snip Ronan Chilvers wrote: Coments inline... snip On 01 Apr,2003 at 10:04 Mustafa Ocak wrote: You can store the value in a session variable /snip -- Ronan e: [EMAIL PROTECTED] t: 01903 739 997 w: www.thelittledot.com The Little Dot is a partnership of Ronan Chilvers and Giles Webberley -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Entering a Query
Hi Shaun Comments inline ... On 01 Apr,2003 at 13:37 shaun shaun wrote: snip Hi, I would be very interested to see an example of how it would be possible to enter a query into a text area and the results of the query displayed on the next page, similar to PHP admin I guess, are they any examples out there? /snip Fairly simple At its most basic you have a form :- form method=post action=do_query.php textarea name=myquery/textarea input type=submit name=submit value=Submit /form which posts to your php page :- ?php $sql = $HTTP_POST_VARS[myquery]; // You'll need code here to sanitize the query and make sure there's // no nasty surprises in it. // then simply create your connection (assuming a function here) $conn = db_connect(); $result = mysql_query($sql); // Code to display the result here ? You would need to have some checking involved for the query. Also, as always, apply 'least privilege' to the user the query runs as. I don't know what you're using it for but be VERY careful - I would only allow selects here unless you're sure you know how it will be used. Hope this helps ... :-) -- Ronan e: [EMAIL PROTECTED] t: 01903 739 997 w: www.thelittledot.com The Little Dot is a partnership of Ronan Chilvers and Giles Webberley -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Entering a Query
Hi Shaun On 01 Apr,2003 at 14:28 shaun shaun wrote: snip thanks for your reply, What i was after is a way of representing the data, given that you dont know what columns will be displayed and how many rows etc? /snip One way to do it is to load the data into arrays. I generally use mysql_fetch_array() to access recordsets. This delivers both an Indexed and associative array of values. You can modify this behaviour with the last argument. Assuming you want to preserve the keys (which will be the column headings in the sql result), in mysql_fetch_array() you would use the constant MYSQL_ASSOC. You could do something like this:- ?php // Assume you have a db connection if (($result = mysql_query($sql_from_textarea))===0) { // Drop out gracefully } // Check we have some rows if (mysql_num_rows($result)) { // We have some rows so load up an array with your recordset // Start a counter $counter=0; // Step thru the recordset while($data = mysql_fetch_array($result,MYSQL_ASSOC)) { // loop through the current row, listing keys and values while (list($k,$v)=each($data)) { // create a new array member of the form // $myarray[index][key]=value $myarray[$counter][$k]=$v; } // increment the index counter $counter++; } // Now we have an array which looks like the data so we can // display it (you could do the keys bit up above as well // actually) // get the keys from the first element - safe cos we know // we have at least one row $keys = array_keys($myarray[0]); // Now a standard loop through to first display the keys // as headings then the data $html = tabletr; // Create a row of headings for ($i=0;$icount($keys);$i++) { $html .= tdb.$keys[$i]./b/td; } // Now loop through the rest of the data while (list(,$v)=each($myarray)) { $html .= tr; // Send keys array pointer back to the start reset($keys); while(list(,$b)=each($keys)) { $html.= td.$v[$b]./td; } $html .= /tr; } $html .= /table; echo $html; } else { // Drop out gracefully } ? Does that all make sense ? Basically, you grab the recordset into an array whose dimensions you can loop through. Then you grab the keys from an array element to give you the columns. Then you loop through, using the keys as your guide for when to change to a new row. There may well be a more elegant way to do it but this would be where I would start !! snip I would only be looking to do 'selects' so how can i ensure that this is the only type of query run? /snip Make sure the user you run the script as, only has select permissions on the db you are using. Once again, hope this helps ;-) -- Ronan e: [EMAIL PROTECTED] t: 01903 739 997 w: www.thelittledot.com The Little Dot is a partnership of Ronan Chilvers and Giles Webberley -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Sharing variable values among PHP files
Hi Leston In case Leif, doesn't get back to you, here's a way to do it (inline). Similar to what Mustafa has already posted:- On 01 Apr,2003 at 8:35 Leston Drake wrote: snip For us novices, can you please share how you would do this with register_globals off? /snip snip ?php // need this on all pages where you want to work with // the session var session_start(); // Check for the existence of the session var and create // it if it doesn't exist if (!session_is_registered(ses_username)) { /snip // Check if session var is set if (!isset($HTTP_SESSION_VARS[ses_username])) { // check to see if we have a posted var from form if (isset($HTTP_POST_VARS[frm_username])) { // We have no session var and a form var // waiting for us $HTTP_SESSION_VARS[ses_username]=$HTTP_POST_VARS[frm_username]; } } // Now $HTTP_SESSION_VARS[ses_username] exists and contains // the username snip session_register(ses_username); } // Are we getting a form var thru ? if so pop it into the session var /snip You can shorten $HTTP_SESSION_VARS to $_SESSION if PHP version 4.1.0. Cheers -- Ronan e: [EMAIL PROTECTED] t: 01903 739 997 w: www.thelittledot.com The Little Dot is a partnership of Ronan Chilvers and Giles Webberley -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Warning: Unable to jump to row...
Hi Ben Comments inline On 31 Mar,2003 at 13:46 Benjamin Trépanier wrote: snip border=0 ? $i!=$id_news_ $id= mysql_result($req,$i,id); $titre = mysql_result($req,$i,titre); $date = mysql_result($req,$i,date); $heure = mysql_result($req,$i,heure); $heure = str_replace(:,h,$heure); $news = stripslashes(trim(mysql_result($req,$i,news))); /snip You should try using one of mysql_fetch_array() / mysql_fetch_row() to step through the recordset. Something along the lines of ?php while ($data = mysql_fetch_array($req)) { // handling code for each row here using references like this $id = $data[id]; $titre = $data[titre]; echo trtd$id/tdtd$titre/td/tr\n; // \n above to keep the html source reasonably tidy } ? snip ? I want that my script show the content of the rows corresponding to my Variable called: Id_News_ So the variable is moving well but when the scirpt is running and go to display the row this code happend: Warning: Unable to jump to row number X /snip Hope this helps. -- Ronan e: [EMAIL PROTECTED] t: 01903 739 997 w: www.thelittledot.com The Little Dot is a partnership of Ronan Chilvers and Giles Webberley -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] PHP for apache logging to mysql
Hi Paul On 27 Mar,2003 at 12:44 Paul Burney wrote: snip Hope that helps. YMMV. TMTOWTDI. /snip It did !! I had tried a direct pipe, but had neglected the all important semi-colon on the insert !!! Is this reasonably efficient on your production server ? Do you have any problems with it ? Also, how are you dealing with growing table sizes ? Do you summarise out data to sub tables ? Or do you limit the date range and periodically dump stuff that is out of range ? Part of the reason for using Perl / PHP, etc was to allow the log data to be filtered and sorted prior to inserting to the db. This would then allow automatic summarising so you could maintian host tables, request tables, etc and limit the size of the main transfer log tables. My approach to the queries thus far has been to keep different 'reports' (which essentially narrow down to individual SQL queries) in a db. A user picks a report, the SQL is selected and run and the data is then displayed (also playing with JPGraph to produce some nice charts). Works quite well and means that adding a new 'report' is simply a matter of adding a row in the reports table. snip Sincerely, Paul Burney http://paulburney.com/ ?php while ($self != asleep) { $sheep_count++; } ? /snip Once again, thanks for the tips !! -- Ronan e: [EMAIL PROTECTED] t: 01903 739 997 w: www.thelittledot.com The Little Dot is a partnership of Ronan Chilvers and Giles Webberley -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] multiple queries in PHP to mysql database.
Hi Jerry Inline comments On 28 Mar,2003 at 12:31 JeRRy JeRRy wrote: How can I update 2 tables at once if a match occours from information inputed into a PHP form. How about turning this around and re-organising the data a little? Why not have a single score table with references to a central username / pw / id table. Table 1 - users id username password Table 2 - scores id userid game1 game2 game3 game4 ... overall You can then do UPDATE table2 SET game1=game1+1, overall=overall+1 WHERE userid = $userid Getting a results table would then be a single query... Does this help at all ? Hopefully I've grasped enough of the concept to not make a complete fool of myself ! Jerry -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Putting a string into a variable.
Hi Tim Comments inline... $stringarray[] = array(); $i = 0; while ( $i 6 ){ $stringarray[$i] = table cellspacing=\0\trtd.$this-differentarray[0] [0]./td/tr/table; } When I echo $stringarray[1] it comes up empty... Is there a special trick to get a You're not incrementing $i. You need $i++ in your while loop. thanks, /Tim -- Ronan e: [EMAIL PROTECTED] t: 01903 739 997 w: www.thelittledot.com The Little Dot is a partnership of Ronan Chilvers and Giles Webberley -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Generate thumbnails from MySql database
On 27 Mar,2003 at 13:46 Dave Carrera wrote: Hi all Hi Dave I have a database holding file locations of images on my system. This works fine and shows them fine on a webpage. I was wondering if it is possible to generate and automatic thumbnail from the original image (all jpegs) so that I can click the thumbnail to see the larger image. I know I can make a small image and a large images and store and retrieve those but I was just wondering if it is possible to do auto thumbnails from the array of images. You could write yourself a little script to generate a thumbnail on the fly ... use an img tag like img src='thumbnailscript.php?image=thisimage.jpg' You could simply cycle through your array and let the thumbnail script create the image for you each time. Have to say, not very efficient ... you'd be far better off either doing an upload form that creates your thumbnails at upload or writing a little PHP daemon that sits on the server and chucks back the image data when queried... I would resize on upload...still automatic and only do it once rather than every page load...you'll bring your server to its knees if you have a large site with lots of hits (or even a small site with lots of hits). BTW, everyone else, hallo ! Ronan here, I do php / mysql / gd / flash stuff to build db driven sites. Also use templating and OOP with an in house content management system to provide generic back end administration sites for our clients. -- Ronan e: [EMAIL PROTECTED] t: 01903 739 997 w: www.thelittledot.com The Little Dot is a partnership of Ronan Chilvers and Giles Webberley -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] PHP for apache logging to mysql
Hi folks Ronan here. Just joined the list. I do PHP / MYSQL / GD / HTML / JavaScript / Flash stuff, building db driven sites, content management systems, etc. I also use PHP as a scripting langauge on my servers - its generally great. However I have a little problem which someone might have come across or be able to shed some light on. I want to pipe logs directly from apache into mysql. At the moment I can do this using a perl script that does this sort of thing:- script #!/usr/bin/perl [ DB CONNECTIONS etc ] while (STDIN) { [ DO DB INSERTS HERE ] } [ DB OBJ CLOSURE etc ] /script I'm doing this in PHP:- script #!/usr/bin/php -q ?php $fp = fopen(/dev/stdin,r); $inputfp = fopen(./input.txt,a); function write_input($input, $inputfp) { [ DB INSERTS HERE ] } $input = fread($fp,4096); // 4096 arbitrary value for testing write_input($input,$inputfp); fclose($inputfp); fclose($fp); ? /script Works great if I manually pipe from ls or something (ie: ls ~/ | phplog.php) but nothing happens when piping from apache. I reckon that the problem lies in the file pointer reading - perl seems to keep the pointer (ie: pipe) open while php seems to close the pipe after each fread(). Any clues ??? Cheers -- Ronan e: [EMAIL PROTECTED] t: 01903 739 997 w: www.thelittledot.com The Little Dot is a partnership of Ronan Chilvers and Giles Webberley -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php