Re: [PHP] Building an array, kind of?

2008-10-25 Thread Martijn Korse

Or, if your mysql version allows it:

SELECT 1, GROUP_CONCAT(some_col) FROM history GROUP BY 1 LIMIT 0,16

That would take away the need to create a comma seperated string in php,
because mysql will have already done it for you ;-)


Dan Shirah wrote:
> 
> TGIF?
> 
> Apparently my brain isn't working this Friday.
> 
> I'm trying to query my table to get the first 16 ID's.  I then want
> to assign the ID's to a variable and have them comma seperated.
> 
> // My query to select the first 16 rows
> $get_charges2 = "SELECT FIRST 16 * FROM history WHERE id = '$id";
> 
> // Executing the query
>  $charge_result2 = ifx_query ($get_charges2, $connect_id);
> 
> How would I assign the result to a variable?
> 
> For instance, say my query returns rows like:
> 
> 1234
> 1235
> 1236
> 1237
> 1238
> 1239
> 
> How would I go about putting that in a variable to equal
> "1234,1235,1236,1237,1238,1239" ?
> 
> 


-
http://devshed.excudo.net http://devshed.excudo.net 
-- 
View this message in context: 
http://www.nabble.com/Building-an-array%2C-kind-of--tp20151654p20162597.html
Sent from the PHP - General mailing list archive at Nabble.com.


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



RE: [PHP] Building an array, kind of?

2008-10-25 Thread Tom Shaw
Here's another easy way.

$data = array();
while ($row = ifx_fetch_row ($charge_result2, "NEXT"){
$data[] = $row['id'];
}
ifx_free_result ($res_id);

$comma_sep = implode(', ', array_values($data));

Thomas Shaw
[EMAIL PROTECTED]

-Original Message-
From: Dan Shirah [mailto:[EMAIL PROTECTED] 
Sent: Friday, October 24, 2008 9:52 AM
To: PHP LIST
Subject: [PHP] Building an array, kind of?

TGIF?

Apparently my brain isn't working this Friday.

I'm trying to query my table to get the first 16 ID's.  I then want
to assign the ID's to a variable and have them comma seperated.

// My query to select the first 16 rows
$get_charges2 = "SELECT FIRST 16 * FROM history WHERE id = '$id";

// Executing the query
 $charge_result2 = ifx_query ($get_charges2, $connect_id);

How would I assign the result to a variable?

For instance, say my query returns rows like:

1234
1235
1236
1237
1238
1239

How would I go about putting that in a variable to equal
"1234,1235,1236,1237,1238,1239" ?


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



[PHP] clear a mysql table

2008-10-25 Thread Ronald Wiplinger (Lists)
I need to clear a table (cache) from a database based on the database size.

Our web site uses cached pages. Our webhost only allow us 100 MB
storage. Usually the database is just 10 MB, but when a search engine
crawls our calendar, then the storage is quickly 108 MB. The system
reports then mathematically correct: Space left on database -8MB !!!

I plan therefore a web page, which is triggered by cron every hour and
will just clear the table.

Can I use just:
mysql_query("DELETE FROM cash")
or die(mysql_error());


or do I need to loop through all records? or is there a better solution?

How can I get the database size?

bye

R.


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



Re: [PHP] clear a mysql table

2008-10-25 Thread tedd

At 11:02 PM +0800 10/25/08, Ronald Wiplinger (Lists) wrote:

Can I use just:
mysql_query("DELETE FROM cash")
or die(mysql_error());


If you need to delete some cash, please look in my direction.  :-)

Cheers,

tedd

--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

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



Re: [PHP] clear a mysql table

2008-10-25 Thread Richard Heyes
> or is there a better solution?

Yes, look for a better hosting firm. 100Mb is paltry these days.

-- 
Richard Heyes

HTML5 Graphing for FF, Chrome, Opera and Safari:
http://www.rgraph.org (Updated October 25th)

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



Re: [PHP] clear a mysql table

2008-10-25 Thread Daniel P. Brown
On Sat, Oct 25, 2008 at 11:02 AM, Ronald Wiplinger (Lists)
<[EMAIL PROTECTED]> wrote:
>
> I plan therefore a web page, which is triggered by cron every hour and
> will just clear the table.
>
> Can I use just:
> mysql_query("DELETE FROM cash")
> or die(mysql_error());

Please remember that GOOGLE is your friend, so STFW before asking
here.  Also, note that there's a specific list for database issues,
PHP-DB --- http://php.net/mailinglists

In direct response to your question, you're looking for the
TRUNCATE command.



-- 

http://www.parasane.net/ [New Look]
[EMAIL PROTECTED] || [EMAIL PROTECTED]

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



[PHP] Query-within-a-query with mySQL/PHP

2008-10-25 Thread Rob Gould
This is somewhat complicated, so I'll try to give examples with real- 
world data.


Basically, I'd like to know how I could take data like this, from mySQL:


2006
Liberty School
Central Coast, California, Central Coast, USA
Chardonnay

2006
Liberty School
Paso Robles, California, Central Coast, USA
Syrah

2006
Liberty School
California, California, USA
Cabernet Sauvignon

2005
Liberty School
Paso Robles, California, Central Coast, USA
Cabernet Sauvignon

2005
Liberty School
Central Coast, California, Central Coast, USA
Chardonnay

2005
Liberty School
California, California, USA
Cabernet Sauvignon

2005
Liberty School
California, California, USA
Zinfandel

2005
Liberty School
California, California, USA
Syrah

2005
Liberty School
Paso Robles, California, Central Coast, USA
Cabernet Sauvignon

2005
Liberty School
Paso Robles, California, Central Coast, USA
Syrah

2004
Liberty School
California, California, , USA
Cabernet Sauvignon

2004
Liberty School
Paso Robles, California, Central Coast, USA
Cabernet Sauvignon

etc



and create a query which would return the data like this:


Liberty School Chardonnay (USA, California, Central Coast) 2007,  
2006, 2005, 2004, 2003, 2002, 2001, 2000, 1997, 1985
Liberty School Cabernet Sauvignon (USA, California) 2006, 2005, 2004,  
2003, 2002, 2001, 2000, 1999, 1998, 1997, 1996, 1995, 1990, 1982, 1976
Liberty School Cabernet Sauvignon (USA, California, Central Coast,  
Paso Robles) 2005, 1993
Liberty School Cabernet Sauvignon (USA, California, Sonoma County)  
2003, 1984



Basically I somehow need to do a GROUP BY producer, and yet somehow  
at the same time, find out all the matching vintages (years), that go  
along with that group and return them the same time the producer  
group is returned.


Right now, my PHP/SQL query string is:

$query = 'SELECT * FROM wine WHERE MATCH(producer, varietal,  
appellation, designation, region, vineyard, subregion, country,  
vintage) AGAINST ( "' . $combostring . '" IN BOOLEAN MODE ) ORDER BY  
' . $orderby . ', producer ASC LIMIT 0,100';


