php - Displaying links for similar articles -


i have page want display articles 1 you're reading (randomly chosen articles same subcategory). want use php script server says have error. here script:

$article = mysqli_query($con,"select * sources id = '$id'"); while($row = mysqli_fetch_array($article)) {      code works $samecat = $row['subcategory']; }  $samecats = explode(', ', $samecat);   foreach($samecats $similar){       $scat[] = "subcategory %".$similar."%";   }   echo implode(' or ',$scat); $samearticle = mysqli_query($con, "select *  sources  (".implode(' or ',$scat).")  , not id='$id'  order rand()  limit 0,3 "); while($row2 = mysqli_fetch_array($samearticle))  {  echo "<a href='article.php?id=".$row2['id']."'>&raquo "      .$row2['headline']."</a>";  } 

the connection works because works other components have bug here :(((

any alternative solutions fine, think way better.

error is:

warning: mysqli_fetch_array() expects parameter 1 mysqli_result

here problem:

https://eval.in/96729

i simulated code , viewed sql you're generating. it's this:

"select *  sources  (subcategory %test% or subcategory %foo% or subcategory %bar% or subcategory %baz%)  , not id=''  order rand()  limit 0,3 " 

you need singlequotes around terms like:

subcategory '%test%'  

so need to:

$scat[] = "subcategory '%".$similar."%'"; 

really should enable error reporting querying.


Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -