if(isset($_GET['action']) && $_GET['action']=='album_id=$album['id']')
現在,我相信大家可以看到這裏的錯誤我想檢查該鏈接被點擊如何調用isset時調用或傳遞此變量?
<a href="<?php echo $profile_data['username'];?>?action=album_id=<?php echo $album['id'];?>">
現在這個鏈接的作品,並顯示它應該在URL中,但我不能弄清楚如何將$ album ['id']傳遞給if語句isset?
編輯
好,我這樣做:
<a href="<?php echo $profile_data['username'];?>?action=album_id&action_id=<?php echo $album['id'];?>">
和
if($_GET['action'] == 'album_id' && $_GET['action_id'] == $album['id'])
,並在返回的不確定變量,如果聲明說,這張專輯是不確定的變量
這是我的htaccess file:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /lr/profile.php?username=$1 [QSA]
這裏是我的整個PHP文件:
<?php
include 'core/init.php';
include 'init.image.php';
protect_page();
include 'includes/overall/overall_header.php';
if(isset($_GET['username']) === true && empty($_GET['username']) === false){
$username = $_GET['username'];
if(user_exists($username) === true){
$user_id = user_id_from_username($username);
$profile_data = user_data($user_id, 'first_name','last_name','email', 'username');
?>
<h1><?php echo $profile_data['first_name']; ?>'s Yor Page</h1>
<div id="navWrapper">
<ul>
<li>
<a href="#"><img src="uploads/profile/blank_profile.gif" width="150" height="150" id="blank_profile"></a>
</li>
<nav>
<ul>
<li>
<a href="<?php echo $profile_data['username'];?>?action=albums">Albums</a>
</li>
<li>
<a href="<?php echo $profile_data['username'];?>?action=music">Music</a>
</li>
</ul>
</nav>
</ul>
</div>
<?php
if(isset($_GET['action']) && $_GET['action']=='albums'){
$albums = get_profile_albums($user_id);
if(empty($albums)){
echo 'No Albums';
}else{
foreach($albums as $album){
if (empty($album['image'])) {
$album['image'] = 'uploads/profile/blank_profile.gif';
}
?>
<p><?php echo $album['name'],' (', $album['count'], ')'?> <br />
<a href="<?php echo $profile_data['username']; ?>?action=album&album_id=<?php echo $album['id']; ?>">
<img src="uploads/thumbs/<?php echo $album['id'];?>/<?php echo $album['image'];?>" />
</a><br />
<?php echo $album['description'];?>...<br />
</p>
<?php
}
}
}
else if (isset($_GET['action']) && $_GET['action']=='album' && isset($_GET['album_id'])){
echo 'albums';
}
if(isset($_GET['action']) && $_GET['action']=='music'){
echo'<h1>Music</h1>';
}
}else{
echo 'Sorry, that user doesn\'t exist';
}
}else{
header('Location: index.php');
exit();
}
include 'includes/overall/overall_footer.php';
?>
你能真正做到這一點?把參數放在url中,比如'action = album_id = 1'? – lusketeer 2012-08-02 01:54:42
是的,它返回使用該鏈接點擊的任何相冊的相冊ID。 – 2012-08-02 01:56:18
感覺有點奇怪,也許我還是有點新的PHP,但我會建議另一種方式 – lusketeer 2012-08-02 01:57:51