Jump to content

Recommended Posts

Hi everyone.

I have a problem that so far no one can help me with. It must be quite easy, as 've seen it done lots.

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 'while 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 with each time it loops loop. (e.g loop1 = form1, loop2 = form2 ect)
At the moment 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]
while ($row = mysql_fetch_array($result)) {




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

      echo "<INPUT type='hidden' name='ID' value='".$row['ID']."'> \n";

echo '<tr>
  <td align="center" class="loginBox_text">
<br>'.$row['date'].'
  </td>
  </tr>
  <tr>
<TD align="center"><A HREF="javascript:document.excel1.submit();" class="loginBox_text">'.$row['title'].'</a></TD>';
echo '</form>';
echo '</tr>';
echo '</table>';



}



[/code]

Thanks for any help

Link to comment
https://forums.phpfreaks.com/topic/14300-re-naming-a-form-inside-a-while-loop/
Share on other sites

The real question is why do you need one form per line. That is a weird design. What is the function of the form? You have no user accessible fields in the form. If you tell us what you're trying to do, perhaps we can show you a better design.

Ken
Hi,

I'm very new to php and am trying to wright my own code. Proving to be very difficult, and very messy.
I know there is an easyer way to do this but i dont know how.

I am trying to build a new article.

page 1.
     This page lists all of the 'dates' and news 'titles' (the new titles are links to there news article.)

Page 2.
      This page show the news article.

Now, if i use a normal submit button (e.g read article) then it works.
but i want it so the 'title' is the submit button.

I hope i'm making sence.
goto [url=http://www.spirestest.com/login2/news]http://www.spirestest.com/login2/news[/url] and you will see what i mean.

Thanks
Hi,


Am i getting closer?
Ive taken out the form, and am now trying to pass the ID through a link.
Not to sure how this is done though.

Any help please.

[code]
while ($row = mysql_fetch_array($result)) {




echo '<table width="340" bgcolor="#FFFFFF" cellpadding="0" cellspacing="0" align="center">';
echo '<tr>
  <td align="center" class="loginBox_text">
<br>'.$row['date'].'
  </td>
  </tr>
  <tr>
<TD align="center"><A HREF="news_art.php?'.$row['ID'].'" class="loginBox_text">'.$row['title'].'</a></TD>';

echo '</tr>';
echo '</table>';

}

[/code]
in your link
<A HREF="news_art.php?'.$row['ID'].'" class="loginBox_text">

change it to:
<A HREF="news_art.php?id='.$row['ID'].'" class="loginBox_text">


then, on the news_art.php page add:

$id = $_GET['id'];

and there you have it. you will have passed the variable through the URL and received it on the next page.
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.