php-general Digest 25 Oct 2008 22:28:28 -0000 Issue 5755
Topics (messages 282421 through 282429):
Re: Building an array, kind of?
282421 by: Tom Shaw
clear a mysql table
282422 by: Ronald Wiplinger (Lists)
282423 by: tedd
282424 by: Richard Heyes
282425 by: Daniel P. Brown
282428 by: Yeti
Query-within-a-query with mySQL/PHP
282426 by: Rob Gould
282427 by: Greg Bowser
Re: what's the difference in the following code?
282429 by: Chris Shiflett
Administrivia:
To subscribe to the digest, e-mail:
[EMAIL PROTECTED]
To unsubscribe from the digest, e-mail:
[EMAIL PROTECTED]
To post to the list, e-mail:
[EMAIL PROTECTED]
----------------------------------------------------------------------
--- Begin Message ---
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" ?
--- End Message ---
--- Begin Message ---
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.
--- End Message ---
--- Begin Message ---
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
--- End Message ---
--- Begin Message ---
> 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)
--- End Message ---
--- Begin Message ---
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.
<?php
$sql = "TRUNCATE TABLE cash";
mysql_query($sql) or die(mysql_error());
?>
--
</Daniel P. Brown>
http://www.parasane.net/ [New Look]
[EMAIL PROTECTED] || [EMAIL PROTECTED]
--- End Message ---
--- Begin Message ---
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
--- End Message ---
--- Begin Message ---
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.
--- End Message ---
--- Begin Message ---
>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.
--- End Message ---
--- Begin Message ---
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/
--- End Message ---