הוסטס - פורום אחסון האתרים הגדול בישראל

הוסטס - פורום אחסון האתרים הגדול בישראל (https://hosts.co.il/forums/index.php)
-   פורום תיכנות (https://hosts.co.il/forums/forumdisplay.php?f=14)
-   -   כיצד ניתן לאנקלד עמוד עם GET? (https://hosts.co.il/forums/showthread.php?t=23003)

-VladK- 01-06-06 11:56

כיצד ניתן לאנקלד עמוד עם GET?
 
שלום.
נגיד ויש לי עמוד כזה:
poll.php?id=342
עכשיו בהתחלה השתמשתי בIFRAME על מנת להציג אותו בתוך האתר...אבל עכשיו אני לא רוצה שזה יהיה ככה...אז כיצד אני יכול לאנקלד את העמוד הזה כך שהוא יקח את המידע שהID שלו זה 342...

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

ניסיתי לעשות ככה:
include 'poll.php?id=342';
אבל זה לא עובד...חח ברור שלו כי זה צריך להיות GET ...אבל בכל מקרה למשהו יש פתרון יותר טוב מIFRAME?

eXtaZa 01-06-06 12:16

תיקח את המשתנה id מהGET:
PHP קוד:

$id=$_GET['id']; 

ובעזרתו תעשה מה שאתה רוצה, להציג נתונים, וכו'.
עדיין לא הבנתי את האינקלוד שניסית לעשות, למה אתה מצפה שיאנקלד לך את זה?
יש קובץ שנקרא בשם כזה?|קורץ|

-VladK- 01-06-06 12:25

לא הבנתה אותי בגרוש...סתכל יש לי עמוד כזה:
poll.php?id=342
שכבר משתמש בGET ובלי GET הוא לא עובד...עד כאן מובן? עכשיו אני רוצה להאנקלד את העמוד עם כל הכתובת כלומר שהאינקלוד יהיה כזה poll.php?id=342 ...עכשיו ניסיתילעשות בשיטה רגילה וזה לא עובד...יש עוד שיטות? חוץ מIFRAME...

eXtaZa 01-06-06 12:28

לא הבנתי אותך, מה אתה רוצה שיהיה בעמוד שיאונקלד?

-VladK- 01-06-06 12:30

בעעע...טוב סתכל...
אני רוצה לאנקלד את העמוד הבא:
PHP קוד:

<?php
define 
("PHP_FILE"true);
///////////////////////
function listpolls( ) {
///////////////////////

include 'db.php';
$sql "SELECT * FROM master_poll WHERE status = 'Online'";
$res mysql_query($sql) or die(mysql_error());

// Retrieve the Results
while ($newArray mysql_fetch_array($res)) {
   
// Convert the Result set into Variables
   
$id $newArray['id'];
   
$poll_name $newArray['question'];
   
$status $newArray['status'];
   
   echo 
"<b>בחר סקר:</b><br />";
   echo 
"<a href=\"poll.php?method=viewpoll&id=$id\">$poll_name</a><br />";
}

}

///////////////////////
function viewpoll( ) {
///////////////////////

$id $_GET['id'];

include 
'db.php';
$sql "SELECT * FROM master_poll WHERE id = '$id'";
$res mysql_query($sql) or die(mysql_error());

// Retrieve the Results
while ($newArray mysql_fetch_array($res)) {
   
// Convert the Result set into Variables
   
$id $newArray['id'];
   
$poll_name $newArray['question'];
   
$status $newArray['status'];
}

if (
$status == "Offline") {
   echo 
"הסקר שבחרתה אינו פעיל!";
   exit();
}

echo 
"<div style=\"width: 100%;\">
$poll_name
<form action=\"poll.php?method=vote\" method=\"post\">
<div dir=\"rtl\">"
;
$results "<a href=\"?method=results&id=$id\">";

include 
'db.php';
$sql "SELECT * FROM poll_answers WHERE poll_id = '$id' ORDER BY id ASC";
$res mysql_query($sql) or die(mysql_error());

// Retrieve the Results
while ($newArray mysql_fetch_array($res)) {
   
// Convert the Result set into Variables
   
$id $newArray['id'];
   
$poll_id $newArray['poll_id'];
   
$answer $newArray['answer'];

echo 
"<input type=\"radio\" name=\"answer_id\" value=\"$id\"> $answer<br />";

}
echo 
"</div>
<div dir=\"ltr\" style=\"height:17px;\">
$results<img src=\"2.gif\" width=\"59\" height=\"17\" border=\"0\" /></a> <input type=\"image\" name=\"image\" src=\"1.gif\">
</div>
</div><input type=\"hidden\" name=\"poll_id\" value=\"$id\">\n"
;
echo 
"</form>";

}

///////////////////////
function checkuser( ) {
///////////////////////

$ip $_SERVER['REMOTE_ADDR'];

include 
'db.php';
$check mysql_query("SELECT * FROM ban_ip WHERE ipaddress = '$ip' LIMIT 1") or die(mysql_error());
if (
mysql_num_rows($check) <= 0) {
  echo 
"&nbsp;";
} else {
  echo 
"הנהלת האתר החליטה שאין לך זכות להצביע! לפרטים נוספים אנא פנו לצוות ההנהלה.";
  exit();
}

}

///////////////////////
function vote( ) {
///////////////////////

checkuser();

$ip $_SERVER['REMOTE_ADDR'];
$poll_id $_POST['poll_id'];
$answer_id $_POST['answer_id'];
$now date('Y-m-d g:i:s a');

include 
'db.php';
$check mysql_query("SELECT * FROM poll_votes WHERE ipaddress = '$ip' AND poll_id = '$poll_id' LIMIT 1") or die(mysql_error());
if (
mysql_num_rows($check) <= 0) {
  
mysql_query("INSERT INTO poll_votes (poll_id, answer_id, ipaddress, time) VALUES ('$poll_id', '$answer_id', '$ip', '$now')") or die (mysql_error());
  echo 
"תודה על ההצבעה! כעת אתה יכול לצפות ב<a href=\"poll.php?method=results&id=$poll_id\">תוצאות הסקר</a>";
} else {
  echo 
"כבר הצבעת בסקר זה!";
}

}

///////////////////////
function results( ) {
///////////////////////

$id $_GET['id'];
include 
'db.php';

echo 
"<table class=\"content\" width=\"100%\">";
    
$votes mysql_query("SELECT * FROM poll_votes WHERE poll_id = '$id'") or die(mysql_error());
    
$total mysql_num_rows($votes);

// Get Available answers
    
$ans_check mysql_query("SELECT * FROM master_poll, poll_answers WHERE master_poll.id = poll_answers.poll_id AND poll_answers.poll_id = '$id'") or die (mysql_error());
    
$r mysql_fetch_assoc($ans_check);
    
$answers mysql_num_rows($ans_check);
    echo 
"<tr><td colspan=3><b>".$r['question']."</b></td></tr>";

// query each answer
for ($i=1$i <= $answers$i++)
{
    
$check2 mysql_query("SELECT poll_answers.id AS ans_id, poll_answers.answer AS answer, master_poll.id AS poll_id, Count(poll_votes.answer_id) AS results
    FROM
    (master_poll INNER JOIN poll_answers ON master_poll.id = poll_answers.poll_id)
    LEFT JOIN poll_votes ON poll_answers.id = poll_votes.answer_id
    WHERE master_poll.id = '$id' and poll_answers.id = '$i'
    GROUP BY master_poll.question, poll_answers.answer"
) or die(mysql_error());
    
$r2 mysql_fetch_assoc($check2);
    
$a_count $r2['results'];
    
$a_final = (($r2['results'] / $total)*100);
    echo 
"<tr>
          <td>"
.$r2['answer']."</td>
          <td>$a_count</td>
          <td>"
.number_format($a_final0)."%</td>
          </tr>"
;
}

echo 
"</table>";

}

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html dir="rtl">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<style type="text/css">

.content
{
    margin: .2cm .2cm .2cm .2cm;
    font-family: arial;
    font-size: 10pt;
    color: #000000;
}

.latest
{
    background: #3366CC;
    text-align: center;
    font-family: verdana;
    font-size: 10pt;
    color: #ffffff;
}

.copyright
{
    margin: .2cm .2cm .2cm .2cm;
    font-family: arial;
    font-size: 10pt;
    color: #000000;
}

</style>

</head>

<body>

    <div class="content">
    <?php
        $method 
$_GET['method'];
        switch (
$method)
        {
            case 
viewpoll:
            
viewpoll();
            break;
            case 
vote:
            
vote();
            break;
            case 
results:
            
results();
            break;
            default:
            
listpolls();
        }
    
?>
    </div>
</body>
</html>


eXtaZa 01-06-06 12:32

תפנה לכתובת poll.php?id=342 עם HEADER:
PHP קוד:

header("Location: poll.php?id=342"); 


-VladK- 01-06-06 12:35

מה זה עוזר לי שאני מפנה....יש לי עמוד....עם מלא טקסט ויש לי תיבה מיוחד בשביל הסקר...עכשיו הסקר נמצא בקובץ אחר...כיצד אני יכול לעשות את הפעולה של הIFRAME רק שבPHP???? בגלל שIFRAME לא מקצועי לדעתי וגם הוא פוגע קצת בעיצוב :-/

Valid 01-06-06 13:44

אי אפשר.
אתה יכול לעשות משהו נורא נורא מכוער
PHP קוד:

require("http://your.website.co.il/poll.php?id=123"); 

אבל אני לא רואה שום טעם.. זה אדיוטי
פשוט תערוך את הדף סקר שלך ותאנקלד אותו כמו בנאדם

Itay 01-06-06 13:47

ממ אולי חשבת על הבסיס הכי פשוט? אם אתה עושה אינקלוד לקובץ שנמצא על השרת - הקוד פשוט נכנס לתוך העמוד שבו עשית את האינקלוד, כלומר אתה צריך להעביר את ה-ID מספר 567 נגיד, אז לפני האינקלוד אתה מגדיר
$id = 567;
ובקובץ שאותו אתה מכניס, אתה ניגש עם $id (ובמקרה שאתה צריך שיגש גם אל ה-GET אז תעשה ניתוב של אם יש ערך ב-GET או לא)

http://il.php.net/include
תסתכל פעם הבאה ב-php.net, במקרה הזה הדוגמא האחרונה שם הייתה עוזרת לך

-VladK- 01-06-06 16:33

תודה עזרתם לי ! חבל שאני צריך עכשיו לכתוב תקובץ מחדש אבל חפיף...זה לא כזאת בעיה (בציניות)


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

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