index.php?id=page

submit

Registered
от доста време се чудя като имам index.php и faq.php и като се напише index.php?id=friends да ви излезе съдържанието на faq.php :) как муже да стане
 
Код:
<?
$id = $_GET['id'];
switch ($id) 
{
case "friends":
include('faq.php');
break;
case "neshto":
include(neshto.php');
break;
default:
include "index.php";
}
?>
това е общо взето...
 
ами..
примерно го записваш във файл menu.php
и после го инклудваш include('menu.php');
и отделно си имаш самото меню което ще е с линковете и ги правиш така примерно де:
<a href="index.php">Начало</a>
<a href="?id=friends">FAQ</a>
<a href="?id=neshto">Neshto</a>
това е принципа...
 
Аз не съм много навътре с PHP ама напраих следния код

Код:
<html>
<a href="index.php">Начало</a> 
<a href="?id=proba">FAQ</a> 
<a href="?id=pro">Neshto</a>
</html>

<?php 
$id = $_GET['id']; 
switch ($id) 
{ 
case "proba": 
include('faq.php'); 
break; 
case "pro": 
include('faqw.php'); 
break; 
default: 
include "index.php"; 
} 

?>

И ми излезоха.... адски много линкове
 
Ами сега нямам хост за да ти покажа.Ако имаш качи го на хоста и виж.Цялата страница се запълва с линковете!
 
m3, този код
Код:
<html> 
<a href="index.php">Начало</a> 
<a href="?id=proba">FAQ</a> 
<a href="?id=pro">Neshto</a> 
</html> 

<?php 
$id = $_GET['id']; 
switch ($id) 
{ 
case "proba": 
include('faq.php'); 
break; 
case "pro": 
include('faqw.php'); 
break; 
default: 
include "index.php"; 
} 

?>

си го сложил в menu.php и си го инклуднал в индекса ли?
аз направих така:
сложих
Код:
 <?php 
$id = $_GET['id']; 
switch ($id) 
{ 
case "proba": 
include('faq.php'); 
break; 
case "pro": 
include('faqw.php'); 
break; 
default: 
include "index.php"; 
} 

?>
в index.php и по-надолу
Код:
<a href="index.php">Начало</a> 
<a href="?id=proba">FAQ</a> 
<a href="?id=pro">Neshto</a>
не съм го слагал в menu.php (или друг) и всичко бачка[/code]
 
В индекса го сложих.А сега с тоя код дето ми го даде ми изписва това:

Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.
 
ем аз дадох примерния код, промени го (тези в червено)според твоите нужди и трябва да работи

<?php
$id = $_GET['id'];
switch ($id)
{
case "proba":
include('faq.php');
break;
case "pro":
include('faqw.php');
break;
default:
include "index.php";
}

?>
 
Ето още един начин да се осъществи това:

index.php
Код:
<center>
<a href="index.php">Начало</a> |
<a href="?id=faq">FAQ</a> |
<a href="?id=contacts">Contacts</a>
</center><hr><br>




<?
if($_GET['id'] == faq) { include "faq.php"; exit(); }
if($_GET['id'] == contacts) { include "contacts.php"; exit(); }
else { 
echo "Това е началната страница";
}

?>

Аз винаги използвам този метод много е известен, но специално аз от никаде не съм го видял просто един ден преди 2-3 години ми хрумна и от тогава го използвам
 
Код:
Warning: include(/index.php) [function.include]: failed to open stream: No such file or directory in E:\XAMPP\xampp\htdocs\proba\include_links.php on line 12

Warning: include() [function.include]: Failed opening '/index.php' for inclusion (include_path='.;E:\XAMPP\xampp\php\pear\') in E:\XAMPP\xampp\htdocs\proba\include_links.php on line 12
142138_orig.jpg

Катето е индекса там е и include_links.php
със съдържание :
Код:
<?
$id = $_GET['id'];
switch ($id)
{
case "reg":
include('./reg.php');
break;
case "log":
include('./login.php');
break;
default:
include "/index.php";
}
?>
 

Back
Горе