Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

[Help] Inserting a row from table1 to table2

New Here ,
Jan 28, 2009 Jan 28, 2009
Hi all,
I'm preparing a script ,
consists of :
-a user inserting page , into users_ins table
-an admin page do (show what users inserted , delete or prove an inserting to be shown in index.php ),
- and the index.php it shows the topics which was inserted by users , and admin has proved them . from proved_topic table

--[the problem]:
in the admin page :
when i click on prove button , how can i send the row i clicked into the proved_topic table and delete it from users_ins table

http://www.shaare7.com/am/somethinglikethis.png
TOPICS
Server side applications
391
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jan 29, 2009 Jan 29, 2009
I'm looking for something similar.

I want to take a SUM value from 1 table and insert it to another table as well.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 29, 2009 Jan 29, 2009
.oO(AMoktar)

> I'm preparing a script ,
> consists of :
> -a user inserting page , into users_ins table
> -an admin page do (show what users inserted , delete or prove an inserting to
>be shown in index.php ),
> - and the index.php it shows the topics which was inserted by users , and
>admin has proved them . from proved_topic table
>
> --[the problem]:
> in the admin page :
> when i click on prove button , how can i send the row i clicked into the
> proved_topic table and delete it from users_ins table
>
>

Why do you want to use two tables? Why not simply do it with a single
table with an additional column for the status? Then the admin can
easily approve or delete records from that table, and the index page
would only show approved records. Nothing easier than that.

If you still want to do it with two tables, you have to use two SQL
queries. The first one to copy the record from one table to another
would be an INSERT with a nested SELECT (sub select), the second one a
DELETE to remove the old record. Both queries should be secured by a
transaction (depends on the used database if this is possible) to keep
the tables in a consistent state, just in case something goes wrong.

But as said - a single table would be much easier, more reliable and a
better design.

Micha
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 30, 2009 Jan 30, 2009
Dear Mr. Michael Fesser , i think it is a genius idea ,
but , please can you explain that , or give a link of a tutorial .
thanks a lot for response ...
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 31, 2009 Jan 31, 2009
LATEST
.oO(AMoktar)

>Dear Mr. Michael Fesser , i think it is a genius idea ,
>but , please can you explain that , or give a link of a tutorial .
>thanks a lot for response ...

Hmm, I don't have any links to tutorials. And without at least some
basic database and SQL knowledge this might become a bit complicated,
even though it's actually a pretty simple task.

You would just add another column to your table, let's call it "status".
It can be of type INT (ENUM might be more appropriate if available, but
let's keep it simple). Then, when a new record is inserted by a user,
you simply set the status field to "0", which means the record has not
been approved by the admin yet. On your admin page you list all those
records with links to approve or delete them. Clicking an "approve" link
should execute an SQL query like this to set the status field for that
particular record from "0" to "1":

UPDATE yourTable
SET status = 1
WHERE topicID = ...

Your index page just needs a query like the following to display only
approved records:

SELECT ...
FROM yourTable
WHERE status = 1

It's really simple and should be doable with DW behaviours, but I can't
help you with that, since I always write my own scripts and queries.

I hope it at least explains the idea and shows the way.

Micha
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines