הרשם שאלות ותשובות רשימת חברים לוח שנה חיפוש הודעות מהיום סמן פורומים כנקראו

   
|!|

סגור את ההודעה
 
כלים לאשכול תצורת הצגה
ישן 29-01-06, 20:40   # 1
miniature
חבר וותיק
 
מיני פרופיל
תאריך הצטרפות: Oct 2005
הודעות: 1,754

miniature לא מחובר  

אה כנראה שהייתי צריך להביא את הקוד המלא מלכתחילה, מצטער.
הנה כל הקוד (ללא השינוי שאמרת לי לעשות):
PHP קוד:
<?php
if($action == "edit" && isset($HTTP_POST_VARS['password'])) {
    
//obviously you should change this password on the next line
    
if($HTTP_POST_VARS['password'] == "123456") {
        
//First let's recompile that line with the pipe symbols so we can reinsert it
        
$line $HTTP_POST_VARS['date'] . "|" $HTTP_POST_VARS['name'];
        
$line .= "|" $HTTP_POST_VARS['articles'];
        
$line str_replace("\r\n","<BR>",$line);
        
$line .= "\r\n";
        
$data file('articles.txt');
        
$data[$id] = $line;
        
//the next line makes sure the $data array starts at the beginning
        
reset($data);
        
//now we open the file with mode 'w' which truncates the file
        
$fp fopen('articles.txt','w');
        foreach(
$data as $element) {
            
fwrite($fp$element);
        }
        
fclose($fp);
        echo 
"<div class=\"content\"><b>הכתבה נערכה</b>\n";
        echo 
"&nbsp;|&nbsp;<a href=\"$PHP_SELF\">חזור לעמוד הראשי</a></div><BR><BR>\n";
        exit;
    } else {
$data file('articles.txt');
//next line removed to make everything else easier in the admin script
//$data = array_reverse($data);
foreach($data as $key=>$element) {
    
$element trim($element);
    
$pieces explode("|"$element);
        echo 
"<div class=\"content\"><b>סיסמה שגויה</b>\n";
        echo 
"&nbsp;|&nbsp;<a href=\"$PHP_SELF?action=edit&id=$key\">חזור</a></div><BR><BR>\n";
        exit;
    }
    }
}
if(
$action == "edit") {
    
$data file('articles.txt');
    
$element trim($data[$id]);
    
$pieces explode("|"$element);
    
//the next line is to reverse the process of turning the end of lines into breaking returns
    
$articles str_replace("<BR>","\r\n",$pieces[2]);
    echo 
"<div id=\"content\"><h2><u>ערוך כתבה</u></h2></div><BR>\n";
    echo 
"<div class=\"content\"><FORM ACTION=\"$PHP_SELF?action=edit\" METHOD=\"POST\" NAME=\"editform\">\n";
    echo 
"שם:<BR>\n";
    echo 
"<INPUT TYPE=\"text\" SIZE=\"30\" NAME=\"name\" value=\"".$pieces[1]."\"><BR>\n";
    echo 
"תוכן הכתבה:<BR>\n";
    echo 
"<TEXTAREA NAME=\"articles\" COLS=\"40\" ROWS=\"5\">".$articles."</TEXTAREA><BR><BR>\n";
    echo 
"סיסמה:<BR>\n";
    echo 
"<INPUT TYPE=\"password\" SIZE=\"30\" NAME=\"password\"><BR>\n";
    echo 
"<INPUT TYPE=\"hidden\" NAME=\"date\" VALUE=\"".$pieces[0]."\">\n";
    echo 
"<INPUT TYPE=\"hidden\" NAME=\"id\" VALUE=\"$id\">\n";
    echo 
"<INPUT TYPE=\"submit\" NAME=\"submit\" VALUE=\" שמור \"><BR>\n";
    echo 
"</FORM></div>\n";
    exit;
}
if(
$action == "delete" && isset($HTTP_POST_VARS['password'])) {
    
//obviously you should change this password on the next line
    
if($HTTP_POST_VARS['password'] == "123456") {
        
$data file('articles.txt');
        
//this next line will remove the single articles item from the array
        
array_splice($data,$id,1);
        
//now we open the file with mode 'w' which truncates the file
        
$fp fopen('articles.txt','w');
        foreach(
$data as $element) {
            
fwrite($fp$element);
        }
        
fclose($fp);    
        echo 
"<div class=\"content\"><b>הכתבה נמחקה</b>\n";    
        echo 
"&nbsp;|&nbsp;<a href=\"$PHP_SELF\">חזור לעמוד הראשי</a></div><BR><BR>\n";
        exit;
    } else {
$data file('articles.txt');
//next line removed to make everything else easier in the admin script
//$data = array_reverse($data);
foreach($data as $key=>$element) {
    
$element trim($element);
    
$pieces explode("|"$element);
        echo 
"<div class=\"content\"><b>סיסמה שגויה</b>\n";
        echo 
"&nbsp;|&nbsp;<a href=\"$PHP_SELF?action=edit&id=$key\">חזור</a></div><BR><BR>\n";
        exit;
    }
    }
}
if(
$action == "delete") {
    echo 
"<div id=\"content\"><h2><u>מחיקת כתבה</u></h2></div>\n";
    
$data file('articles.txt');
    
$element trim($data[$id]);
    
$pieces explode("|"$element);
    echo 
"<div class=\"content\">" $pieces[2] . "<BR>" "<b>נשלח על ידי " $pieces[1] . " ב " $pieces[0] . "</b>\n";
    echo 
"<BR><BR>\n";
    echo 
"אם אתה בטוח שברצונך למחוק את הכתבה, הקלד את הסיסמה ומחק:<BR><BR>\n";
    echo 
"<FORM ACTION=\"$PHP_SELF?action=delete\" METHOD=\"POST\" NAME=\"deleteform\">\n";
    echo 
"סיסמה:<BR>\n";
    echo 
"<INPUT TYPE=\"password\" SIZE=\"30\" NAME=\"password\"><BR>\n";
    echo 
"<INPUT TYPE=\"hidden\" NAME=\"id\" VALUE=\"$id\">\n";
    echo 
"<INPUT TYPE=\"submit\" NAME=\"submit\" VALUE=\" מחק \"><BR>\n";
    echo 
"</FORM></div>\n";
    exit;
}

