Page 1 of 1

PHP code with no output returned,please help!

Posted: Mon Mar 14, 2011 2:16 am
by ponyyune
<?php
mysql_connect ("localhost", "root","") or die ('Error : '.mysql_error());
mysql_select_db("keyword");

$question_text = $_POST['question_text'];

list($first_word) = explode(' ', $question_text);

$query ="SELECT c.field_name,t.category_name, d.domain_name FROM category_fields c, taxonomy_category t, taxonomy_domain d
WHERE c.category_Id = t.category_Id AND t.domain_Id = d.domain_Id
AND c.field_name = '$first_word'";

$result = mysql_query($query);

while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
echo "Keyword :{$row['c.field_name']} <br>" .
"Category : {$row['t.category_name']} <br>" .
"Domain : {$row['d.domain_name']} <br><br>";
}
?>
The output i get did not return the result as stated in query.It displays only the table form by echo above.Is there anything wrong with my code ?

I have a database with 3 tables (category_fields,taxonomy_category,taxonomy_domain)

Re: PHP code with no output returned,please help!

Posted: Mon Mar 14, 2011 6:37 am
by cpetercarter
I think that the problem is that $first_word is an array, not a string, so that the SQL query does not make sense. Try echoing $query to make sure that it says what you want it to say.