2016-11-03 3 views
0

は、私は、データベースからmultiableテーブルからより多くのコンテンツを取得しようとしていますが、コードは動作しません 、私のコードに問題があります。エラーPHPのMysqli_fetch_array

これは私が

警告取得しています警告です:mysqli_fetch_array()が Cに与えられた ブール、パラメータ1がmysqli_resultれることを想定しています\ WAMP \ WWW \ Leerjaar2 \ myband2SlideOut \モデル\ getuser.php行に45

$q = $_GET['q']; 
$con = mysqli_connect('localhost','root','','myband'); 
if (!$con) { 
die('Could not connect: ' . mysqli_error($con)); 
} 

mysqli_select_db($con,"myband"); 

$sql="SELECT title.newsarticles, content.newsarticles,  information.newsarticles, title.band, information.band FROM newsarticles FULL OUTER JOIN band ON newsarticles.title=band.title LIKE '%$q%'"; //wildcard 

//$sql="SELECT * FROM newsarticles WHERE title LIKE '%$q%'"; //wildcard 

$result = mysqli_query($con,$sql); 
if (!$sql) { 
printf("Error: %s\n", mysqli_error($con)); 
exit(); 
} 
echo "<table> 
<tr> 
<th>Title</th> 
<th>Content</th> 
</tr>"; 
while($row = mysqli_fetch_array($result)) { 
echo "<tr>"; 
echo "<td>" .$row['title']. "</td>"; 
echo "<td>" .$row['content']. "</td>"; 
} 
echo "</table>"; 
mysqli_close($con); 
+0

'$ sqlを=" SELECT title.newsarticles、content.newsarticles、information.newsarticles、title.band、情報あなたのPHP myadminでこれを実行すると解決策があります。 – devpro

+0

参照してください。このhttp://stackoverflow.com/questions/2973202/mysqli-fetch-array-mysqli-fetch-assoc-mysqli-fetch-row-expects-parameter-1 – Mack4Hack

+0

QUERYが間違っています。 '$ sqlを=" SELECT title.newsarticles、content.newsarticles、information.newsarticles、title.band、information.band「%$ Q%LIKE FULL OUTERがnewsarticles.title = band.title ONバンドに参加newsarticlesとnewsarticles.titleのいずれかから" "; 'や' $ sqlを=" newsarticles FULL OUTER FROM title.newsarticles、content.newsarticles、information.newsarticles、title.bandを選択、information.bandはWHERE LIKE newsarticles.title newsarticles.title = band.title上のバンドに参加します] %$ q% '";' –

答えて

0

あなたのクエリは次のとおりです。

$sql="SELECT title.newsarticles, content.newsarticles, 
information.newsarticles, title.band, information.band FROM newsarticles 
FULL OUTER JOIN band ON newsarticles.title=band.title LIKE '%$q%'" //wildcard 

怒鳴るようON newsarticles.title=band.title後に列名を使用してください:

where column_name LIKE '%$q%'" 

SQL LIKE構文

SELECT column_name(s) 
FROM table_name 
WHERE column_name LIKE pattern; 
+0

がどんなWHEREここで必要です? – devpro

+0

はい 'COLUMN_NAME LIKE '%の$ Qは%'" '' –

+0

$ _GET [ 'Q'] 'クエリはSQLインジェクションのために開いている。 – devpro