Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #9615

Re: testing for source to use

From Scott Johnson <noonehome@chalupasworld.com>
Newsgroups comp.lang.php
Subject Re: testing for source to use
Date 2013-05-24 15:12 -0700
Organization A noiseless patient Spider
Message-ID <knoocq$ijt$1@dont-email.me> (permalink)
References <1ij92ldq768qa.1x65hwkghfrwa.dlg@40tude.net> <knnmpb$bcj$1@dont-email.me> <1v457my8r62xi$.1sjc4errknv11$.dlg@40tude.net>

Show all headers | View raw


On 5/24/2013 12:22 PM, richard wrote:
> On Fri, 24 May 2013 05:38:44 -0700, Scott Johnson wrote:
>
>> On 5/23/2013 8:23 PM, richard wrote:
>>
>>>
>>> $result = mysql_query("SELECT avid FROM A$year WHERE id = $number");
>>> if (!$result) { echo 'Could not run query: ' . mysql_error();  exit; }
>>> $vid = mysql_fetch_row($result);
>>>
>>> echo $vid[0];
>>> $v=$vid[0];
>>> $v1=substr($v,0,1);
>>>
>>>
>>> $yt="http://www.youtube.com/watch?v=".$vid[0];
>>>
>>> if ($v1="/"){$yt="http://mroldies.net".$vid[0];}
>>> echo "<br />".$yt;
>>>
>>
>> Richard.....*lost for words*
>>
>> *refound*
>>
>> Brother you really should start keeping notes of these simple errors.
>> You keep revisiting the errors that people do when they first start
>> using PHP.
>>
>> Many in the NG have taken their own time to point these out and give you
>> good advice, and to not learn or write the solutions down is being very
>> disrespectful to those peoples times, which is why you probably get many
>> disparaging comments.
>>
>> I have a very bad memory myself but I keep a notebook and revisit it
>> whenever I run into an error to ensure I (or someone else) have not
>> already solved it previously.
>>
>> Just a suggestion.
>>
>> Scotty
>
> FYI, I found that I could use the substr() function to solve my problem
> with.
> With everything that I had read, there was one very important thing every
> one of these writers left out!
> That being, the natural mind says the first character is "1" and therefore
> the number 1 should be used if you want to start at the begining.
> e.g.
> substr("123",1,1)
> The output is "1" correct?
> Wrong!
> It is "2".
> To output the "1", the correct code is substr("123",0,1).
> Why?
> I suspect that this is due to the fact the substring is treated as an array
> and the array always begins with [0] by default.
>


Yes that is the expected return/functionality of substr(), especially if 
you read the 'manual' on the function.  It specifies that 0 is the base.

Always remember (or write it down).  php.net is your friend.

Back to comp.lang.php | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

testing for source to use richard <noreply@example.com> - 2013-05-23 23:23 -0400
  Re: testing for source to use "Beauregard T. Shagnasty" <a.nony.mous@example.invalid> - 2013-05-24 03:36 +0000
  Re: testing for source to use JohnT <john@example.com> - 2013-05-24 10:17 +0000
  Re: testing for source to use Doug Miller <doug_at_milmac_dot_com@example.com> - 2013-05-24 10:50 +0000
    Re: testing for source to use Tim Streater <timstreater@greenbee.net> - 2013-05-24 12:53 +0100
      Re: testing for source to use The Natural Philosopher <tnp@invalid.invalid> - 2013-05-24 13:23 +0100
      Re: testing for source to use Doug Miller <doug_at_milmac_dot_com@example.com> - 2013-05-24 13:10 +0000
        Re: testing for source to use richard <noreply@example.com> - 2013-05-24 15:10 -0400
          Re: testing for source to use Doug Miller <doug_at_milmac_dot_com@example.com> - 2013-05-24 21:41 +0000
  Re: testing for source to use Scott Johnson <noonehome@chalupasworld.com> - 2013-05-24 05:38 -0700
    Re: testing for source to use richard <noreply@example.com> - 2013-05-24 15:22 -0400
      Re: testing for source to use Scott Johnson <noonehome@chalupasworld.com> - 2013-05-24 15:12 -0700

csiph-web