0

我有一个域,其中用户有一个具有自己名称的子域。

例子:

  • 用户:维托
  • 子域:vitor.google.com

该数据库具有user列表,my_users并具有列birthdayaddress、和in 表。我如何在 PHP 中做到这一点,才能将这些信息直接用户访问数据库?passwordcitystateusers_infosindex.php

这是我的错误代码:

// Get Subdomain
$urlExplode = explode('.', $_SERVER['HTTP_HOST']);
if (count($urlExplode) > 2 && $urlExplode[0] !== 'www') {
    $subdomain = $urlExplode[0];    
    echo $subdomain;
}


// Select DB
$sql = "SELECT * FROM users_infos i INNER JOIN my_users u on u.id = i.id where u.users='$users'"; 
    $result = mysql_query($sql); 
    if($result === FALSE) { 
    die(mysql_error());
     // TODO: better error handling 
    }

else {
$row = mysql_fetch_array($result);
$userTitleSite = $row['userTitleSite'];
echo $id_textos = $row["id_textos"];
echo "<br />";
echo $id = $row["id"];
echo "<br />";
echo $phone = $row["phone"];
echo "<br />";
echo "<br />";

}

// Says that the subdomain is = user
$subdomain = $user;

正确答案如下:

使用您给我的帮助,看起来我到了这里.. 遵循我可以为有相同问题的未来用户执行的正确代码:

// Get subdomain
$urlExplode = explode('.', $_SERVER['HTTP_HOST']);
if (count($urlExplode) > 2 && $urlExplode[0] !== 'www') {
    $subdomain = $urlExplode[0];    
    echo $subdomain;
}


// Says that the subdomain is = user
$user = $subdomain;


// Select DB
$sql = "SELECT * FROM vms_textos i INNER JOIN vms_users u on u.id = i.id where u.user='$user'"; 
    $result = mysql_query($sql); 
    if($result === FALSE) { 
    die(mysql_error());
     // TODO: better error handling 
    }

else {
$row = mysql_fetch_array($result);
$userTitleSite = $row['userTitleSite'];
echo "<br />";
echo $id_textos = $row["id_textos"];
echo "<br />";
echo $user= $row["user"];
echo "<br />";
echo $id = $row["id"];
echo "<br />";
echo $telefone = $row["telefone"];
echo "<br />";
echo "<br />";

}

echo "<br />";
echo "<br />";

谢谢大家帮助我!:)

4

2 回答 2

0

你确定 WHERE 子句u.id = i.id是正确的吗?换句话说,您的 my_users 和 users_infos 表中的 ID 列是否匹配?在 users_infos 表(例如 my_users_id)上有一个外键引用更为常见,在这种情况下,查询将类似于:

SELECT * 
FROM users_infos i 
INNER JOIN my_users u on u.id = i.my_users_id
WHERE u.users='$users'
于 2013-10-26T14:15:54.417 回答
0
$subdomain = $user;

应该在 $sql 之前,因为你的代码是写的 $user 是空的。

于 2013-10-26T14:04:42.747 回答