This produced the first list you see at the top of this email.

Any help is greatly appreciated.

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



Re: [PHP] Query-within-a-query with mySQL/PHP

2008-10-25 Thread Greg Bowser
>Basically I somehow need to do a GROUP BY producer, and yet somehow at the
same time, find out all the matching vintages (years), that go along with
that group and return them the same time the producer group is returned.

If I'm following you correctly, you have a column "year" in your group, and
rather than returning just one year in your result set, you would like every
year in the group.

This can be accomplished with the group_concat() [1] function:

SELECT field1,field2,field3, GROUP_CONCAT(distint year) as years FROM table
WHERE conditions GROUP BY foo;

[1]
http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html#function_group-concat

-- GREG.


Re: [PHP] clear a mysql table

2008-10-25 Thread Yeti
I used to have a similar problem
What I did was to define a max number of cashed pages.
So when reaching that number I simply did it the FIFO way

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



Re: [PHP] what's the difference in the following code?

2008-10-25 Thread Chris Shiflett

On Oct 23, 2008, at 2:10 PM, Jochem Maas wrote:


The order is reversed, so if $host has a non-zero length, it is not
escaped.


first thing that I noticed, second wondering why no charset was  
specified,

thirdly was wondering why it's not plain:

$host = htmlentities($host);

but nonetheless your point stands, :-)


Yeah, fair enough.

To my credit, I also noticed the problem without spending more than a  
second or two on that line, but I also recognized how it could be  
missed. To me, it's similar to missing when someone calls a functions  
and gets the order of arguments wrong. You can tell what they meant,  
so the error doesn't stand out as boldly. Perhaps subconsciously you  
anticipate that they're right, because in most of the code, they are.


The challenge of being perfect is why I've developed a number of tools  
to help me out. I'm going to release one of the best of these as open  
source in a few months. I might mention that on this list, since it  
seems appropriate. Hopefully no one will mind the "advertising" too  
much. :-)


now about that charset ... your blog post uses UTF-7 to demonstrate  
the
potential for problems ... but htmlentities() doesn't support that  
charset,
or at least not according to the docs, in fact the list of supported  
charsets