echo 
"<div id=\"content\"><h2><u>כתבות נוכחיות</u></h2></div>\n";
$data file('articles.txt');
$data array_reverse($data);
foreach(
$data as $key=>$element) {
    
$element trim($element);
    
$pieces explode("|"$element);

    echo 
"<BR><div class=\"content\">" $pieces[2] . "<BR>" "<b>נשלח על ידי " $pieces[1] . " ב " $pieces[0] . "</b>\n";
    echo 
"&nbsp;(<a href=\"$PHP_SELF?action=delete&id=$key\">מחק</a>\n";
    echo 
"&nbsp;|&nbsp;<a href=\"$PHP_SELF?action=edit&id=$key\">ערוך</a>)\n";
    echo 
"<BR><HR><BR><BR></div>\n";
}
?>
אם תדע איך לעשות את אותו הדבר רק שתהיה אפשרות של עריכה ומחיקה אז תודה רבה
__________________
יואב.

דרכים ליצירת קשר:

אימייל: thebigfire@walla.co.il
הודעה פרטית
 
ישן 29-01-06, 20:45   # 2
meshuga
הנהלת הפורום לשעבר
 
meshuga's Avatar
 
מיני פרופיל
תאריך הצטרפות: Oct 2005
גיל: 35
הודעות: 7,601

meshuga לא מחובר  

סתם שאלה, זה קוד שלך? כי יש שם הרבה הערות באנגלית, מה שאני לא רואה הרבה בקרב המתכנתים הישראלים..
בכל מקרה.....אני עובד על זה....שניה..

טוב הבנתי מה עשית פה...אני בדיוק עובד על מערכת בדיוק עם אותו דבר....עריכה מחיקה ובלאגן מקבצים.
אני עשיתי בדיוק מה שאתה עשית חוץ מזה שאתה השתמשת בפונקציה שמורידה ממערך ואני פשוט עשיתי שאם הid שווה לו הוא לא יכניס...
בכל מקרה....במקום כל foreach אתה צריך לשים את הלולאת for שהראיתי לך....אין ברירה...

אין לי זמן עכשיו לסדר את כל הקוד כי הוא יחסית ארוך לזמן שאני יכול עכשיו לשבת על זה....
תנסה קצת לבד....תסתכל על מה שהבאתי לך בהשוואה לשלך ותנסה להבין.
 
סגור את ההודעה

חברים פעילים הצופים באשכול זה: 1 (0 חברים ו- 1 אורחים)
 

כלים לאשכול
תצורת הצגה

חוקי פירסום
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is מופעל
סמיילים הם מופעל
[IMG] קוד מופעל
קוד HTML מכובה

קפיצה לפורום


כל הזמנים הם GMT +2. הזמן כעת הוא 03:18.

מופעל באמצעות VBulletin גרסה 3.8.6
כל הזכויות שמורות ©
כל הזכויות שמורות לסולל יבוא ורשתות (1997) בע"מ