Jump to content


Photo

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


  • Please log in to reply
5 replies to this topic

#1 spires

spires
  • Members
  • PipPipPip
  • Advanced Member
  • 492 posts

Posted 08 July 2006 - 12:04 PM

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
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>'; 
			

	
	}

    Thanks for any help

How to make over $600 a day from AdSense? Discover EXACTLY how he does it in these videos:
http://www.adsense-online.com

#2 mrwhale

mrwhale
  • Members
  • PipPipPip
  • Advanced Member
  • 42 posts

Posted 08 July 2006 - 12:44 PM

Use a while instead of for.

The way your are doing it is wierd :P

#3 spires

spires
  • Members
  • PipPipPip
  • Advanced Member
  • 492 posts

Posted 08 July 2006 - 01:27 PM

Could you explain a bit more please?  ;D
How to make over $600 a day from AdSense? Discover EXACTLY how he does it in these videos:
http://www.adsense-online.com

#4 GingerRobot

GingerRobot
  • Staff Alumni
  • Advanced Member
  • 4,086 posts
  • LocationUK

Posted 08 July 2006 - 01:33 PM

<?php
while($row = mysql_fetch_array($result)
{
//rest of your code - access database values in the same way.
}
?>


#5 spires

spires
  • Members
  • PipPipPip
  • Advanced Member
  • 492 posts

Posted 08 July 2006 - 01:57 PM

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
How to make over $600 a day from AdSense? Discover EXACTLY how he does it in these videos:
http://www.adsense-online.com

#6 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 08 July 2006 - 04:28 PM

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.
<?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>'; 
}?>

Ken




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users