how to get the data when there are multiple buttons

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
angelina
Forum Newbie
Posts: 6
Joined: Fri May 16, 2008 5:53 am

how to get the data when there are multiple buttons

Post by angelina »

hi.. i am not tat familiar wit PHP.. here is my problem..

i have to prints some thing like this-

TEXT 1 vote up vote down

TEXT 2 vote up vote down

TEXT 3 vote up vote down

TEXT 4 vote up vote down

TEXT 5 vote up vote down

i am using a loop to print all that is in red.. while i do this.. i am displaying the buttons too in the same loop.

now how do i get the data when that button is clicked??
User avatar
highjo
Forum Contributor
Posts: 118
Joined: Tue Oct 24, 2006 1:07 pm

Re: how to get the data when there are multiple buttons

Post by highjo »

I think your post is a little hard to follow or understand.what is in red are text and what is in blue are buttons?What are text are printed by a loop right?So you want to click on a button to make something appear right?If you know javascript and a little css you can do it.for now try to be explicite to have answers.ok? :D
angelina
Forum Newbie
Posts: 6
Joined: Fri May 16, 2008 5:53 am

Re: how to get the data when there are multiple buttons

Post by angelina »

yup.. sorry i forgot to mention that.. ones in blue vote_up vote_down are the buttons..
angelina
Forum Newbie
Posts: 6
Joined: Fri May 16, 2008 5:53 am

Re: how to get the data when there are multiple buttons

Post by angelina »

yes the text is in the loop.. n the buttons are also printed in the same loop..
say.. if button vote_up is pressed for Text_1 i will have to insert some changes in the DB.. how do i get that its the TEXT 1
nowaydown1
Forum Contributor
Posts: 169
Joined: Sun Apr 27, 2008 1:22 am

Re: how to get the data when there are multiple buttons

Post by nowaydown1 »

One way would just be to set the value of your vote_up, vote_down buttons to something relevant to what your text is:

Code: Select all

 
TEXT 1
<input type="submit" name="voteUp" value="Text1" />
<input type="submit" name="voteDown" value="Text1" />
 
TEXT 2
<input type="submit" name="voteUp" value="Text2" />
<input type="submit" name="voteDown" value="Text2" />
 
User avatar
highjo
Forum Contributor
Posts: 118
Joined: Tue Oct 24, 2006 1:07 pm

Re: how to get the data when there are multiple buttons

Post by highjo »

if the db from where you are fetching the data for text has a unique field lest's say id then it would be simple.you have to create a new file to do the edit or the database update part for you.Do you know about query string?if yes you should understand what i'm going to tell you if not you have to post you code so that i can see it right?
ok let's back to the explanation.
in th loop i want you to remove the buttons and print html links i mean the <a></a> stuff for each text ok?
after that in your query to select the text select a field that uniquely identify your text.i assume the field name to be id.

Code: Select all

 
while($row = mysqli_fetch_array($query))
{
 //this is for explantion purpose only right?
  echo " <a href='updatefile.php?id=$row[id]'>$row[text]";
}
 
then in the file updatefile should be the one that would process the update part of the work with the query that is suppose to be executed.
If it is buttons i suppose you would echo <form></form> element for each.then in the action you do the same query string.we cool? :)
angelina
Forum Newbie
Posts: 6
Joined: Fri May 16, 2008 5:53 am

Re: how to get the data when there are multiple buttons

Post by angelina »

thanks nowaydown1 n highjo for help!!!
User avatar
highjo
Forum Contributor
Posts: 118
Joined: Tue Oct 24, 2006 1:07 pm

Re: how to get the data when there are multiple buttons

Post by highjo »

i'm not sure i understand but it's ok :D .It seems you don't speak english.If you speak french and still having problem, you can write a private message to explain your problem and i'll reply in french for it.
angelina
Forum Newbie
Posts: 6
Joined: Fri May 16, 2008 5:53 am

Re: how to get the data when there are multiple buttons

Post by angelina »

thanks for ur concern highjo.. i really appreciate it!!!! :)
Post Reply