2013-05-11 1 views
0

나는 PHP로 사용하는 선택 쿼리가 있고 내부에 가입하지만, 브라우저에 오류가 표시됩니다 : 당신은 당신의 SQL 구문에 오류가INER의 joinnnn와 코드와 작동하지 않는 선택은

을; 라인 1

에서 '유 INNER SPE 가입 사용자로부터 SELECT specialization_name' 근처를 사용할 수있는 권리 구문에 대한 MySQL 서버 버전에 해당하는 설명서를 확인

이 사람이 나를 도울 수 있습니까?

쿼리입니다 :

if(isset($_POST['listbyq'])) 
{ 
    if($_POST['listbyq']=="newest_members") 
    { 
     $querySrting="WHERE registered_date!='' ORDER BY registered_date DESC " or die(mysql_error()); 
     $queryMSG="Showing senior to oldest memebrs"; 
    } 
elseif($_POST['listbyq']=="by_specialization") 

    { 
     $querySrting="SELECT specialization_name FROM user u  INNER JOIN specialization s  ON u.specialization=s.specialization_id  WHERE u.user_id='$id'"; 

     $result = mysql_query($queryString) or die(mysql_error()); 
     $queryMSG="showing members with specs"; 
    } 
elseif($_POST['listbyq']=="by_firstname") 
    { 
     $fname = $_POST['fname']; 
     $fname = stripcslashes($fname); 
     $fname = strip_tags($fname); 
     $querySrting="WHERE first_name LIKE '%$fname%'"or die(mysql_error()); 
     $queryMSG="Showing member with the name you searched for"; 
    } 
} 
///******query the member data using the queryString*******// 
$sql = mysql_query("SELECT user_id, first_name, last_name, birth_date, registered_date FROM user $querySrting") or die(mysql_error()); 
//**********************outputlist*********************************// 
$outputlist=""; 
while($row = mysql_fetch_array($sql)) 
{ 
    $id=$row['user_id']; 
    $firstname=$row['first_name']; 
    $lastname=$row['last_name']; 
    $birthdate=$row['birth_date']; 
    $spec = $row['specialization']; 
    $registereddate=$row['registered_date']; 
    ////***********for the upload image*************************// 
     $check_pic="members/$id/image01.jpg"; 
    $default_pic="members/0/image01.jpg"; 
    if(file_exists($check_pic)) 
    { 
     $user_pic="<img src=\"$check_pic\"width=\"120px\"/>"; 
    } 
    else 
    { 
     $user_pic="<img src=\"$default_pic\"width=\"120px\"/>"; 
    } 

    $outputlist.=' 
    <table width="100%"> 
       <tr> 
        <td width="23%" rowspan="3"><div style="height:120px;overflow:hidden;"><a href = "http://localhost/newadamKhoury/profile.php?user_id='.$id.'" target="_blank">'.$user_pic.'</a></div></td> 
        <td width="14%"><div align="right">Name:</div></td> 
        <td width="63%"><a href = "http://localhost/newadamKhoury/profile.php?user_id='.$id.'" target="_blank">'.$firstname.' '.$lastname.'</a></td> 
        </tr> 

        <tr> 
        <td><div align="right">Birth date:</div></td> 
        <td>'.$birthdate.'</td> 
        </tr> 
        <tr> 
        <td><div align="right">Registered:</div></td> 
        <td>'.$registereddate.'</td> 
        </tr> 
        </table> 
        <hr /> 
      '; 

}//close while 

?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta name="keywords" content="" /> 
<meta name="description" content="" /> 
<meta http-equiv="content-type" content="text/html; charset=utf-8" /> 
<title>Search_Members</title> 
<link href='http://fonts.googleapis.com/css?family=Oswald:400,300' rel='stylesheet' type='text/css' /> 
<link href='http://fonts.googleapis.com/css?family=Abel|Satisfy' rel='stylesheet' type='text/css' /> 
<link href="default.css" rel="stylesheet" type="text/css" media="all" /> 
<!--[if IE 6]> 
<link href="default_ie6.css" rel="stylesheet" type="text/css" /> 
<![endif]--> 
</head> 
<body> 
<?php require_once('header.php'); ?> 
<div id="wrapper"> 
    <div id="page-wrapper"> 
     <div id="page"> 
      <div id="wide-content"> 


       <table width="94%" height="63"> 
       <tr> 
        <td width="29%"><form id="form1" method="post" action="member_search.php"> 

        Browse Newest Members 
        <input type="submit" name="button" id="button" value="go" /> 
        <input type="hidden" name="listbyq" value="newest_members" /> 
        </form></td> 
        <td width="28%"><form id="form2" name="form2" method="post" action="member_search.php"> 
        Search By specialization<br /> 
        <select name="specialization" class="formField"> 
         <option value="0">-- Select Your Specialization --</option> 

          <?php specializationQuery(); ?> 
        </select> 


        <input type="submit" name="button2" id="button2" value="go" /> 
        <input type="hidden" name="listbyq" value="by_specialization" /> 
        </form></td> 
        <td width="43%"><form id="form3" name="form3" method="post" action="member_search.php"> 
        Search By firstname 
        <label> 
        <input type="text" name = "fname" id="fname" /> 
        </label> 
        <input type="submit" name="button3" id="button3" value="go" /> 
        <input type="hidden" name="listbyq" value="by_firstname" /> 
        </form></td> 
       </tr> 
       </table> 
       <br /> 
       <table width="70%" align="center"> 
       <tr> 
        <td><?php print "$queryMSG"; ?> 
         <br /> 
         <?php print "$outputlist"; ?> 
        </td> 
       </tr> 
       </table> 
+0

'$ querySrting'을 에코로 붙여 넣을 수 있습니까? – mehdi

답변

0

코드는 쿼리 구문의 마지막에 정렬 문자열을 추가 할 것으로 보인다. 기본 구문은 다음과 같습니다 당신은 다음 문자열 중 하나를 추가

SELECT user_id, first_name, last_name, birth_date, registered_date 
FROM user 

:

$querySrting="WHERE registered_date!='' ORDER BY registered_date DESC " 

    $querySrting="SELECT specialization_name FROM user u  INNER JOIN specialization s  ON u.specialization=s.specialization_id  WHERE u.user_id='$id'"; 

    $querySrting="WHERE first_name LIKE '%$fname%'"or die(mysql_error()); 

흠. 이 중 하나가 기본 select . . . from 성명 뒤에 맞지 않습니다.

$querySrting="order by (SELECT specialization_name FROM user u  INNER JOIN specialization s  ON u.specialization=s.specialization_id  WHERE u.user_id='$id')"; 

또는 간단한 버전 :, 당신이 할 수 중간 예를하지만 order by 문에서 하위 쿼리 해결하려면

$querySrting="order by (SELECT specialization_name FROM specialization s WHERE s.user_id=user.user_id"; 

하지만, 읽을 수있는 전문화 아마 유용을, 그래서에 넣어 기본 쿼리 :

SELECT user_id, first_name, last_name, birth_date, registered_date, specialization_name 
FROM user u left outer join 
    specialization s 
    on u.specialization = s.specialization_id 

그리고 단지 중앙 정렬합니다

관련 문제