php-general Digest 7 Jul 2006 20:41:06 -0000 Issue 4227
Topics (messages 239191 through 239201):
Re: Web service in PHP
239191 by: nicolas figaro
combine implode() and array_keys() to get a string of key names
239192 by: Dave M G
239193 by: Jochem Maas
239194 by: Dimiter Ivanov
239195 by: Janet Valade
Video in PHP
239196 by: Leonard Burton
239198 by: tg-php.gryffyndevelopment.com
239200 by: Richard Lynch
Re: [PHP-WIN] Dynamic HTML table sort with PHP
239197 by: tg-php.gryffyndevelopment.com
239199 by: Vandegrift, Ken
Re: Startinga shell process with a life of its own
239201 by: Richard Lynch
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 ---
Pham Huu Le Quoc Phuc a écrit :
Hi!
Hi,
I want to build a Web Service in PHP.
cool !
Could you give me some explain about this problem.
Have any framework of Web service in PHP?
could you give us some infos about the "web service" you'd like to build ?
Please help me!
N F
--- End Message ---
--- Begin Message ---
PHP List,
I've got a series of associative arrays that contain simple string
values that I want to insert into my database.
In each array, the names of the keys correspond to the column names
in the database table. The values stored in the array are, of course,
the values that I want to insert into the columns.
So, I want to set up a function where I can pass the array as an
argument, and it will construct the MySQL statement using the keys for
column names, and array values for insert values.
Within the function, the query looks like this:
$query = "INSERT INTO table (" . $columns . ") VALUES = (" . $values
. ")";
Assuming that the array argument passed to the function is called
$array, converting the array values to the insert values is pretty easy:
$values = implode(", ", $array);
But in the case of using the array keys for column names, it's not
so easy:
$columns = implode(", " array->keys($array));
I know that code above doesn't work, because, as described in the
manual, array keys returns a list of the numerical indexes along with
the string indexes. Something like this:
Array
(
[0] => column1
[1] => column2
[2] => column3
)
At least, that's what it looks like if it's just echoed out.
Is there a way I can strip out the relevant column names to be more
like this:
"column1, column2. column3"
Thank you for any advice.
--
Dave M G
--- End Message ---
--- Begin Message ---
Dave M G wrote:
> PHP List,
>
> I've got a series of associative arrays that contain simple string
> values that I want to insert into my database.
>
> In each array, the names of the keys correspond to the column names
> in the database table. The values stored in the array are, of course,
> the values that I want to insert into the columns.
>
> So, I want to set up a function where I can pass the array as an
> argument, and it will construct the MySQL statement using the keys for
> column names, and array values for insert values.
>
> Within the function, the query looks like this:
> $query = "INSERT INTO table (" . $columns . ") VALUES = (" . $values
> . ")";
>
> Assuming that the array argument passed to the function is called
> $array, converting the array values to the insert values is pretty easy:
> $values = implode(", ", $array);
>
> But in the case of using the array keys for column names, it's not so
> easy:
> $columns = implode(", " array->keys($array));
>
> I know that code above doesn't work, because, as described in the
> manual, array keys returns a list of the numerical indexes along with
> the string indexes. Something like this:
>
> Array
> (
> [0] => column1
> [1] => column2
> [2] => column3
> )
>
> At least, that's what it looks like if it's just echoed out.
>
> Is there a way I can strip out the relevant column names to be more
> like this:
>
> "column1, column2. column3"
>
> Thank you for any advice.
I'll assume you 'data' array only contains associative keys for simpilicity,
here we go:
function davesMakeValueSafeForDBInsertionFunc($v)
{
if (is_null($arg)) return 'NULL';
if (is_numeric($arg)) return $arg;
return "'".mysql_real_escape_string($arg)."'";
}
function davesFunkyDBElementQuoterFunc($elName)
{
return "`{$elName}`";
}
$data = array(
'col1' => 1,
'col2' => null,
'col3' => "yadda yadda",
);
$columns = join(',', array_map('davesFunkyDBElementQuoterFunc',
array_keys($data)));
$values = join(',', array_map('davesMakeValueSafeForDBInsertionFunc', $data));
$query = "INSERT INTO table ($columns) VALUES ($values)";
// tada!
>
> --
> Dave M G
>
--- End Message ---
--- Begin Message ---
On 7/7/06, Dave M G <[EMAIL PROTECTED]> wrote:
PHP List,
I've got a series of associative arrays that contain simple string
values that I want to insert into my database.
In each array, the names of the keys correspond to the column names
in the database table. The values stored in the array are, of course,
the values that I want to insert into the columns.
So, I want to set up a function where I can pass the array as an
argument, and it will construct the MySQL statement using the keys for
column names, and array values for insert values.
Within the function, the query looks like this:
$query = "INSERT INTO table (" . $columns . ") VALUES = (" . $values
. ")";
Assuming that the array argument passed to the function is called
$array, converting the array values to the insert values is pretty easy:
$values = implode(", ", $array);
But in the case of using the array keys for column names, it's not
so easy:
$columns = implode(", " array->keys($array));
I know that code above doesn't work, because, as described in the
manual, array keys returns a list of the numerical indexes along with
the string indexes. Something like this:
Array
(
[0] => column1
[1] => column2
[2] => column3
)
At least, that's what it looks like if it's just echoed out.
Is there a way I can strip out the relevant column names to be more
like this:
"column1, column2. column3"
Thank you for any advice.
--
Dave M G
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Well after calling array_keys you have an array with all the keys.
If you implode it the same way like you get the values from the
original array, you will get what you want.
$values = implode(", ", $array);
$keys = array_keys($array);
$columns = implode(", ",$keys);
--- End Message ---
--- Begin Message ---
Dave M G wrote:
PHP List,
I've got a series of associative arrays that contain simple string
values that I want to insert into my database.
In each array, the names of the keys correspond to the column names
in the database table. The values stored in the array are, of course,
the values that I want to insert into the columns.
So, I want to set up a function where I can pass the array as an
argument, and it will construct the MySQL statement using the keys for
column names, and array values for insert values.
Within the function, the query looks like this:
$query = "INSERT INTO table (" . $columns . ") VALUES = (" . $values
. ")";
Assuming that the array argument passed to the function is called
$array, converting the array values to the insert values is pretty easy:
$values = implode(", ", $array);
But in the case of using the array keys for column names, it's not so
easy:
$columns = implode(", " array->keys($array));
I know that code above doesn't work, because, as described in the
manual, array keys returns a list of the numerical indexes along with
the string indexes.
Actually, it doesn't matter what the indexes are when you use implode.
Implode just puts the values into a string. Here's code that will work.
$field_array = array_keys($fields_form);
$fields = implode(",",$field_array);
$values = implode('","',$fields_form);
$query = "INSERT INTO Table1 ($fields) VALUES (\"$values\")";
$result = mysqli_query($cxn,$query);
$fields_form is an associative array of all the fields to be entered
into the database, with the field names as keys and the field values as
values. This code quotes the values in the $values string in the query,
as needed if the values are strings.
Janet
Something like this:
Array
(
[0] => column1
[1] => column2
[2] => column3
)
At least, that's what it looks like if it's just echoed out.
Is there a way I can strip out the relevant column names to be more
like this:
"column1, column2. column3"
Thank you for any advice.
--
Dave M G
--
Janet Valade -- janet.valade.com
--- End Message ---
--- Begin Message ---
Hi all,
I am researching setting up an application in PHP where it would play
various videos.
I played with PHP and Totem but it didn't work exactly as planned.
This code got the videos playing
<snip>
exec("totem --fullscreen million_dollar_weekend.mpeg");
exec("totem --fullscreen we_use_power_edit.mp4");
</snip>
The problem here is that when the video stops totem stays open and
therefore my script does not realize that it is time to play the next
video.
Does anyone have any ideas how to get them to stop properly?
Is there another/better player than totem? Videolan does not have the
level of command line control that totem does.
Is there a pcntl function that might do the trick?
I could keep a list of the videos and lengths and then have my script
issue a kill comand once the length of time plus some play time has
ellapsed.
Thanks,
--
Leonard Burton, N9URK
[EMAIL PROTECTED]
"The prolonged evacuation would have dramatically affected the
survivability of the occupants."
--- End Message ---
--- Begin Message ---
Looks like totem supports playlists, why not just generate a playlist and pipe
that into totem?
And I don't see any obvious documentation without downloading Totem, but you
might check to see if there's an "exit on end" option that'd return control
back to PHP if a playlist isn't an option.
Or if you can feed totem a list of files without generating a playlist. Some
media players will generate a playlist in memory based on a list of file
names/paths sent to it rather than loading a text file playlist.
-TG
= = = Original message = = =
Hi all,
I am researching setting up an application in PHP where it would play
various videos.
I played with PHP and Totem but it didn't work exactly as planned.
This code got the videos playing
<snip>
exec("totem --fullscreen million_dollar_weekend.mpeg");
exec("totem --fullscreen we_use_power_edit.mp4");
</snip>
The problem here is that when the video stops totem stays open and
therefore my script does not realize that it is time to play the next
video.
Does anyone have any ideas how to get them to stop properly?
Is there another/better player than totem? Videolan does not have the
level of command line control that totem does.
Is there a pcntl function that might do the trick?
I could keep a list of the videos and lengths and then have my script
issue a kill comand once the length of time plus some play time has
ellapsed.
Thanks,
--
Leonard Burton, N9URK
[EMAIL PROTECTED]
"The prolonged evacuation would have dramatically affected the
survivability of the occupants."
___________________________________________________________
Sent by ePrompter, the premier email notification software.
Free download at http://www.ePrompter.com.
--- End Message ---
--- Begin Message ---
On Fri, July 7, 2006 11:23 am, Leonard Burton wrote:
> I am researching setting up an application in PHP where it would play
> various videos.
>
> I played with PHP and Totem but it didn't work exactly as planned.
>
> This code got the videos playing
> <snip>
> exec("totem --fullscreen million_dollar_weekend.mpeg");
> exec("totem --fullscreen we_use_power_edit.mp4");
> </snip>
>
> The problem here is that when the video stops totem stays open and
> therefore my script does not realize that it is time to play the next
> video.
>
> Does anyone have any ideas how to get them to stop properly?
man totem *MIGHT* list a command line argument to make it play one
video and quit...
Or you might contact the totem team and get them to add it for you.
> Is there another/better player than totem? Videolan does not have the
> level of command line control that totem does.
>
> Is there a pcntl function that might do the trick?
You could run totem in the background, and poll the process PID and
see how "busy" it is, maybe...
> I could keep a list of the videos and lengths and then have my script
> issue a kill comand once the length of time plus some play time has
> ellapsed.
This is hinky, as the user could easily "pause" the video, presumably...
Random Thought:
Perhaps PHP GTK http://gtk.php.net already has a video player of some
kind with "hooks" for you to know when the video is finished.
--
Like Music?
http://l-i-e.com/artists.htm
--- End Message ---
--- Begin Message ---
If you're only sorting by one column at a time (not adding to a column sort
list) then you can do something like this:
$ascdesc = ($_GET['sortcol'] == 'colA' AND $_GET['ad'] == 'ASC') ? 'DESC' :
'ASC';
echo "<a href=\"script.php?sortcol=colA&ad=$ascdesc\">ColA</a>\n";
$ascdesc = ($_GET['sortcol'] == 'colB' AND $_GET['ad'] == 'ASC') ? 'DESC' :
'ASC';
echo "<a href=\"script.php?sortcol=colB&ad=$ascdesc\">ColA</a>\n";
$ascdesc = ($_GET['sortcol'] == 'colC' AND $_GET['ad'] == 'ASC') ? 'DESC' :
'ASC';
echo "<a href=\"script.php?sortcol=colC&ad=$ascdesc\">ColA</a>\n";
In this case, the only time you want a descending sort is when the column being
sorted is the current column (who's HREF is being output) and the current sort
value is ASC. If current sort value is blank, it'll default to ascending.
And if you're not familiar with that $var = (condition) ? 'value1' : 'value2';
syntax, look up ternary operations. It's just a short hand way of saying "if
this is true, use this value, else use this second value".
I also did code once where each column you clicked got added to the sort list.
So if you clicked column B, that became primary sort. If you clicked on column
C after that, then C became the primary sort and B was the secondary sort. On
top of that I did thte ASC/DESC thing too.
Just a matter of working out the logic, but yes, you can do it all in PHP.
-TG
= = = Original message = = =
Good Day List,
Does anybody know of a pure PHP way to make table header cells trigger a
column sort?
If I have a table header that contains a link that when clicked
resubmits the page to itself with the proper sort query variables (e.g.
index.php?sortBy=ORDER_ID&sortOrder=ASC), I want PHP to rewrite the
sortOrder query string to be "sortOrder=DESC" and then "sortOrder=ASC"
the next time column heading is clicked. This way, the column will sort
like windows columns and users will feel "at-home" with the process.
I can write some JavaScript that will dynamically rewrite the href
attribute of the link, but I was hoping for a pure PHP solution in case
JavaScript is disabled.
Thanks.
Ken Vandegrift
[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>
Web Administrator
Sharis Mgmt. Corp
___________________________________________________________
Sent by ePrompter, the premier email notification software.
Free download at http://www.ePrompter.com.
--- End Message ---
--- Begin Message ---
Thanks for the tip!
This works great as I only need a single column sort :)
Ken Vandegrift
[EMAIL PROTECTED]
Web Administrator
Sharis Mgmt. Corp
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
Sent: Friday, July 07, 2006 10:01 AM
To: [email protected]
Subject: Re: [PHP-WIN] Dynamic HTML table sort with PHP
If you're only sorting by one column at a time (not adding to a column
sort list) then you can do something like this:
$ascdesc = ($_GET['sortcol'] == 'colA' AND $_GET['ad'] == 'ASC') ?
'DESC' : 'ASC'; echo "<a
href=\"script.php?sortcol=colA&ad=$ascdesc\">ColA</a>\n";
$ascdesc = ($_GET['sortcol'] == 'colB' AND $_GET['ad'] == 'ASC') ?
'DESC' : 'ASC'; echo "<a
href=\"script.php?sortcol=colB&ad=$ascdesc\">ColA</a>\n";
$ascdesc = ($_GET['sortcol'] == 'colC' AND $_GET['ad'] == 'ASC') ?
'DESC' : 'ASC'; echo "<a
href=\"script.php?sortcol=colC&ad=$ascdesc\">ColA</a>\n";
In this case, the only time you want a descending sort is when the
column being sorted is the current column (who's HREF is being output)
and the current sort value is ASC. If current sort value is blank,
it'll default to ascending.
And if you're not familiar with that $var = (condition) ? 'value1' :
'value2'; syntax, look up ternary operations. It's just a short hand
way of saying "if this is true, use this value, else use this second
value".
I also did code once where each column you clicked got added to the sort
list. So if you clicked column B, that became primary sort. If you
clicked on column C after that, then C became the primary sort and B was
the secondary sort. On top of that I did thte ASC/DESC thing too.
Just a matter of working out the logic, but yes, you can do it all in
PHP.
-TG
= = = Original message = = =
Good Day List,
Does anybody know of a pure PHP way to make table header cells trigger a
column sort?
If I have a table header that contains a link that when clicked
resubmits the page to itself with the proper sort query variables (e.g.
index.php?sortBy=ORDER_ID&sortOrder=ASC), I want PHP to rewrite the
sortOrder query string to be "sortOrder=DESC" and then "sortOrder=ASC"
the next time column heading is clicked. This way, the column will sort
like windows columns and users will feel "at-home" with the process.
I can write some JavaScript that will dynamically rewrite the href
attribute of the link, but I was hoping for a pure PHP solution in case
JavaScript is disabled.
Thanks.
Ken Vandegrift
[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]> Web Administrator
Sharis Mgmt. Corp
___________________________________________________________
Sent by ePrompter, the premier email notification software.
Free download at http://www.ePrompter.com.
--- End Message ---
--- Begin Message ---
On Thu, July 6, 2006 9:29 pm, John Gunther wrote:
> Which PHP method allows me to start a shell process from a web page
> script and let it proceed to its conclusion even though I end the
> page.
> Most of the various execute functions seem to wait for the process to
> finish before PHP continues. I don't understand the ones with
> open/close
> functions. Will opening a process and failing to close it let it run
> after the page ends? Will failing to close cause other problems? Can
> you
> point me to example code? The shell commands I want to run are
> typically
> themselves PHP programs whose execution time is far too long to
> complete
> in a browser context.
On some machines, on some OSes, in some configurations, with some
commands, tacking "&" onto the end of what you exec, will sometimes
"work"...
I would recommend, however, that you re-structure things slightly so
that the Architecture is more like this:
User visits web page.
Page generates a database record of what needs to be done.
Page finished.
CRON JOB:
Look in task list of what needs doing, and do some of them.
Make sure only one job is done at a time, or whatever race conditions
are handled here.
I've done projects both ways, and always end up frustrated with the
"PHP attempts to background a process" and the "Task List + Cron"
always works out far far better.
--
Like Music?
http://l-i-e.com/artists.htm
--- End Message ---