0

Well im working on a small php script and i made a query to connect to db like this:

$id = mysql_real_escape_string(strip_tags($_POST['keyword']));
$query = mysql_query("select * from kalimat WHERE name LIKE '%$id%' OR content like '%$id%'");
while($row=mysql_fetch_assoc($query))
{
    echo "<a href='interpretation-".$row['id'].".html'><li>".$row['name']."</li></a>";
}

Now i want to echo the result of select from names then echo the result of selecting from content thank you in advance.

4
  • 2
    Please do not use the mysql_ functions, theyre deprecated. Use mysqli instead Commented Jul 3, 2014 at 10:20
  • I'm not sure I understand what you are trying to do? Do you want to make new select statements or just check which of the results matched on name and which on content? Maybe use an if statement to check if name or content matches? Commented Jul 3, 2014 at 10:20
  • please explain it more... Commented Jul 3, 2014 at 10:21
  • @aniri the current querry show me result in random order i want to show the records that match the name then the records than match the content Commented Jul 3, 2014 at 10:21

1 Answer 1

2

Try that

   select * from kalimat WHERE name LIKE '%$id%' OR content like '%$id%'
   order by  CASE WHEN name    LIKE '%$id%' THEN 0
                  WHEN content LIKE '%$id%' THEN 1 END
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.