is quite limited, out of curiosity what would your recommendation be
if one is faced with a having 'htmlentize' a string encoded in UTF-7  
or

some other charset not supported by htmlentities()?


That's a good question. I would probably convert it to something like  
UTF-8, escape it, then convert it back. I've never faced this  
situation, and the scenario I was recreating in my post was when  
someone attacked Google using UTF-7. Google didn't actually want to  
support that character encoding.


If you specify ISO-8859-1 in your Content-Type header, it's actually  
fine to omit the character encoding in htmlentities(), because it uses  
that by default. (Also, not all mismatches are exploitable.) However,  
it always catches my eye, because it demonstrates a lax treatment of  
character encoding in general. I like to see it explicitly declared  
everywhere.


a second question: strip_tags() doesn't have a charset parameter,  
how does
it manage to cope without knowing the input string encoding? or does  
it

not and is it actually vulnerable to maliciously encoded input?


My guess would be that it doesn't cope. :-) I never use strip_tags(),  
so someone else might be able to offer a much better answer.


Hope that helps, and thanks for the discussion.

Chris

--
Chris Shiflett
http://shiflett.org/

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



Re: [PHP] clear a mysql table

2008-10-25 Thread Micah Gersten


Ronald Wiplinger (Lists) wrote:
> I need to clear a table (cache) from a database based on the database size.
>
> Our web site uses cached pages. Our webhost only allow us 100 MB
> storage. Usually the database is just 10 MB, but when a search engine
> crawls our calendar, then the storage is quickly 108 MB. The system
> reports then mathematically correct: Space left on database -8MB !!!
>
> I plan therefore a web page, which is triggered by cron every hour and
> will just clear the table.
>
> Can I use just:
> mysql_query("DELETE FROM cash")
> or die(mysql_error());
>
>
> or do I need to loop through all records? or is there a better solution?
>
> How can I get the database size?
>
> bye
>
> R.
>
>   
Perhaps you should not have search engines index your calendar.

Thank you,
Micah Gersten
onShore Networks
Internal Developer
http://www.onshore.com


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



[PHP] Replacing with f*ck and f*cking

2008-10-25 Thread Ryan S
Hey!
I'm just trying to replace some of the more bad words with their slightly 
censored counterparts like so

$bad_words = array(/*Well you know the words so am not going to write them 
here*/);
$bad_words_replacements = array("f*ck", "f*cking");
$comment = str_replace("$bad_words",$bad_words_replacements,  $comment);

My question is this, for just two words its fine to use the above, but a pal 
tells me that if using a lot of words (eg: 15) and the $comment is big then it 
can take quite some time and be a bit of a processing strain as well because 
php first checks the first word from the good list against all the 15 words in 
the bad list against the comment then moves to the second word etc.

Is this really bad processing wise and would you recommend any other way of 
doing this?
The other question i have is, wont "f*ck" catch "f*cking" as well? so should i 
delete the longer f*cking?

I'm not really trying to stop people swearing... just trying to make it not 
"jump out" so much, this was the poster is happy coz i have not censored him to 
bits and the reader should be a bit happy coz its a bit decent.

Thanks!
R


  

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



Re: [PHP] Replacing with f*ck and f*cking

2008-10-25 Thread Andrew Barnett
Maybe you should look at the source code of an open source project that can
already do this such as phpBB.  I'm not exactly sure where to find it in the
phpBB code though.

Andrew


2008/10/26 Ryan S <[EMAIL PROTECTED]>

> Hey!
> I'm just trying to replace some of the more bad words with their slightly
> censored counterparts like so
>
> $bad_words = array(/*Well you know the words so am not going to write them
> here*/);
> $bad_words_replacements = array("f*ck", "f*cking");
> $comment = str_replace("$bad_words",$bad_words_replacements,  $comment);
>
> My question is this, for just two words its fine to use the above, but a
> pal tells me that if using a lot of words (eg: 15) and the $comment is big
> then it can take quite some time and be a bit of a processing strain as well
> because php first checks the first word from the good list against all the
> 15 words in the bad list against the comment then moves to the second word
> etc.
>
> Is this really bad processing wise and would you recommend any other way of
> doing this?
> The other question i have is, wont "f*ck" catch "f*cking" as well? so
> should i delete the longer f*cking?
>
> I'm not really trying to stop people swearing... just trying to make it not
> "jump out" so much, this was the poster is happy coz i have not censored him
> to bits and the reader should be a bit happy coz its a bit decent.
>
> Thanks!
> R
>
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>