php-general Digest 15 Nov 2010 10:52:16 -0000 Issue 7037

Topics (messages 309481 through 309493):

Re: String manipulation
        309481 by: a...@ashleysheridan.co.uk
        309482 by: D. Dante Lorenso
        309483 by: Ron Piggott
        309492 by: Tamara Temple

PHP loop to issue sql insert
        309484 by: Rick Dwyer
        309485 by: Simon J Welsh
        309486 by: Rick Dwyer

Returning values from a function
        309487 by: Ron Piggott
        309489 by: 惠新宸

Retrieving function values
        309488 by: Ron Piggott
        309490 by: Bastien Koert
        309491 by: Tamara Temple
        309493 by: Richard Quadling

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


----------------------------------------------------------------------
--- Begin Message ---
What about something like this:

$pos = (strpos(' ', $string, 76))?strpos(' ',$string, 76):strlen($string);

Thanks,
Ash
http://www.ashleysheridan.co.uk

----- Reply message -----
From: "Ron Piggott" <ron.pigg...@actsministries.org>
Date: Sun, Nov 14, 2010 20:48
Subject: [PHP] Re: String manipulation
To: <php-gene...@lists.php.net>


How would I write an IF statement that looks for the first space space (“ “) 
left of the 76th character in a string or <br>, which ever comes first --- OR 
the end of the string (IE the string is less than 76 characters long? I 
specifically want is it’s character position in the string.  Ron

The Verse of the Day
“Encouragement from God’s Word”
http://www.TheVerseOfTheDay.info

--- End Message ---
--- Begin Message ---
On 11/14/10 2:48 PM, Ron Piggott wrote:
How would I write an IF statement that looks for the first space space (“ “) left of 
the 76th character in a string or<br>, which ever comes first --- OR the end of 
the string (IE the string is less than 76 characters long? I specifically want is 
it’s character position in the string.  Ron

... but you sound like you are looking for the 'wordwrap' function.

-- Dante

----------
D. Dante Lorenso
da...@lorenso.com
972-333-4139

--- End Message ---
--- Begin Message ---
I am receiving this error:

Warning: strpos() [function.strpos]: Offset not contained in string

I have never seen it before, what do I do?  I made one change to it though, you 
didn’t have <br> in it before so I changed the syntax to:

$pos = (strpos(' ', $activity_description_result, 
76))?strpos('<br>',$activity_description_result, 
76):strlen($activity_description_result);

Ron



The Verse of the Day
“Encouragement from God’s Word”
http://www.TheVerseOfTheDay.info

From: a...@ashleysheridan.co.uk 
Sent: Sunday, November 14, 2010 4:58 PM
To: Ron Piggott ; php-gene...@lists.php.net 
Subject: Re: [PHP] Re: String manipulation

What about something like this:

$pos = (strpos(' ', $string, 76))?strpos(' ',$string, 76):strlen($string);

Thanks,
Ash
http://www.ashleysheridan.co.uk

----- Reply message -----
From: "Ron Piggott" <ron.pigg...@actsministries.org>
Date: Sun, Nov 14, 2010 20:48
Subject: [PHP] Re: String manipulation
To: <php-gene...@lists.php.net>


How would I write an IF statement that looks for the first space space (“ “) 
left of the 76th character in a string or <br>, which ever comes first --- OR 
the end of the string (IE the string is less than 76 characters long? I 
specifically want is it’s character position in the string.  Ron

The Verse of the Day
“Encouragement from God’s Word”
http://www.TheVerseOfTheDay.info


--- End Message ---
--- Begin Message ---

On Nov 14, 2010, at 4:48 PM, Ron Piggott wrote:

Warning: strpos() [function.strpos]: Offset not contained in string


Shouldn't you check the length of the string before giving it the offset?

From: a...@ashleysheridan.co.uk

$pos = (strpos(' ', $string, 76))?strpos(' ',$string, 76):strlen($string);

Doesn't strpos(' ',$string,76) look for the first space to the *right* of position 76?

I really don't know how to do this except by exploding the string and shooting the array of characters, keeping mind of the last space found before you get to slot 75.

----- Reply message -----
From: "Ron Piggott" <ron.pigg...@actsministries.org>

How would I write an IF statement that looks for the first space space (“ “) left of the 76th character
^ left

in a string or <br>, which ever comes

first --- OR the end of the string (IE the string is less than 76 characters long? I specifically want is it’s character position in the string.



--- End Message ---
--- Begin Message ---
Hello List.

I have a sql command that counts, groups and sorts data from a table. I need to insert the results of that sql command into different table.

My sql SELECT looks like  this:

select count(*) as count, searchkeywords from searchtable group by searchkeywords order by count desc;

and returns records like this:

578     green
254     blue
253     red
253     yellow
118     orange
.... etc.

My PHP looks like this so far:

$sql = "select count(*) as count, searchkeywords from searchtable group by searchkeywords order by count desc"; $result = @mysql_query($sql,$connection) or die("Couldn't execute checkcat query");
$num = mysql_num_rows($result);
echo $num;


The echo is of course returning the total number of records.... not data as listed above.

I know a WHILE statement is to be used here, but can't get it to work.

How do I loop through the above found data, inserting each value as like this:

insert into mytable (count, color) values ("578", "green");
insert into mytable (count, color) values ("254", "blue");
...etc



Thanks,


 --Rick


--- End Message ---
--- Begin Message ---
On 15/11/2010, at 12:47 PM, Rick Dwyer wrote:

> Hello List.
> 
> I have a sql command that counts, groups and sorts data from a table.  I need 
> to insert the results of that sql command into different table.
> 
> My sql SELECT looks like  this:
> 
> select count(*) as count, searchkeywords from searchtable group by 
> searchkeywords order by count desc;
> 
> and returns records like this:
> 
> 578   green
> 254   blue
> 253   red
> 253   yellow
> 118   orange
> .... etc.
> 
> My PHP looks like this so far:
> 
> $sql = "select count(*) as count, searchkeywords from searchtable group by 
> searchkeywords order by count desc";
> $result = @mysql_query($sql,$connection) or die("Couldn't execute checkcat 
> query");
> $num = mysql_num_rows($result);
> echo $num;
> 
> 
> The echo is of course returning the total number of records.... not data as 
> listed above.
> 
> I know a WHILE statement is to be used here, but can't get it to work.
> 
> How do I loop through the above found data, inserting each value as like this:
> 
> insert into mytable (count, color) values ("578", "green");
> insert into mytable (count, color) values ("254", "blue");
> ...etc
> 
> 
> 
> Thanks,
> 
> 
> --Rick

Personally I'll get MySQL to do it for me using: insert into mytable (count, 
color) select count(*) as count, searchkeywords from searchtable group by 
searchkeywords order by count desc (see 
http://dev.mysql.com/doc/refman/5.1/en/insert-select.html for more information 
on INSERT ... SELECT)

Otherwise, you'll want to use mysql_fetch_assoc($result). Examples and 
information can be found at http://php.net/mysql_fetch_assoc
---
Simon Welsh
Admin of http://simon.geek.nz/

Who said Microsoft never created a bug-free program? The blue screen never, 
ever crashes!

http://www.thinkgeek.com/brain/gimme.cgi?wid=81d520e5e

--- End Message ---
--- Begin Message ---

On Nov 14, 2010, at 8:15 PM, Simon J Welsh wrote:

On 15/11/2010, at 12:47 PM, Rick Dwyer wrote:

Hello List.

I have a sql command that counts, groups and sorts data from a table. I need to insert the results of that sql command into different table.

My sql SELECT looks like  this:

select count(*) as count, searchkeywords from searchtable group by searchkeywords order by count desc;

and returns records like this:

578     green
254     blue
253     red
253     yellow
118     orange
.... etc.

My PHP looks like this so far:

$sql = "select count(*) as count, searchkeywords from searchtable group by searchkeywords order by count desc"; $result = @mysql_query($sql,$connection) or die("Couldn't execute checkcat query");
$num = mysql_num_rows($result);
echo $num;


The echo is of course returning the total number of records.... not data as listed above.

I know a WHILE statement is to be used here, but can't get it to work.

How do I loop through the above found data, inserting each value as like this:

insert into mytable (count, color) values ("578", "green");
insert into mytable (count, color) values ("254", "blue");
...etc



Thanks,


--Rick

Personally I'll get MySQL to do it for me using: insert into mytable (count, color) select count(*) as count, searchkeywords from searchtable group by searchkeywords order by count desc (see http://dev.mysql.com/doc/refman/5.1/en/insert-select.html for more information on INSERT ... SELECT)

Wow... I have never heard of the combination of INSERT... SELECT before.... worked perfectly. Thanks.

--Rick


--- End Message ---
--- Begin Message ---
I am writing a string parsing function.


I need to return 3 values from a function:

return $string_to_display;
return $string_to_parse;
return $continue_parsing;

I am not sure how to retrieve these variables.

The Verse of the Day
“Encouragement from God’s Word”
http://www.TheVerseOfTheDay.info

--- End Message ---
--- Begin Message ---
Hi:
  return array(
     'string_to_display' => $string_to_display,
     .....
  );

Best regards

惠新宸     Xinchen Hui
http://www.laruence.com/

On 2010/11/15 11:10, Ron Piggott wrote:

I am writing a string parsing function.


I need to return 3 values from a function:

return $string_to_display;
return $string_to_parse;
return $continue_parsing;

I am not sure how to retrieve these variables.

The Verse of the Day
“Encouragement from God’s Word”
http://www.TheVerseOfTheDay.info

--- End Message ---
--- Begin Message ---
I am writing a custom function and I need to be able to retrieve 3 values from 
it.

string_parse_tool ( $string_to_parse )

The 3 variables I need to retrieve from the function are:

$string_to_parse
$string_to_display
$continue_parsing

I only know how to retrieve 1 variable from a function, not 3.  Could someone 
help me please?

Thank you.

Ron

--- End Message ---
--- Begin Message ---
On Sun, Nov 14, 2010 at 10:12 PM, Ron Piggott
<ron.pigg...@actsministries.org> wrote:
> I am writing a custom function and I need to be able to retrieve 3 values 
> from it.
>
> string_parse_tool ( $string_to_parse )
>
> The 3 variables I need to retrieve from the function are:
>
> $string_to_parse
> $string_to_display
> $continue_parsing
>
> I only know how to retrieve 1 variable from a function, not 3.  Could someone 
> help me please?
>
> Thank you.
>
> Ron

2 options

Pass them back as an array
$data['parse'] = "some value";
$data['display'] = "some value";
$data['continue'] = "some value";

return $data;

or send it back as a delimited string

$data = $parse .'|'. $display .'|'. $continue;

return $data;





-- 

Bastien

Cat, the other other white meat

--- End Message ---
--- Begin Message ---

On Nov 14, 2010, at 9:12 PM, Ron Piggott wrote:

I am writing a custom function and I need to be able to retrieve 3 values from it.


To return multiple values, you have to return an array:

        return array($var1, $var2, $var3);

Then at the calling site, you retrieve them with a list construct:

        list ($var1, $var2, $var3) = function_returning_array($param);



--- End Message ---
--- Begin Message ---
On 15 November 2010 03:12, Ron Piggott <ron.pigg...@actsministries.org> wrote:
> I am writing a custom function and I need to be able to retrieve 3 values 
> from it.
>
> string_parse_tool ( $string_to_parse )
>
> The 3 variables I need to retrieve from the function are:
>
> $string_to_parse
> $string_to_display
> $continue_parsing
>
> I only know how to retrieve 1 variable from a function, not 3.  Could someone 
> help me please?
>
> Thank you.
>
> Ron

Beside the array() return you could ...

function string_parse_tool($string_source, &$string_to_parse,
&$string_to_display, &$continue_parsing) {
}

Now you can use ...
string_parse_tool($string_source, $string_to_parse,
$string_to_display, $continue_parsing);

Depending upon your code, you could drop the first parameter
completely, but that would always overwrite the supplied value with
the return value.
-- 
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY

--- End Message ---

Reply via email to