Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Query für Felder verschiebung?

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Language: German
View previous topic :: View next topic  
Author Message
Micha
Smarty Rookie


Joined: 28 Aug 2004
Posts: 9

PostPosted: Sat Jan 15, 2005 4:22 pm    Post subject: Query für Felder verschiebung? Reply with quote

Hallo zusammen,

ich möchte gern ein Charts Script schreiben, dazu nmöchte ich ein mal in der Woche ein Update meiner Tabelle "tabelle" durchführen

Die Tabelle hat 5 Felder (ID, Feld1, Feld2, Feld3, reloadTime)

Ich möchte das der Wert von Feld 2 in Feld 1 und Wert von Feld3 in Feld2 verschoben wird und das für jede Zeile also Where ID

habe es so probiert
[php:1:482550d8c6]<?php

definiere Zeitangabe zum update....
...
$from=$db->query_first("SELECT FROM tabelle"); .....
while($row = $db->fetch_array($result)) {
$db->query("UPDATE tabelle SET
Feld1 = '".addslashes($row['Feld2'])."',
Feld2 = '".addslashes($row['Feld3'])."',
Feld3 = '".addslashes($row['Feld'])."',
reloadTime = '".time()."'
WHERE ID = '".$from['ID']."'");
}
?>[/php:1:482550d8c6]

leider funktioniert es nicht, bzw. werden alle Felder mit dem selbem Wert gefüllt Crying or Very sad

Weiß da jemand eine Lösung oder ein Tutorial

Danke im Vorraus
Micha
Back to top
View user's profile Send private message
coach
Smarty Regular


Joined: 03 Jun 2004
Posts: 65

PostPosted: Sun Jan 16, 2005 4:26 pm    Post subject: Reply with quote

Hi,

ich hätte einen anderen Vorschlag für dich. Merk dir doch in einer seperaten Tabelle oder Datei, welche deiner 3 Spalten die älteste/neuste ist.

Du kannst ja auch mittels

Code:

SELECT
   Feld1 AS Feld2
   ,Feld2 AS Feld3
   ,Feld3 AS Feld1


selektieren - und dieses SQL-Statement kannst du ja zusammenbasteln mit String-Verkettung.

Ansonsten fällt mir nur noch ein, temporäre Spalten Feld1_temp bis Feld3_temp anlegen, Update mit SET Feld1_temp = Feld2 ...., alte Spalten droppen und temporäre Spalten umbenennen.

Aber was hat das mit Smarty zu tun?

Coach
Back to top
View user's profile Send private message
T.
Smarty Regular


Joined: 22 Aug 2004
Posts: 69
Location: AT

PostPosted: Sun Jan 16, 2005 5:02 pm    Post subject: Reply with quote

theroetisch könnt das auch mit purem sql gehen (fragt sich nur in welcher reihenfolge man das set machen muss, probiers aus)

update Tabelle
SET Feld1=Feld2,
Feld2=Feld3
WHERE wasauchimmer

mfg Thomas
_________________
Oppossom - Heavy rock from austria
Back to top
View user's profile Send private message Visit poster's website
CaptainE
Smarty Rookie


Joined: 23 Dec 2004
Posts: 22

PostPosted: Sun Jan 16, 2005 11:53 pm    Post subject: Reply with quote

Hi,

also meiner ansicht nach kannst du das ganze mit drei SQL statements machen, evtl auch mit einem aber ich weiß nicht wie die angaben nach SET von der reihenfolge her abgearbeitet werden.
Also wie gesagt ohne gewähr mein vorschlag:
Code:
UPDATE tabelle SET Feld1 = Feld2 WHERE irgendwas
UPDATE tabelle SET Feld2 = Feld3 WHERE irgendwas
UPDATE tabelle SET Feld3 = $neuerwert WHERE irgendwas


wenn du das für die ganze tabelle machen willst kannst die WHEREs einfach weglassen.
Wie gesagt das problem ist dass er, wenn das in einem statement ist dann die änderungen nicht übernimmt vor er die nächste spalte verschiebt und dann im endefekt überall das gleiche drin steht
Back to top
View user's profile Send private message
Micha
Smarty Rookie


Joined: 28 Aug 2004
Posts: 9

PostPosted: Sun Jan 23, 2005 8:51 am    Post subject: Reply with quote

Danke an T.

sein Vorschlag hat am besten funktioniert Cool

Falls jemand braucht hier ist mein Source

[php:1:dbc19cd361]<?php

$files = array();
$result = $db->query("SELECT fileID FROM file");
while ($row = $db->fetch_array($result)) {
$row['fileID'] = $row['fileID'];
$files[] = $row;
}


foreach($files as $key => $val) {
$db->query("UPDATE mp_file SET
counter1 = counter2,
counter2 = counter3,
counter3 = counter
WHERE $key = '".$val."'");
}

$db->unbuffered_query("UPDATE settings SET reloadTime = '".time()."'",1);

?>[/php:1:dbc19cd361]
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Language: German All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP