spires Posted July 11, 2006 Share Posted July 11, 2006 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 articlerelated 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 Quote Link to comment https://forums.phpfreaks.com/topic/14300-re-naming-a-form-inside-a-while-loop/ Share on other sites More sharing options...
kenrbnsn Posted July 11, 2006 Share Posted July 11, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/14300-re-naming-a-form-inside-a-while-loop/#findComment-56254 Share on other sites More sharing options...
micah1701 Posted July 11, 2006 Share Posted July 11, 2006 that was my question, why use forms at all? if its just to go to an article, why not just make it a link? Quote Link to comment https://forums.phpfreaks.com/topic/14300-re-naming-a-form-inside-a-while-loop/#findComment-56256 Share on other sites More sharing options...
spires Posted July 11, 2006 Author Share Posted July 11, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/14300-re-naming-a-form-inside-a-while-loop/#findComment-56259 Share on other sites More sharing options...
spires Posted July 11, 2006 Author Share Posted July 11, 2006 HiLinking is exactly what i want to do, But if i use a link, how will the next page know what ID to read from?Thats why i have a form, passing a hidden ID feild. Quote Link to comment https://forums.phpfreaks.com/topic/14300-re-naming-a-form-inside-a-while-loop/#findComment-56264 Share on other sites More sharing options...
spires Posted July 11, 2006 Author Share Posted July 11, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/14300-re-naming-a-form-inside-a-while-loop/#findComment-56270 Share on other sites More sharing options...
micah1701 Posted July 11, 2006 Share Posted July 11, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/14300-re-naming-a-form-inside-a-while-loop/#findComment-56274 Share on other sites More sharing options...
spires Posted July 11, 2006 Author Share Posted July 11, 2006 Cheers mate.You are a genius! You did it.Now all that i've got to do is figure out this <PREV> 123456789 <NEXT>' business.[url=http://www.spirestest.com/login2/news/index.php]http://www.spirestest.com/login2/news/index.php[/url]Thanks again Quote Link to comment https://forums.phpfreaks.com/topic/14300-re-naming-a-form-inside-a-while-loop/#findComment-56287 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.