php-general Digest 2 Jul 2007 12:14:09 -0000 Issue 4880
Topics (messages 258025 through 258028):
Re: Selecting Rows Based on Row Values Being in Array
258025 by: Jim Lucas
Re: Anybody had luck compiling memcache with php6 ?
258026 by: M. Sokolewicz
258027 by: Stut
Re: mail function problem
258028 by: web2.get-telecom.fr
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 ---
kvigor wrote:
Jim,
Please excuse the ignorance, I'm a newbie, but I'm only use to simple
SELECT, INSERT statements.
Your original code: $SQL = "SELECT * FROM my_Table WHERE CONCAT(value1,
value2, value3) IN ('".join("','", $list)."')
This can be broken down into smaller parts so to explain by example.
# This is to clean the input values for the SQL statement
function mysql_clean($value) {
return mysql_real_escape_string($value);
}
# Define your list of values to compare to
$list = array(
'6blue40lbs',
'7orange50lbs',
'8orange60lbs',
'9purple70lbs',
);
# You will want to do something like this with the values of the $list
# array just to make sure they are clean: reference the function above
array_walk($list, 'mysql_clean');
# This will return a string formated like this.
# '6blue40lbs','7orange50lbs','8orange60lbs','9purple70lbs'
$IN_VALUE = "'".join("','", $list)."'";
$SQL = "SELECT *
FROM my_Table
WHERE CONCAT(value1, value2, value3)
IN ({$IN_VALUE})";
# The final query string will look like this
SELECT *
FROM my_Table
WHERE CONCAT(value1, value2, value3)
IN ('6blue40lbs','7orange50lbs','8orange60lbs','9purple70lbs')
# Now run this through your query function and get the results
$results = mysql_query($SQL) OR die('SQL Failure: '.$SQL);
So basically what we have is a comparison that is based off the output
of the CONCAT() function that creates one string out of value1, value2,
value3 and then compares that with each of the values listed within the
parenthesis. the IN (...) part of the SQL statement tells SQL that it
is getting a list of values that it should compare the concat() value
against.
Doing it this way, will allow you to only run one query instead of
running one per value that you want to compare against. As you can
tell, as your data set grows your multiple queries would drag your DB to
a halt
Hope this explains it.
Let me know if you need further explanation.
OK, I get everything up to the ('''.join(''','''$list).''')
I'm guessing that the .join( ). putting together some values, but I don't
know what
also the .join( ). is to be preceded by something... I don't know what.
//Forgive my ignorance, I'll can get it.
Also the .join( ). what is this doing I looked at the PHP and MySQL function
of each, and haven't seen comparable code.
I'm asking because I don't know where we're telling the code to compare the
values.
You stated...
and create one string from them
Where do I give the name to the string?
So this is where I am so far:
$sql = "SELECT* FROM table WHERE CONCAT(size,color,weight) IN( )";
"Jim Lucas" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
K. Hayes wrote:
Will do. Thanks.
----- Original Message ----- From: "Jim Lucas" <[EMAIL PROTECTED]>
To: "kvigor" <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Saturday, June 30, 2007 1:46 AM
Subject: Re: [PHP] Selecting Rows Based on Row Values Being in Array
kvigor wrote:
Hello All,
I'm attempting to return rows from a mysql DB based on this criteria:
I have a list, in the form of an array that I need to compare against
each row
in the table. Where theres a match I need that entire row returned.
e.g. $varListof 3outOf_10Fields = array(6blue40lbs, 7orange50lbs,
8orange60lbs, 9purple70lbs);
The array contains 3 of the db row fields in 1 value. However there are
10 fields/columns in the table.
===============
what table looks like |
===============
size color weight
ROW 1 | value1 | value1 | value1 | value1 | value1 | value1 |
So how could I set up a query that would SELECT the entire row, if the
row contained $varListof 3outOf_10Fields[1].
Open to any suggestions or work arounds. I'm playing with extract()
but code is too crude to even post.
I would suggest approaching the problem with a slightly different
thought.
just have the sql concat() the columns together and then compare.
something like this should do the trick
$list = array(
'6blue40lbs',
'7orange50lbs',
'8orange60lbs',
'9purple70lbs',
);
$SQL = "
SELECT *
FROM my_Table
WHERE CONCAT(value1, value2, value3) IN ('".join("','", $list)."')
";
mysql_query($SQL);
this should take, for each row in the DB, value1 + value2 + value3 and
create one string from them, then it will compare each string in the
IN (...) portion to each entry in the $list array().
Let me know if you need any further help
one other thing, make sure that you run each of the values in the $list
array() through mysql_real_escape_string(). That way it is all nicely
encoded for the SQL statement.
--- End Message ---
--- Begin Message ---
PHP 6 is about as broken as can be, and buggy as hell... why would you
even want to compile it? or extensions for it...?
- Tul
Cathy Murphy wrote:
I am trying to compile memcache 2.1.2 with php6 , but getting errors .
Anybody had luck with this?
Thanks,
Cathy
www.nachofoto.com
--- End Message ---
--- Begin Message ---
M. Sokolewicz wrote:
PHP 6 is about as broken as can be, and buggy as hell... why would you
even want to compile it? or extensions for it...?
1) To help out the developers by testing it
2) To test a project against the next major version
3) For funzies! ;)
Cathy: You might have better luck by contacting the maintainer of that
extension. Failing that the internals list may be able to help, but that
should be a last resort.
-Stut
--
http://stut.net/
Cathy Murphy wrote:
I am trying to compile memcache 2.1.2 with php6 , but getting errors .
Anybody had luck with this?
Thanks,
Cathy
www.nachofoto.com
--- End Message ---
--- Begin Message ---
I've already checked :
- the mail logs : no mail send
- and the apache error and access logs : nothing except this :
192.168.0.1 - - [02/Jul/2007:14:07:22 +0200] "GET /~eeeeee/mail.php
HTTP/1.1" 200 49291 "-" "Mozilla/5.0 (Windows; U; Windows NT 5.1; fr;
rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4"
192.168.0.1 - - [02/Jul/2007:14:07:22 +0200] "GET
/~eeeeee/mail.php?=PHPE9568F34-D428-11d2-A769-00AA001ACF42 HTTP/1.1" 200
2524 "http://mysite.domain.do/~eeeeee/mail.php" "Mozilla/5.0 (Windows;
U; Windows NT 5.1; fr; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4"
192.168.0.1 - - [02/Jul/2007:14:07:22 +0200] "GET
/~eeeeee/mail.php?=SUHO8567F54-D428-14d2-A769-00DA302A5F18 HTTP/1.1" 200
2813 "http://mysite.domain.do/~eeeeee/mail.php" "Mozilla/5.0 (Windows;
U; Windows NT 5.1; fr; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4"
192.168.0.1 - - [02/Jul/2007:14:07:22 +0200] "GET
/~eeeeee/mail.php?=PHPE9568F35-D428-11d2-A769-00AA001ACF42 HTTP/1.1" 200
2146 "http://mysite.domain.do/~eeeeee/mail.php" "Mozilla/5.0 (Windows;
U; Windows NT 5.1; fr; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4"
Chris a écrit :
[EMAIL PROTECTED] wrote:
Hi,
I'm running PHP 5.2.3 on Solaris 10 (AMD64).
My mail function doesn't send any mail, the return value of mail
function is false...
But sendmail_path value is OK in php.ini, and I've tried to send a
mail with sendmail on console with the same user (the apache user),
and everything's ok...
Does anyone have solution ?
Check your mail logs and your apache logs to see if any errors are
showing up.
--- End Message ---