Forum Moderators: coopster
I am fetching the data from a database and displaying it.
while ($row = mysql_fetch_assoc($result)) {
?><p> <div id="txtHint" align="center"><div align="center"> <?
echo "<table><tr><td>"?><div align="left"><? echo" Company Name : </td><td>"?><div align="left"><? echo $row['company'] . "</td><tr><td>"?><div align="left"><? echo" Date : </td><td>"?><div align="left"><? echo $row['date'] ."</td><tr><td>"?><div align="left"><? echo" Quantity : </td><td>"?><div align="left"><? echo $row['quantity']. "</td><tr><td>"?><div align="left"><? echo" Total Transaction Value : </td><td>"?><div align="left"><? echo $row['transaction']."</td><tr><td>"?><div align="left"><? echo" Bookerage : </td><td>"?><div align="left"><? echo $row['bookerage']."</td><tr><td>"?><div align="left"><? echo" Pmt Amt : </td><td>"?><div align="left"><? echo $row['pmt']."</td></tr></table>" ;
?></div>
</div> <div id ="buy"><a href="javascript: showdiv('buyform')">Show</a></div><div id="buyform" style="display:none ">HI</div></p>
<? }
?>
It is working fine, but u must have noticed that the div "buyform" is being added everytime. What I want is that everytime the user clicks on "Show"....it must show the div-buyform.
But this code displays buyform only on the first click, not everytime :(
I suppose some loop has to be created on the div name. Please help me, its urgent!
Regards,
Ayush
A numerical indice should do the trick. So, outside of your while loop put:
$count = 0;
Then inside your while loop:
while ($row = mysql_fetch_assoc($result)) {
$new_count = $count++;
and add the count to your code like this:
<div id ="buy"><a href="javascript: showdiv('buyform<?php echo $new_count;?>')">Show</a></div><div id="buyform<?php echo $new_count;?>" style="display:none ">HI</div>
I`ve not seen the javascript you use, but I assume something like that would work?
dc
<div id ="buy"><a href="javascript: showdiv('buyform<?=$i?>')">Show</a></div><div id="buyform<?=$i?>" style="display:none ">HI</div></p>
increment your $i at the 'TOP' of every loop with $i++;
This way each div will have a different name and you will only open the div you click on
Hope that helps if I understand you problem correctly
Trent
Now one more thing :
What do I have to change in this?
[codes]
<script language="javascript">
function showdiv() {
if (document.getElementById){
obj2 = document.getElementById('buyform');
if (obj2.style.display == "none"){
obj2.style.display = "";
} else {
obj2.style.display = "";
}
}
}
</script>
[/codes]