php-general Digest 5 May 2012 22:35:42 -0000 Issue 7802

2012-05-05 Thread php-general-digest-help

php-general Digest 5 May 2012 22:35:42 - Issue 7802

Topics (messages 317793 through 317804):

Re: Calculating driving distance between UK postcodes
317793 by: tamouse mailing lists

Re: function
317794 by: tamouse mailing lists
317797 by: Jim Giner
317801 by: tamouse mailing lists
317802 by: tamouse mailing lists

Re: PHP  Emacs
317795 by: tamouse mailing lists

Re: Retrieve pages from an ASP driven site
317796 by: tamouse mailing lists

Re: Running through an enormous SQL file
317798 by: Brian Dunning
317800 by: tamouse mailing lists

Re: get content rss feed
317799 by: tamouse mailing lists

Re: code deployment through php
317803 by: tamouse mailing lists

Re: PHP  Database Problems -- Code Snippets
317804 by: Matijn Woudt

Administrivia:

To subscribe to the digest, e-mail:
php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
php-gene...@lists.php.net


--
---BeginMessage---
On Fri, May 4, 2012 at 9:18 AM, Terry Ally (Gmail) terrya...@gmail.com wrote:
 Google works in Javascript extensively - not a language with which I
 have in-depth experience hence my reason for asking for PHP solution.

 For example the following will get me a JSON output with the distance in
 Kms and time. I don't know how to get PHP to read this information and
 extract just the distance. I need the distance so that I can calculate cost
 of a trip.

 form id=google action=
 http://maps.googleapis.com/maps/api/distancematrix/json; method=get
 input type=text name=origins value= /
 input type=text name=destinations value= /
 input type=hidden name=sensor value=false
 input type=hidden name=submitted value=1
 bra type=submit
 onClick=document.getElementById('google').submit()strongstrongGet
 Distance/strong/strong/a
 /form

Using Google Maps API is pretty straight-forward. You don't need to
set up a form or a use a POST to get the info. This page should
describes how to use a standard GET query to get the info you want:

 https://developers.google.com/maps/documentation/distancematrix/ 

Setting up the proper URL to call, you can activate it using
file_get_contents provided you have allow_url_fopen set to true in
php.ini. (Do make sure to check for possible errors returned.)

You can get the response back as either JSON or XML, both of which PHP
can parse into useful data structures:

 http://us.php.net/manual/en/function.json-decode.php 

 http://us.php.net/manual/en/book.simplexml.php 
---End Message---
---BeginMessage---
On Thu, May 3, 2012 at 9:12 PM, Ron Piggott
ron.pigg...@actsministries.org wrote:
 I need to access a FUNCTION I programmed within a different FUNCTION.  Are 
 these able to be passed like a variable?  Or are they able to become like a 
 $_SESSION variable in nature?  How am I able to do this?

 I am essentially programming:

 ===
 function name( $flag1, $flag2 ) {

 # some PHP

 echo name_of_a_different_function( $flag1 , $flag2 );

 }
 ===

 The error I am receiving is “Call to undefined function 
 name_of_a_different_function”

Where is name_of_a_different_function defined? If it is somewhere in
the same file as name, that shouldn't be a problem, provided it is
defined in the same namespace/scope as name. If it is defined in a
different file, you need to include that file before you make the echo
statement.

For example:

function func1 ($flag1, $flag2) {

   # blah blah

   echo func2($flag1, $flag2);
}

function func2 ($flag1, $flag2) {

   #blah blah

   return some string value;
}

in the same file should be just fine. It doesn't really matter what
order func1 and func2 are declared in.

However, if func2 is defined in some_other_file.php, you need to
include it in this_file.php (where func1 is defined) first:

this_file.php:
include('some_other_file.php');

function func1 ($flag1, $flag2) {

   #blah blah

   echo func2 ($flag1, $flag2);
}


some_other_file.php:
function func2 ($flag1, $flag2) {

   #blah blah

   return some string value;
}

If func2 is a method for an object/class, you'll have to access it
that way in func1:

this_file.php:
include('MyClass.php');
function func1 ($flag1, $flag2) {

   # blah blah, instantiate object?
   $myobj = new MyClass();

   echo $myobj-func2 ($flag1, $flag2);
}

