php-general Digest 4 Jun 2006 16:16:38 -0000 Issue 4166

Topics (messages 237334 through 237347):

Re: Delete
        237334 by: benifactor
        237335 by: Rabin Vincent
        237337 by: George Babichev
        237338 by: Larry Garfield
        237339 by: Rabin Vincent
        237341 by: tedd

Re: php java intregration
        237336 by: Rabin Vincent

How do I make a HTML tree for a set of nodes?
        237340 by: Niels
        237342 by: tedd
        237343 by: Niels
        237344 by: tedd
        237345 by: Niels
        237346 by: Martin Alterisio
        237347 by: Mike Bellerby

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:
        php-general@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---
when you insert each blog into your database, im assuming your not doing
this by hand each and every time, assign each blog an id.

in the place you want to delete the blog entries, list all of the blogs
titles and ids.
and then use mysql(delete);

example:
<?
//create a variable for the delete blog entry of you control panel
    if ($view == delete_blog) {
        //this should be the value of your submit button
        if ($deleteBlog) {
            //this is the value of the blog entries to delete
            if (!$idblog) {
                //this is your error message, to be displayed if no blog was
chosen to delete
                $de = "<font face=tahoma color=black size=1>You Need To
Choose a post to delete</font>";
             }
            else {
                //list the values of the array in which all the blog entries
you would like to delete are
                $delBlog = implode(",", $idblog);
                    //do the actual deletion
                        mysql_query("delete From blogs where id
IN($delBlog)") or die(mysql_error());
                            //display the succesfull message if the blog
entries were deleted
                            echo("<font face=tahoma color=black
size=1><b><center>blog(s):</b> $delBlog <b>has/have been
deleted;</b></b></center>");

//now we display the blog entries
//plus the sucsessfull message
?>

<form method="post">
<?php
$gn = mysql_query("Select * FROM blogs");
while ($d = mysql_fetch_array($gn)) {
?>
<INPUT TYPE="checkbox" NAME="idBlog[]" VALUE="<? echo("$d[id]"); ?>"><?
echo("<font face=tahoma color=black size=1><b>Post id:</b> $d[id]<b>;</b>
<b>Post Title:</b> $d[title]<b>;</b> <b>Posted by:</b>
$d[poster]<b>;</b><br>"); ?>
<?php
 }
?>
<br><br><input type="submit" name="deleteNerd" value="Delete"
class="button">
</form>
<?php
}
}
else {
//display blog entries only
?>
<form method="post">
<?php
$gn = mysql_query("Select * FROM blogs");
while ($d = mysql_fetch_array($gn)) {
?>
<INPUT TYPE="checkbox" NAME="idBlog[]" VALUE="<? echo("$d[id]"); ?>"><?
echo("<font face=tahoma color=black size=1><b>Post id:</b> $d[id]<b>;</b>
<b>Post Title:</b> $d[title]<b>;</b> <b>Posted by:</b>
$d[poster]<b>;</b><br>"); ?>
<?php
 }
?>
<br><br><input type=submit name="deleteNerd" value="Delete" class="button">
</form>
<?php
}
?>
this is a very rough example, however you should catch the drift, make your
id an array, implode that array and delete all the array data from the
database.

----- Original Message ----- 
From: "George Babichev" <[EMAIL PROTECTED]>
To: "PHP General list" <php-general@lists.php.net>
Sent: Saturday, June 03, 2006 6:40 PM
Subject: [PHP] Delete


> Hello everyone! I wrote a blog application, but now for the admin panel, i
> am trying to add a feature to delete blog posts. It would show the title
of
> the post next to it, and have a delete link which would delete it. How
would
> I do this? I mean if I have multiple blog entry's, how would I delete them
> without using php my admin?
>

--- End Message ---
--- Begin Message ---
On 6/4/06, George Babichev <[EMAIL PROTECTED]> wrote:
Hello everyone! I wrote a blog application, but now for the admin panel, i
am trying to add a feature to delete blog posts. It would show the title of
the post next to it, and have a delete link which would delete it. How would
I do this? I mean if I have multiple blog entry's, how would I delete them
without using php my admin?

Presumably, you have an id column in your blog posts table
which is the primary key. Then you can just delete posts by
doing something like:

mysql_query('DELETE FROM posts WHERE id = 2312');

Or if you want to delete multiple in one go

mysql_query('DELETE FROM posts WHERE id IN (23,34,12)');

Rabin

--- End Message ---
--- Begin Message ---
Thank you for the help guys, but the I guess I kinda have another question.
So I do assign an id to each blog post, and it is auto_increment, so in my
blog delete page, it would display all the blog title's and a delete button
nex to it. So lets say I click delete on the third entry. How would my
program know to delete THAT entry and not another one?

On 6/3/06, benifactor <[EMAIL PROTECTED]> wrote:

when you insert each blog into your database, im assuming your not doing
this by hand each and every time, assign each blog an id.

in the place you want to delete the blog entries, list all of the blogs
titles and ids.
and then use mysql(delete);

example:
<?
//create a variable for the delete blog entry of you control panel
    if ($view == delete_blog) {
        //this should be the value of your submit button
        if ($deleteBlog) {
            //this is the value of the blog entries to delete
            if (!$idblog) {
                //this is your error message, to be displayed if no blog
was
chosen to delete
                $de = "<font face=tahoma color=black size=1>You Need To
Choose a post to delete</font>";
             }
            else {
                //list the values of the array in which all the blog
entries
you would like to delete are
                $delBlog = implode(",", $idblog);
                    //do the actual deletion
                        mysql_query("delete From blogs where id
IN($delBlog)") or die(mysql_error());
                            //display the succesfull message if the blog
entries were deleted
                            echo("<font face=tahoma color=black
size=1><b><center>blog(s):</b> $delBlog <b>has/have been
deleted;</b></b></center>");

//now we display the blog entries
//plus the sucsessfull message
?>

<form method="post">
<?php
$gn = mysql_query("Select * FROM blogs");
while ($d = mysql_fetch_array($gn)) {
?>
<INPUT TYPE="checkbox" NAME="idBlog[]" VALUE="<? echo("$d[id]"); ?>"><?
echo("<font face=tahoma color=black size=1><b>Post id:</b> $d[id]<b>;</b>
<b>Post Title:</b> $d[title]<b>;</b> <b>Posted by:</b>
$d[poster]<b>;</b><br>"); ?>
<?php
}
?>
<br><br><input type="submit" name="deleteNerd" value="Delete"
class="button">
</form>
<?php
}
}
else {
//display blog entries only
?>
<form method="post">
<?php
$gn = mysql_query("Select * FROM blogs");
while ($d = mysql_fetch_array($gn)) {
?>
<INPUT TYPE="checkbox" NAME="idBlog[]" VALUE="<? echo("$d[id]"); ?>"><?
echo("<font face=tahoma color=black size=1><b>Post id:</b> $d[id]<b>;</b>
<b>Post Title:</b> $d[title]<b>;</b> <b>Posted by:</b>
$d[poster]<b>;</b><br>"); ?>
<?php
}
?>
<br><br><input type=submit name="deleteNerd" value="Delete"
class="button">
</form>
<?php
}
?>
this is a very rough example, however you should catch the drift, make
your
id an array, implode that array and delete all the array data from the
database.

----- Original Message -----
From: "George Babichev" <[EMAIL PROTECTED]>
To: "PHP General list" <php-general@lists.php.net>
Sent: Saturday, June 03, 2006 6:40 PM
Subject: [PHP] Delete


> Hello everyone! I wrote a blog application, but now for the admin panel,
i
> am trying to add a feature to delete blog posts. It would show the title
of
> the post next to it, and have a delete link which would delete it. How
would
> I do this? I mean if I have multiple blog entry's, how would I delete
them
> without using php my admin?
>



--- End Message ---
--- Begin Message ---
Make each button a separate form, with the id as a hidden value.  Like so:

<div>
<form method='post'>
<p>My first entry</p>
<input type='hidden' name='id' value='1' />
<input type='submit' value='Delete' />
</form>
</div>

<div>
<form method='post'>
<p>My second entry</p>
<input type='hidden' name='id' value='2' />
<input type='submit' value='Delete' />
</form>
</div>

Obviously you'd want something better formatted, but you get the idea.  Then 
on the receiving end, you'd simply "DELETE FROM entries where id=$id;".  That 
is, AFTER you process and clean the submitted id value so that it's not an 
injection risk. :-)

On Sunday 04 June 2006 00:53, George Babichev wrote:
> Thank you for the help guys, but the I guess I kinda have another question.
> So I do assign an id to each blog post, and it is auto_increment, so in my
> blog delete page, it would display all the blog title's and a delete button
> nex to it. So lets say I click delete on the third entry. How would my
> program know to delete THAT entry and not another one?
>
> On 6/3/06, benifactor <[EMAIL PROTECTED]> wrote:
> > when you insert each blog into your database, im assuming your not doing
> > this by hand each and every time, assign each blog an id.
> >
> > in the place you want to delete the blog entries, list all of the blogs
> > titles and ids.
> > and then use mysql(delete);
> >
> > example:
> > <?
> > //create a variable for the delete blog entry of you control panel
> >     if ($view == delete_blog) {
> >         //this should be the value of your submit button
> >         if ($deleteBlog) {
> >             //this is the value of the blog entries to delete
> >             if (!$idblog) {
> >                 //this is your error message, to be displayed if no blog
> > was
> > chosen to delete
> >                 $de = "<font face=tahoma color=black size=1>You Need To
> > Choose a post to delete</font>";
> >              }
> >             else {
> >                 //list the values of the array in which all the blog
> > entries
> > you would like to delete are
> >                 $delBlog = implode(",", $idblog);
> >                     //do the actual deletion
> >                         mysql_query("delete From blogs where id
> > IN($delBlog)") or die(mysql_error());
> >                             //display the succesfull message if the blog
> > entries were deleted
> >                             echo("<font face=tahoma color=black
> > size=1><b><center>blog(s):</b> $delBlog <b>has/have been
> > deleted;</b></b></center>");
> >
> > //now we display the blog entries
> > //plus the sucsessfull message
> > ?>
> >
> > <form method="post">
> > <?php
> > $gn = mysql_query("Select * FROM blogs");
> > while ($d = mysql_fetch_array($gn)) {
> > ?>
> > <INPUT TYPE="checkbox" NAME="idBlog[]" VALUE="<? echo("$d[id]"); ?>"><?
> > echo("<font face=tahoma color=black size=1><b>Post id:</b> $d[id]<b>;</b>
> > <b>Post Title:</b> $d[title]<b>;</b> <b>Posted by:</b>
> > $d[poster]<b>;</b><br>"); ?>
> > <?php
> > }
> > ?>
> > <br><br><input type="submit" name="deleteNerd" value="Delete"
> > class="button">
> > </form>
> > <?php
> > }
> > }
> > else {
> > //display blog entries only
> > ?>
> > <form method="post">
> > <?php
> > $gn = mysql_query("Select * FROM blogs");
> > while ($d = mysql_fetch_array($gn)) {
> > ?>
> > <INPUT TYPE="checkbox" NAME="idBlog[]" VALUE="<? echo("$d[id]"); ?>"><?
> > echo("<font face=tahoma color=black size=1><b>Post id:</b> $d[id]<b>;</b>
> > <b>Post Title:</b> $d[title]<b>;</b> <b>Posted by:</b>
> > $d[poster]<b>;</b><br>"); ?>
> > <?php
> > }
> > ?>
> > <br><br><input type=submit name="deleteNerd" value="Delete"
> > class="button">
> > </form>
> > <?php
> > }
> > ?>
> > this is a very rough example, however you should catch the drift, make
> > your
> > id an array, implode that array and delete all the array data from the
> > database.
> >
> > ----- Original Message -----
> > From: "George Babichev" <[EMAIL PROTECTED]>
> > To: "PHP General list" <php-general@lists.php.net>
> > Sent: Saturday, June 03, 2006 6:40 PM
> > Subject: [PHP] Delete
> >
> > > Hello everyone! I wrote a blog application, but now for the admin
> > > panel,
> >
> > i
> >
> > > am trying to add a feature to delete blog posts. It would show the
> > > title
> >
> > of
> >
> > > the post next to it, and have a delete link which would delete it. How
> >
> > would
> >
> > > I do this? I mean if I have multiple blog entry's, how would I delete
> >
> > them
> >
> > > without using php my admin?

-- 
Larry Garfield                  AIM: LOLG42
[EMAIL PROTECTED]               ICQ: 6817012

"If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it."  -- Thomas 
Jefferson

--- End Message ---
--- Begin Message ---
On 6/4/06, Larry Garfield <[EMAIL PROTECTED]> wrote:
Make each button a separate form, with the id as a hidden value.  Like so:

<div>
<form method='post'>
<p>My first entry</p>
<input type='hidden' name='id' value='1' />
<input type='submit' value='Delete' />
</form>
</div>
[snip]

You may find it easier to generate links of the form
delete.php?id=1, etc. Then you won't have to use a seperate
form for each link. The id will be available in delete.php
in $_GET. The same sanity checking applies in this case too.

Rabin

--- End Message ---
--- Begin Message ---
At 10:53 PM -0700 6/3/06, George Babichev wrote:
>Thank you for the help guys, but the I guess I kinda have another question.
>So I do assign an id to each blog post, and it is auto_increment, so in my
>blog delete page, it would display all the blog title's and a delete button
>nex to it. So lets say I click delete on the third entry. How would my
>program know to delete THAT entry and not another one?

Your specific question of "how to delete" I am sure other will provide, but 
consider this idea.

If you have a page that shows blog entries, then why not have an admin page 
that shows exactly the same thing except if has check-boxes next to the posts? 
And, if you check any of those and click "Submit", then those entries will be 
deleted from the database -- simple, plus you already have most of the code. :-)

I had a similar problem and was designing an admin page that would do the 
things I wanted (add/delete/alter items) when it dawned on me that all I needed 
was a check-box and a submit button added to my main display page.

As to how to delete and such, you may find this useful:

http://www.weberdev.com/get_example-384.html

hth's

tedd

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

--- End Message ---
--- Begin Message ---
On 6/4/06, Vedanta Barooah <[EMAIL PROTECTED]> wrote:
the pecl snapshots have the dll php_java.dll, but does not have the
jar php_java.jar which is also required?

I don't know about the snapshots, but the PECL zip on the
download page does have the jar you are looking for.

Rabin

--- End Message ---
--- Begin Message ---
Hi,


I have a set of nodes. Each node has a parent and so the set can be thought
of as a tree. I want to show that tree somehow on a webpage, served by PHP.
I cannot use Dot/Graphwiz for various reasons. What I'm looking for is an
output of DIVs or tablecells, showing the nodes and their connections. It's
not a trivial task, IMO, but doable. Possibly somebody has already made
something similiar, but I can't find anything on Google. Can anybody point
me to helpful information?

Thanks,
Niels

--- End Message ---
--- Begin Message ---
At 2:07 PM +0200 6/4/06, Niels wrote:
>Hi,
>
>
>I have a set of nodes. Each node has a parent and so the set can be thought
>of as a tree. I want to show that tree somehow on a webpage, served by PHP.
>I cannot use Dot/Graphwiz for various reasons. What I'm looking for is an
>output of DIVs or tablecells, showing the nodes and their connections. It's
>not a trivial task, IMO, but doable. Possibly somebody has already made
>something similiar, but I can't find anything on Google. Can anybody point
>me to helpful information?
>
>Thanks,
>Niels


What, a binary-tree or linked-list sort of thing?

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

--- End Message ---
--- Begin Message ---
On Sunday 04 June 2006 14:58, tedd wrote:

> At 2:07 PM +0200 6/4/06, Niels wrote:
>>Hi,
>>
>>
>>I have a set of nodes. Each node has a parent and so the set can be
>>thought of as a tree. I want to show that tree somehow on a webpage,
>>served by PHP. I cannot use Dot/Graphwiz for various reasons. What I'm
>>looking for is an output of DIVs or tablecells, showing the nodes and
>>their connections. It's not a trivial task, IMO, but doable. Possibly
>>somebody has already made something similiar, but I can't find anything on
>>Google. Can anybody point me to helpful information?
>>
>>Thanks,
>>Niels
> 
> 
> What, a binary-tree or linked-list sort of thing?
> 
> tedd

Not binary -- a node can have several children. Each node has an id and a
parentId. The actual structure isn't important and can easily be objects,
arrays-of-arrays or whatever is handy.

//Niels

--- End Message ---
--- Begin Message ---
At 3:03 PM +0200 6/4/06, Niels wrote:
>On Sunday 04 June 2006 14:58, tedd wrote:
>
>> At 2:07 PM +0200 6/4/06, Niels wrote:
>>>Hi,
>>>
>>>
>>>I have a set of nodes. Each node has a parent and so the set can be
>>>thought of as a tree. I want to show that tree somehow on a webpage,
>>>served by PHP. I cannot use Dot/Graphwiz for various reasons. What I'm
>>>looking for is an output of DIVs or tablecells, showing the nodes and
>>>their connections. It's not a trivial task, IMO, but doable. Possibly
>>>somebody has already made something similiar, but I can't find anything on
>>>Google. Can anybody point me to helpful information?
>>>
>>>Thanks,
>>>Niels
>>
>>
>> What, a binary-tree or linked-list sort of thing?
>>
>> tedd
>
>Not binary -- a node can have several children. Each node has an id and a
>parentId. The actual structure isn't important and can easily be objects,
>arrays-of-arrays or whatever is handy.
>
>//Niels

You can dynamically generate a table and place text (and/or color) the cells 
that are nodes -- that would be my approach. You would need to know the width 
and depth of the tree and then just fill in the cells that are nodes.

hth's

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

--- End Message ---
--- Begin Message ---
On Sunday 04 June 2006 15:30, tedd wrote:

[snip]

> You can dynamically generate a table and place text (and/or color) the
> cells that are nodes -- that would be my approach. You would need to know
> the width and depth of the tree and then just fill in the cells that are
> nodes.
> 
> hth's
> 
> tedd

Yes, well... It's a tad more complicated I think. Yes, I can make a table,
finding the dimensions shouldn't be a big problem. Placing the nodes in the
right cells isn't as easy, and making the connections is downright
difficult.

A problem with using a table is that cells can't be individually sized.
However DIVs or TDs is a minor problem. The major problem is to walk
through the tree properly (recursively probably), and remember the
connections. And then rendering them...


Thank you for your answer,
Niels

--- End Message ---
--- Begin Message ---
2006/6/4, Niels <[EMAIL PROTECTED]>:

Hi,


I have a set of nodes. Each node has a parent and so the set can be
thought
of as a tree. I want to show that tree somehow on a webpage, served by
PHP.
I cannot use Dot/Graphwiz for various reasons. What I'm looking for is an
output of DIVs or tablecells, showing the nodes and their connections.
It's
not a trivial task, IMO, but doable. Possibly somebody has already made
something similiar, but I can't find anything on Google. Can anybody point
me to helpful information?

Thanks,
Niels

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


I had a similar problem that, although it was with a binary tree, it can be
used with your tree. PHP doesn't like too much the use of recursion, but
this time recursion is the way to go (if you want to keep the code
maintainable). Hopefully the tree will not span deep enough to cause any
problems... (hopefully).

The function will receive a node and return a table representation of the
branch started by this tree, if you point this function to the root node
you'll have your table. In each cell it will have to indicate whether it is
empty, it has a node or a line connecting neighbor cells. One important
thing to define here is the way the function will organize the nodes in the
table, in my function the root node was at the top in the center.

First, the trivial case: if the node doesn't have children return a table
with one cell, the node itself.
Then, the recursive case: if the node have children, call the function with
those nodes and store the tables returned. According to the representation I
used, it calculated the combined width of those tables, created a new table
where the first row contained the parent node centered, the second line an
horizontal line from the column where the first children would be to the
column where the last children would be. Then it build the rest of the table
pasting together, horizontally, the tables of the children. Voila! a nice
table representation of the tree.

--- End Message ---
--- Begin Message ---
You could do it by dynamically generating an image.

Mike


Niels wrote:

On Sunday 04 June 2006 15:30, tedd wrote:

[snip]

You can dynamically generate a table and place text (and/or color) the
cells that are nodes -- that would be my approach. You would need to know
the width and depth of the tree and then just fill in the cells that are
nodes.

hth's

tedd

Yes, well... It's a tad more complicated I think. Yes, I can make a table,
finding the dimensions shouldn't be a big problem. Placing the nodes in the
right cells isn't as easy, and making the connections is downright
difficult.

A problem with using a table is that cells can't be individually sized.
However DIVs or TDs is a minor problem. The major problem is to walk
through the tree properly (recursively probably), and remember the
connections. And then rendering them...


Thank you for your answer,
Niels



--- End Message ---

Reply via email to