spires Posted July 8, 2006 Share Posted July 8, 2006 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 articlerelated 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 Quote Link to comment https://forums.phpfreaks.com/topic/14020-the-name-the-form-and-the-for-loop-sounds-like-a-movie/ Share on other sites More sharing options...
mrwhale Posted July 8, 2006 Share Posted July 8, 2006 Use a while instead of for.The way your are doing it is wierd :p Quote Link to comment https://forums.phpfreaks.com/topic/14020-the-name-the-form-and-the-for-loop-sounds-like-a-movie/#findComment-54756 Share on other sites More sharing options...
spires Posted July 8, 2006 Author Share Posted July 8, 2006 Could you explain a bit more please? ;D Quote Link to comment https://forums.phpfreaks.com/topic/14020-the-name-the-form-and-the-for-loop-sounds-like-a-movie/#findComment-54763 Share on other sites More sharing options...
GingerRobot Posted July 8, 2006 Share Posted July 8, 2006 [code]<?phpwhile($row = mysql_fetch_array($result){//rest of your code - access database values in the same way.}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/14020-the-name-the-form-and-the-for-loop-sounds-like-a-movie/#findComment-54767 Share on other sites More sharing options...
spires Posted July 8, 2006 Author Share Posted July 8, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/14020-the-name-the-form-and-the-for-loop-sounds-like-a-movie/#findComment-54773 Share on other sites More sharing options...
kenrbnsn Posted July 8, 2006 Share Posted July 8, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/14020-the-name-the-form-and-the-for-loop-sounds-like-a-movie/#findComment-54823 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.