Toon posts:

[php] newbie,mysql in php content script

Pagina: 1
Acties:
  • 50 views sinds 30-01-2008

Verwijderd

Topicstarter
Ik heb een script voor een content management systeem van een vereniging. dit is het compleet gedownloade script, maar is het nu ook mogelijk, om gegevens uit een database te halen, en die in de tekst forms te zetten, zodat het zeg maar een 'edit' pagina wordt?
Ik ben een newbie, maar heb zeker al vele dingen geprobeerd, maar telkens komen de gegevens niet in forms maar erbuiten ofzo.
Wie kan mij helpen? Dus dat de mysql tags ervoor zouden zorgen, dat de berichten in de forms komen, zodat ze zijn aan te passen..

Dit zou ongeveer de mysql tag zijn:

// Selecteer alle id's en titels van de tabel
$sql = SELECT id, titel, bericht FROM nieuws WHERE id = '$id'

$result = mysql_query($sql);


En dit het totale phpscript.

PHP:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<?
    //Instantiates an editor
    function richtext_instantiate($editor_id){
        global $root;
        ?>
        <object id="<? echo $editor_id; ?>" style="BACKGROUND-COLOR: buttonface" data="<? echo $root,"../../contentmanagement/rte/"; ?>richedit.html" width="95%" height="150" type="text/x-scriptlet" VIEWASTEXT></object>
        <?
    } # end richtext_instantiate()


    //Builds javascript to fill in values from e.g. a database
    function richtext_populate($form_name,$editor_ids,$fields){

        /*****************************************************/
        /*    We have to generate javascript-functions to populate the
        /*    Richtext-editors spesified in $editor_ids, with html from e.g. database
        /*
        /*****************************************************/

        ?>
        <SCRIPT language="JavaScript" event="onload" for="window">
            <?
            //////////////////////////////////////////////////
            //Several text-editors/text-feilds in one form
            //////////////////////////////////////////////////
            for($i=0;$i<count($fields);$i++){
                //Sets options for each editor
                echo $editor_ids[$i],".options = \"history=no;source=yes\";\n";
                //Fills in text spesified in certain textarea-fields
                echo $editor_ids[$i],".docHtml = ",$form_name,".",$fields[$i],".innerText;\n";
            }
            ?>        
        </SCRIPT>
        <?
    } # end richtext_populate()



    //Function for adding Richtext-formatted text to the form
    function richtext_postit($form_name,$editor_ids,$fields){
    ?>
        <SCRIPT language="JavaScript">
            function copyValue(){ 
                <? for($i=0;$i<count($fields);$i++){                
                    echo $form_name,".",$fields[$i],".innerText = ",$editor_ids[$i],".docHtml;\n";
                }?>
            }
        </SCRIPT>
    <?
    } # end richtext_postit()


#
# Saving the data in e.g. a database
#


    if($submit){
        /*****************************
        /*    Save your  data from the form here...
        /*
        /*****************************/

    }


# Initiating the Richtext editors


    //First we make an array consisting id's for all the Richtext editors you want to use
    $editor_ids[0]="richtext_tittel";
    $editor_ids[1]="richtext_ingress";
    $editor_ids[2]="richtext_tekst";

    //Then we have to name the textareas we have instantiated Richtext for
    $fields[0]="sak_tittel";
    $fields[1]="sak_ingress";
    $fields[2]="sak_tekst";

    //Print out the function for adding the Richtext-formatted text to the form
    richtext_postit("sak",$editor_ids,$fields);

# Instantiating the editors
#


    //Display some Title
    echo "Tittel:<br>";
    richtext_instantiate($editor_ids[0]);//Instantiate the first editor
    //Display some Title
    echo "<br>Ingress:<br>";
    richtext_instantiate($editor_ids[1]);//Instantiate the second editor
    //Display some Title
    echo "<br>Tekst:<br>";
    richtext_instantiate($editor_ids[2]);//Instantiate the third editor

#
# Getting variables from database
#
    /***********************
    /*    Get variables from database here
    /*************************/


#
# Building the form
#

    //Now we build our (hidden) form:
    ?>
    <form name="sak" id="sak" ONSUBMIT="copyValue();" action="<? echo '$PHP_SELF'; ?>" method="POST" enctype="multipart/form-data">';
        <TEXTAREA name="sak_tittel" style="display:none" rows="1" cols="20"><? echo $var1; ?></textarea>
        <TEXTAREA name="sak_ingress" style="display:none" rows="1" cols="20"><? echo $var2; ?></TEXTAREA>
        <TEXTAREA name="sak_tekst" style="display:none" rows="1" cols="20"><? echo $var3; ?></TEXTAREA>
        <?
        //We'll use this submit-button to submit the form
        ?>
        <input type="submit" name="submit" value="Submit">
        <input type="reset" value="Reset">
    </form>
    <?


    //After creating the form, we can populate the fields
    richtext_populate("sak",$editor_ids,$fields);
?>

[ Voor 12% gewijzigd door Verwijderd op 21-01-2003 15:59 ]


  • D2k
  • Registratie: Januari 2001
  • Laatst online: 09-01 11:25

D2k

sja daar gaan we niet aan beginnen
we zijn hier geen helpdesk

Doet iets met Cloud (MS/IBM)


Dit topic is gesloten.