Forum Moderators: coopster

Message Too Old, No Replies

loop

plz

         

ayushchd

11:20 am on May 3, 2007 (gmt 0)

10+ Year Member



Hi again,

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

dreamcatcher

11:35 am on May 3, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi 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

eltreno

11:36 am on May 3, 2007 (gmt 0)

10+ Year Member



At a quick guess, looks like you are nameing all your divs buyform, so firstly change the name on every loop, something like,

<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

ayushchd

11:39 am on May 3, 2007 (gmt 0)

10+ Year Member



Thanks A Lot!

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]

eltreno

11:45 am on May 3, 2007 (gmt 0)

10+ Year Member



<script language="javascript">
function showdiv(obj) {
if (document.getElementById){
obj2 = document.getElementById(obj);
if (obj2.style.display == "none"){
obj2.style.display = "";
} else {
obj2.style.display = "";
}
}
}
</script>

That should do it, just add the 'obj' twice where i have above