0

I want to retrieve data from database using ajax the data is retrieving successfully but it is not showing properly on page. Maybe it is the issue of if else condition.

Here is my code:

<?php


        $query = mysql_query("SELECT * FROM cart_polling WHERE country = '".$_REQUEST['id']."' ORDER BY sort_order ASC") or die(mysql_error());
        $record = mysql_num_rows($query);


        while($getcontry = mysql_fetch_array($query)){
        ?>    
    <div class="Question_Table">  
      <div class="Question_Title">Q<?php echo $getcontry['sort_order']; ?>-<?php echo $getcontry['question']; ?></div>

<!-- ****** Box1 START ****** -->

    <?php 
    if($getcontry['img1']!=""){ 

    ?>
    <div class="bg">
    <?php
    if(isset($_SESSION['id'])){

    ?>
    <div class="img"><center>
      <a href="javascript:void(0)" class="op">
<img src="images/pollimg/<?php echo $getcontry['img1']; ?>" width="104" height="102" class="middleimg2" onclick="getValue('<?php echo $_REQUEST['id']; ?>','<?php echo $getcontry['option1']; ?>','<?php echo $getcontry['id']; ?>','1','<?php echo $getcontry['img1'] ?>','<?php echo $getcontry['categoryname'] ?>','<?php echo $getcontry['question']; ?>')"  /></a>
</center></div>

<?php } ?>


<div class="Vote_button">
<img src="images/vote_button.png" onclick="sendvar();" align="middle">



    <img src="images/view_results.png" onClick="showresult(<?php echo $getcontry['id']; ?>)" align="middle">
</div>
<?php
}



</div>
<?php } ?> // here the while loops end.

I want (<div id="txtHint<?php echo $getcontry['id']; ?>"></div>) this in else condition and the above code in if condition when I click on image viewresult.png a function call which retrieve data from database. I want the data will show in else condition and the above code including loop shows in if condition.

The txtHint($getcontray['id']) is the id of every record whose value changes dynamically with the help of while loop. And txthint is also saves the response of ajax.

If I am using if condition than while loop is not running in else condition and the id can't pass to AJAX response and the correct data will not show, so how can I do that?

halfer
  • 19,824
  • 17
  • 99
  • 186
  • 2
    You are using [an **obsolete** database API](http://stackoverflow.com/q/12859942/19068) and should use a [modern replacement](http://php.net/manual/en/mysqlinfo.api.choosing.php). You are also **vulnerable to [SQL injection attacks](http://bobby-tables.com/)** that a modern API would make it easier to [defend](http://stackoverflow.com/questions/60174/best-way-to-prevent-sql-injection-in-php) yourself from. – Quentin Jan 27 '13 at 16:18
  • I've re-paragraphed your question to make it marginally easier to understand. Notwithstanding, I'm afraid the last three paragraphs are quite hard to follow - would you consider simplifying them? If you split your explanations into shorter sentences, often the resulting text is easier to parse. – halfer Jan 27 '13 at 21:07

1 Answers1

0

in line: <img src="images/pollimg/

'<?php echo $getcontry['img1'] ?>','<?php echo $getcontry['categoryname'] ?>'

missing 2 semicolon.

'<?php echo $getcontry['img1']; ?>','<?php echo $getcontry['categoryname']; ?>'

UPDATE: And missing ?> php end syntax at the bottom of your file:

<?php
}
//here is the missing tag:
?>

</div>
<?php } ?> // here the while loops end.