Jump to content

Archived

This topic is now archived and is closed to further replies.

spires

the name, the form and the for loop. (sounds like a movie :-)

Recommended Posts

Hi everyone.

I have a problem that so far no one can help me with.

I'm pulling out 'Tiltes' from a data base. These title when clicked will goto the news article
related to the title.
              With me so far?
Good.
    The for loop goes through a gets each row (one by one) out of the database and places each row in a form.
Now, heres the problem.
     i can not change the form name for each loop, each title has its own form, but with the same name.
so its only the last title that will go to its destination??

Any way around this???

Heres the code
[code] for ($i = 0; $i < $count; $i++) {
$row = mysql_fetch_array($result);



echo '<table width="340" bgcolor="#FFFFFF" cellpadding="0" cellspacing="0" align="center">';
echo '<form name="form1" action="news_art.php" method="post">';

      echo "<INPUT type='hidden' name='ID' value='".$row['ID']."'> \n";
echo "<INPUT type='hidden' name='date' value='".$row['date']."'> \n";
  echo "<INPUT type='hidden' name='title' value='".$row['title']."'> \n";
  echo "<INPUT type='hidden' name='art' value='".$row['art']."'> \n";
echo '<tr>
  <td align="center" class="loginBox_text">
<br>'.$row['date'].'
  </td>
  </tr>
  <tr>
  <td align="center" class="Title">
'.$row['title'].'
  </td>
  </tr>
  <tr>
<TD align="center"><A HREF="javascript:document.form1.submit();" class="loginBox_text">'.$row['title'].'</a></TD>';
echo '</form>';
echo '</tr>';
echo '</table>';



}[/code]

    Thanks for any help

Share this post


Link to post
Share on other sites
[code]
<?php
while($row = mysql_fetch_array($result)
{
//rest of your code - access database values in the same way.
}
?>
[/code]

Share this post


Link to post
Share on other sites
ok,

But, all that does is the same thing, just loops through the code.

It still doesn't let me change the neme of the form? which is all i need to do.

Any more ideas?

Cheers

Share this post


Link to post
Share on other sites
The big question here is why do you have one form for each title? And why are you using Javascript to submit the forms?

But the answer to your question, assuming you keep your current design.
[code]<?php
    for ($i = 0; $i < $count; $i++) {
    $row = mysql_fetch_assoc($result);
    echo '<table width="340" bgcolor="#FFFFFF" cellpadding="0" cellspacing="0" align="center">';
    echo '<form name="form' . $i .'" action="news_art.php" method="post">'; // make the form names form0 to form(n)
    echo "<INPUT type='hidden' name='ID' value='".$row['ID']."'> \n";
    echo "<INPUT type='hidden' name='date' value='".$row['date']."'> \n";
    echo "<INPUT type='hidden' name='title' value='".$row['title']."'> \n";
    echo "<INPUT type='hidden' name='art' value='".$row['art']."'> \n";
    echo '<tr><td align="center" class="loginBox_text"><br>'.$row['date'].'</td></tr><tr><td align="center" class="Title">'.$row['title'].'
  </td>
  </tr>
  <tr>
    <TD align="center"><A HREF="javascript:document.form' . $i . '.submit();" class="loginBox_text">'.$row['title'].'</a></TD>';
    echo '</form>';
    echo '</tr>';
    echo '</table>';
}?>[/code]

Ken

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.