Jump to content


Photo

re-naming a form inside a while loop???


  • Please log in to reply
7 replies to this topic

#1 spires

spires
  • Members
  • PipPipPip
  • Advanced Member
  • 492 posts

Posted 11 July 2006 - 03:07 PM

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

	
	}




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 kenrbnsn

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

Posted 11 July 2006 - 03:14 PM

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

#3 micah1701

micah1701
  • Members
  • PipPipPip
  • Advanced Member
  • 613 posts
  • LocationEllington, CT USA

Posted 11 July 2006 - 03:17 PM

that was my question, why  use forms at all? if its just to go to an article, why not just make it a link?
"Confidence in the face of risk."

#4 spires

spires
  • Members
  • PipPipPip
  • Advanced Member
  • 492 posts

Posted 11 July 2006 - 03:21 PM

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 http://www.spirestest.com/login2/news and you will see what i mean.

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

#5 spires

spires
  • Members
  • PipPipPip
  • Advanced Member
  • 492 posts

Posted 11 July 2006 - 03:26 PM

Hi

Linking 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.


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

#6 spires

spires
  • Members
  • PipPipPip
  • Advanced Member
  • 492 posts

Posted 11 July 2006 - 03:41 PM

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.

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

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

#7 micah1701

micah1701
  • Members
  • PipPipPip
  • Advanced Member
  • 613 posts
  • LocationEllington, CT USA

Posted 11 July 2006 - 03:48 PM

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.
"Confidence in the face of risk."

#8 spires

spires
  • Members
  • PipPipPip
  • Advanced Member
  • 492 posts

Posted 11 July 2006 - 04:06 PM

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.

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users