Page 1 of 1

Php code dont return data

Posted: Sat Nov 12, 2011 5:56 pm
by williamh262000
Hi, I have the following tables:
topic
topic_id int(10) AUTO_INCREMENT
sub_id int(10)
topic
problems
problem_id int(10) AUTO_INCREMENT
topic_id int(10)
problem
THIS IS MY CODE TO GET THE PROBLEMS FROM EACH TOPIC

Code: Select all

<?php
 login();
         $topic_id = $_GET['cat'];
         $query="SELECT  problem_id, problem from problems WHERE topic_id=$topic_id ORDER BY problem ASC";
         $result=mysql_query($query);
         while($row=mysql_fetch_array($result,MYSQL_ASSOC))
         {

                  $problem_id = $row['problem_id'];
                  $problem = $row['problem'];

             echo "<h3><a href=\"index.php?content=answers&cat=$topic_id\">$problem</a></h3><br>\n";
         }
?>
But returns repeadeatly the same problems in each topic.... how i can fix it. ... thanks for you cooperation

Re: Php code dont return data

Posted: Sun Nov 13, 2011 1:32 pm
by danwguy
don't assign it to a var in the while statement if you are going to echo it out at the same time also I always surround my queries with single quotes when using =, just use

Code: Select all

$topic_id = $_GET['cat'];
$query="SELECT problem_id, problem from problems WHERE topic_id = '$topic_id' ORDER BY problem ASC";
$result=mysql_query($query);
while($row=mysql_fetch_assoc($result))
{

echo "<h3><a href='index.php?content=answers&cat=".$topic_id."'>".$row['problem']."</a></h3><br>\n";
}
?>

Re: Php code dont return data

Posted: Mon Nov 14, 2011 7:15 pm
by williamh262000
still does not work... it returns always the same problem from the topics...

Code: Select all

http://localhost/chemath.com/index.php?content=topics&cat=1
the cat=1 is always return for the topic 1, topic 2 ....etc

when it suppose to be cat=2 for topic 2... etc