Jump to content

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


spires

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
Link to comment
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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.