MyClass.php:
class MyClass
{
   function func2 ($flag1, $flag2) {

  #blah blah
  return some string value;
   }
}
---End Message---
---BeginMessage---
But the OP says function is defined inside a different function.  Your 
theories to a solution don't fit that problem.
tamouse mailing lists tamouse.li...@gmail.com wrote in message 
news:cahuc_t-416_-lpcn3mo8qqxwrh4pnq5fmwouhwpdk+hmkgh...@mail.gmail.com...
On Thu, May 3, 2012 at 9:12 PM, Ron Piggott
ron.pigg...@actsministries.org wrote:

Where is 

Re: [PHP] PHP Database Problems -- Code Snippets

2012-05-05 Thread Matijn Woudt
On Thu, May 3, 2012 at 4:20 PM, Ethan Rosenberg eth...@earthlink.net wrote:
 At 06:47 PM 5/2/2012, Matijn Woudt wrote:

 On Wed, May 2, 2012 at 11:43 PM, Ethan Rosenberg eth...@earthlink.net
 wrote:  Dear list -   Sorry for the attachment. Â Here are code snippets
 --- Ethan, I don't want to sound rude, but it appears to me you don't have
 any understanding of what you're doing. It might help if you understand what
 the code is doing... Let me explain.   GET THE DATA FROM INTAKE3:   Â  Â
 function handle_data()  Â  Â {  Â  Â  Â  global $cxn;  Â  Â  Â  $query =
 select * from Intake3 where  1;   Â  Â
  if(isset($_Request['Sex']) trim($_POST['Sex']) != '' ) $_Request does not
 exists, you're looking for $_REQUEST. And why are you mixing $_REQUEST and
 $_POST here?  Â  Â  Â  {  Â  Â  Â  Â  Â  Â if ($_REQUEST['Sex'] === 0) 
 Â  Â  Â  Â  Â  Â {  Â  Â  Â  Â  Â  Â  Â  $sex = 'Male';  Â  Â  Â  Â  Â  Â
 }  Â  Â  Â  Â  Â  Â else  Â  Â  Â  Â  Â  Â {  Â  Â  Â  Â  Â  Â  Â  $sex =
 'Female';  Â  Â  Â  Â  Â  Â }  Â  Â  Â  }   Â  Â } What is the point of
 the handle_data function above? It doesn't do anything.  Â  Â
 $allowed_fields = array  Â  Â  Â  ( Â 'Site' =$_POST['Site'], 'MedRec' =
 $_POST['MedRec'], 'Fname' =  $_POST['Fname'], 'Lname' = $_POST['Lname'] ,
  Â  Â  Â  Â  Â  Â  'Phone' = $_POST['Phone'] , 'Sex' = $_POST['Sex'] Â ,
 'Height'  = $_POST['Height'] Â );   Â  Â if(empty($allowed_fields))  Â
  Â {  Â  Â  Â  Â  Â echo ouch;  Â  Â }   Â  Â $query = select * from
 Intake3  where  1 ;     Â foreach ( $allowed_fields as $key = $val )
  Â  Â {  Â  Â  Â  if ( (($val != '')) )   Â  Â {  Â  Â  Â  $query .= 
 AND ($key  = '$val') ;    Â }    Â  Â  $result1 = mysqli_query($cxn,
 $query);  Â  Â } First, this will allow SQL injections, because you insert
 the values directly from the browser. Second, you should move the last line
 ($result1=...), outside of the foreach loop, now you're executing the query
 multiple times. Third, you should check if $result1 === FALSE, in case the
 query fails   Â  Â $num = mysqli_num_rows($result1);  Â  Â if(($num =
 mysqli_num_rows($result1)) == 0) Doing the same thing twice?  Â  Â {  ? 
 Â  Â br /br /centerbp style=color: red; font-size:14pt; No
 Records  Retrieved #1/center/b/style/p  ?php  Â  Â exit();  Â
  Â }   DISPLAY THE INPUT3 DATA:   THIS SEEMS TO BE THE ROUTINE THAT
 IS FAILINGÂ  Â centerbSearch Results/b/centerbr /   Â
  Â centertable border=4 cellpadding=5 cellspacing=55 Â rules=all
  Â frame=box  Â  Â tr class=\heading\  Â  Â thSite/th  Â  Â
 thMedical Record/th  Â  Â thFirst Name/th  Â  Â thLast Name/th
  Â  Â thPhone/td  Â  Â thHeight/td  Â  Â thSex/td  Â  Â
 thHistory/td  Â  Â /tr   ?php   Â  Â  Â  while ($row1 =
 mysqli_fetch_array($result1, MYSQLI_BOTH))  Â  Â  Â  {  Â  Â  Â  Â  Â  Â
 print_r($_POST); Doesn't really make sense to print $_POST here..  Â  Â  Â
  Â  Â  Â  Â  global $MDRcheck;  Â  Â  Â  Â  Â  Â  Â  $n1++;  Â  Â  Â  Â  Â
  Â  Â  echo br /n1 br /;echo $n1;  Â  Â  Â  Â  Â  Â {  Â  Â  Â  Â  Â
  Â  Â  if (($n1  2)  ($MDRcheck == $row1[1]))  Â  Â  Â  Â  Â  Â  Â  { 
 Â  Â  Â  Â  Â  Â  Â  Â  Â  Â echo 2== Â ;  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â
 echo $MDRcheck;  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â echo td $row1[0] /td\n;
  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â echo td $row1[1] /td\n;  Â  Â  Â  Â  Â
  Â  Â  Â  Â  Â echo td $row1[2] /td\n;  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â
 echo td $row1[3] /td\n;  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â echo td
 $row1[4] /td\n;  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â echo td $row1[5]
 /td\n;  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â echo td $row1[6] /td\n;  Â
  Â  Â  Â  Â  Â  Â  Â  Â  Â echo td $row1[7] /td\n;  Â  Â  Â  Â  Â  Â
  Â  Â  Â  Â echo /tr\n;  Â  Â  Â  Â  Â  Â  Â  }  Â  Â  Â  Â  Â  Â  Â
  elseif (($n1  2)  ($MDRcheck != $row1[1]))  Â  Â  Â  Â  Â  Â  Â  {  Â
  Â  Â  Â  Â  Â  Â  Â  Â  Â echo 2!= Â ;   Â  Â  Â  Â  Â  Â  Â  Â  Â  Â
 echo $MDRcheck;Â  Â  Â  Â  Â  Â  Â  Â  Â  Â continue; continue
 doesn't do anything here.  Â  Â  Â  Â  Â  Â  Â  }  Â  Â  Â  Â  Â  Â  Â
  elseif ($n1 == 2)  Â  Â  Â  Â  Â  Â  Â  {   Â  Â  Â  Â  Â  Â  Â  Â  Â  Â
 define( MDR , Â $row1[1]);  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â echo br /row1
 br;echo $row1[1];  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â echo tr\n;   Â  Â
  Â  Â  Â  Â  Â  Â  Â  Â $_GLOBALS['mdr']= $row1[1];  Â  Â  Â  Â  Â  Â  Â  Â
  Â  Â $_POST['MedRec'] = $row1[1]; You're not supposed to set variables in
 $_POST...  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â $MDRold = $_GLOBALS['mdr']; It
 appears you want the old value of mdr, if so, then you should do this before
 you set it again 2 lines above..  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â echo td
 $row1[0] /td\n;  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â echo td $row1[1]
 /td\n;  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â echo td $row1[2] /td\n;  Â
  Â  Â  Â  Â  Â  Â  Â  Â  Â echo td $row1[3] /td\n;  Â  Â  Â  Â  Â  Â
  Â  Â  Â  Â echo td $row1[4] /td\n;  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â
 echo td $row1[5] /td\n;  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â echo td
 $row1[6] /td\n;  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â echo td $row1[7]
 /td\n;  Â  Â  Â  Â  Â  Â  Â  Â  Â  

[PHP] I'm missing something

2012-05-05 Thread Jim Giner
I have a discrepancy in the number of elements in my arrays and can't see 
why.

Here is some code:
Note the lines with the ***

*** $plyrs = 0;
 unset($plyrnames_ar);
 unset($js_names);
 unset($js_seeds);
*** $rows = mysql_num_rows($qrslts);
***echo in mysql there are $rows rowsbr;
 while ($row = mysql_fetch_array($qrslts))
 {   // build the name value here
  $mi = ($row['MI']=='') ? '' :  .$row['MI'];
  $nm = $row['LastName']., .$row['FirstName'].$mi;
  if ($row['srtdbls']=='X')
  {
   $mi = ($row['partMI']=='') ? '' :  .$row['partMI'];
   $nm .= /.$row['partLN']., .$row['partFN'].$mi;
  }
***  $plyrs++;
  $plyrnames_ar[$nm] = $row['Draw_pos'];
 }
*** echo before sort there are .count($plyrnames_ar). in 
plyrsnames_arbr;
 ksort($plyrnames_ar);
 foreach ($plyrnames_ar as $nm=$sd)
 {
  $js_names[] = $nm;
  $js_seeds[] = $sd;
 }
*** echo plyrs is $plyrs and there are .count($js_names). entries in 
js_rnames and .count
***($plyrnames_ar). entries in plyrnames_ar and .count($js_seeds). in 
js_seeds;
 exit();

The problem is that my $plyrs field comes up 18, while in truth there are 
only 17 rows of data in my database.
All of the other array-size counts echo out as being only 17, but my $rows 
and $plyrs fields come up as 18.  I was having problems with my javascript 
showing an undefined array element and took a bit o time to determine what 
it was and where it was happening.

Questions - does mysql_num_rows return a extra row that somehow doesn't get 
processed in the while loop? And if it does how come the counter ($plyrs) 
that I put into the loop comes up higher than it should.? 



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



Re: [PHP] I'm missing something

2012-05-05 Thread Matijn Woudt
On Sun, May 6, 2012 at 12:38 AM, Jim Giner jim.gi...@albanyhandball.com wrote:
 I have a discrepancy in the number of elements in my arrays and can't see
 why.

 Here is some code:
 Note the lines with the ***

 *** $plyrs = 0;
  unset($plyrnames_ar);
  unset($js_names);
  unset($js_seeds);
 *** $rows = mysql_num_rows($qrslts);
 ***echo in mysql there are $rows rowsbr;
  while ($row = mysql_fetch_array($qrslts))
  {   // build the name value here
  $mi = ($row['MI']=='') ? '' :  .$row['MI'];
  $nm = $row['LastName']., .$row['FirstName'].$mi;
  if ($row['srtdbls']=='X')
  {
   $mi = ($row['partMI']=='') ? '' :  .$row['partMI'];
   $nm .= /.$row['partLN']., .$row['partFN'].$mi;
  }
 ***  $plyrs++;
  $plyrnames_ar[$nm] = $row['Draw_pos'];
  }
 *** echo before sort there are .count($plyrnames_ar). in
 plyrsnames_arbr;
  ksort($plyrnames_ar);
  foreach ($plyrnames_ar as $nm=$sd)
  {
  $js_names[] = $nm;
  $js_seeds[] = $sd;
  }
 *** echo plyrs is $plyrs and there are .count($js_names). entries in
 js_rnames and .count
 ***($plyrnames_ar). entries in plyrnames_ar and .count($js_seeds). in
 js_seeds;
  exit();

 The problem is that my $plyrs field comes up 18, while in truth there are
 only 17 rows of data in my database.
 All of the other array-size counts echo out as being only 17, but my $rows
 and $plyrs fields come up as 18.  I was having problems with my javascript
 showing an undefined array element and took a bit o time to determine what
 it was and where it was happening.

 Questions - does mysql_num_rows return a extra row that somehow doesn't get
 processed in the while loop? And if it does how come the counter ($plyrs)
 that I put into the loop comes up higher than it should.?



My guess would be that you end up with 2 rows having the same $nm,
overwriting the value that's already in $plyrnames_ar.

- Matijn

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



Re: [PHP] I'm missing something

2012-05-05 Thread Jim Giner


My guess would be that you end up with 2 rows having the same $nm,
overwriting the value that's already in $plyrnames_ar.

- Matijn

Genius at work!  Thanks - I'll look into that. 



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



Re: [PHP] I'm missing something

2012-05-05 Thread Jim Giner
Yup that was it!  Something I knew would happen during my design, but forgot 
to code for now.

Jim Giner jim.gi...@albanyhandball.com wrote in message 
news:e2.dc.30075.c6ea5...@pb1.pair.com...


 My guess would be that you end up with 2 rows having the same $nm,
 overwriting the value that's already in $plyrnames_ar.

 - Matijn
 
 Genius at work!  Thanks - I'll look into that.
 



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



Re: [PHP] I'm missing something

2012-05-05 Thread Matijn Woudt
On Sun, May 6, 2012 at 12:53 AM, Jim Giner jim.gi...@albanyhandball.com wrote:
 Yup that was it!  Something I knew would happen during my design, but forgot
 to code for now.

 Jim Giner jim.gi...@albanyhandball.com wrote in message
 news:e2.dc.30075.c6ea5...@pb1.pair.com...


 My guess would be that you end up with 2 rows having the same $nm,
 overwriting the value that's already in $plyrnames_ar.

 - Matijn
 
 Genius at work!  Thanks - I'll look into that.


Jim,

Two things:
1) You should bottom post on this (probably any) mailing list.
2) You can avoid these errors if you define unique fields in your database.

- Matijn

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