How to implement a click on the left record name under PHP conditions, specific content on the right side of the page display?

Source: Internet
Author: User
Tags php foreach
I made a Web page, and the left column is a record name, which I read from MySQL through a looping statement and displayed on each line. The right side is the specific content frame for each record (which is a lot of empty boxes). Want to achieve the goal is: Click on any of the left record name, on the right of the individual empty boxes in the specific content of the record (in fact, the contents of each field to fill in each empty box).
What simple framework should be used to implement the record name on the left can be clicked? Then passed what variables to control the reading record, the specific record information from the MySQL read out (it seems that the record content, displayed in the various empty boxes are not difficult, I can complete this step)? Of course, the specific contents of each record in MySQL already exist, query can be.


Daniel here please help Ah, this is my first time to ask, it is urgent ah. Thank you.


Reply to discussion (solution)

Do it with Ajax.

When you click on the left side of the record name, the record name with Ajax to the background to query the corresponding information returned after the Fill in the box

Thank you for your reply.

Using Ajax, younger brother is a novice, that probably use what important statements or key points, and even have links to the case what I think of it?

Thank you very much.

Just wait till I write you a demo.

Thank you very much first.

Demo Address http://www.colg.biz/demo/d1.php

Code

Show Page

 
 
 
 
 
  
 
 
 
Id Col1 Col2 Col3 Col4
         


Processing a Request page
 
  ". $each." ";}} echo Json_encode ($html); exit;}? >

Sweat... The account password has been leaked ....

Change the

Thank you so much!

The next question is: How to give you the score? Is it just a knot stick?

Ask:

You are divided into the main program and processing the page program, the second processing page program should be ajax.php it? It seems that the ajax.php should be asked to be in the same directory as the Residence program, right?

Ask:

You are divided into the main program and processing the page program, the second processing page program should be ajax.php it? It seems that the ajax.php should be asked to be in the same directory as the Residence program, right?

It's okay to write the path in a different directory. "HTML path" under study

Thank you very much, Daniel, this is exactly what I want.

I'll try to figure out the details, and if you have any details, please enlighten me.

You are welcome to be new, learning a lot of exchanges and common progress have problems directly, you can quote my reply so I can see the reminder in time

Demo Address http://www.colg.biz/demo/d1.php

Code

Show Page

 
 
 
 
 
  
 
 
 
Id Col1 Col2 Col3 Col4
         


Processing a Request page
 
  ". $each." ";}} echo Json_encode ($html); exit;}? >


In the page I want to complete, the empty box on the right is basically empty (as shown in this program), but one is a single option (input form, using radio method). My basic function of this page is to empty the box on the right and select the single option, click on the lower right to save the key, then the record is stored in MySQL, and the new record in the left column shows (has implemented the above features).

Now I click on the left side of a record, such as your demo display, should be able to display the relevant content (I am still learning the details), but the right side of this single option display is difficult. For example, I read two options from the database (1 or 2), how to represent it on a single option (because the small circle before the previous single option is hollow, and if one of them is selected, it becomes a small circle with a solid)?

Thank you, first.

Do you want to click on the left side and then the right two items are not selected or have you selected one of them?

The difference is that the latter has a checked= "checked" in the selected input tag.

Do you want to click on the left side and then the right two items are not selected or have you selected one of them?

The difference is that the latter has a checked= "checked" in the selected input tag.

The existing input form is roughly:
Form action= "main/inputdriver.php" method= "POST" >


Option One


Some of the formatting provisions, omitted here


Option two



When you click on the left, the recording information appears on the right. And on the right side of this single option (with two options), I want one of them to have been selected, the data from the database (1 or 2, and the values of the two options are already set in the form). To ask this question, the main concern is conflict with the previous input form and cannot be taken into account.

When I ask you questions, I feel ashamed of myself, I am a new novice.

Do you ajax use "PHP return all HTML" or "PHP return array with JS to handle"?

If the former is directly output as
Form action= "main/inputdriver.php" method= "POST" >


Option One


Some of the formatting provisions, omitted here


Option two


As to where this checked= "checked" appears, judge and output in the PHP program that the Ajax points to

If the latter, JS processing array with the relevant fields to judge and the need to select the addition of this checked= "checked" can be.



Do you ajax use "PHP return all HTML" or "PHP return array with JS to handle"?

If the former is directly output as
Form action= "main/inputdriver.php" method= "POST" >


Option One


Some of the formatting provisions, omitted here


Option two


As to where this checked= "checked" appears, judge and output in the PHP program that the Ajax points to

If the latter, JS processing array with the relevant fields to judge and the need to select the addition of this checked= "checked" can be.


Have a good experience first.

Here, the younger brother first deeply Zuoyi thanked.

Do you ajax use "PHP return all HTML" or "PHP return array with JS to handle"?

If the former is directly output as
Form action= "main/inputdriver.php" method= "POST" >


Option One


Some of the formatting provisions, omitted here


Option two


As to where this checked= "checked" appears, judge and output in the PHP program that the Ajax points to

If the latter, JS processing array with the relevant fields to judge and the need to select the addition of this checked= "checked" can be.


In combination with my question, it is certainly best to use PHP to return an array.
I read your code carefully, in the demo to you, is not the way to return all HTML PHP?
If I need the way that PHP returns an array, then I need the program in the demo section, the main thing is, how does the Foreach loop in the second paragraph change the details?

Oh, the details are always out of the way.

Demo Address http://www.colg.biz/demo/d1.php

Code

Show Page

 
 
 
 
 
  
 
 
 
Id Col1 Col2 Col3 Col4
         


Processing a Request page
 
  ". $each." ";}} echo Json_encode ($html); exit;}? >


The demo you provide is still very enlightening. In the combination of my actual programming, there are a lot of problems, mainly:
1. The ajax.php reply is to read a string from the MySQL database that is connected to the contents of each field, which coincides with the simple empty box in your demo, and the result is very good. And I this page to the right, not only have a single option, the other empty boxes between the text (in fact, the empty box content of the description text), but also a lot of formatting code. In order to achieve the results of the previous input form, empty box is empty, but there is actually code inside, such as:




So it's hard to split the content into empty boxes by using the full HTML return form in the demo. So, it's been a good way to try it for a long time today, and the conclusion is to use the JS array to return the content from the MySQL query. But how does the code change?

2. The above question is the main problem, if the above problem is solved, I can make my own judgment, and in a single option to use check= "checked" method to solve.

It took a long time to try and finally summed up the question. Oh, help AH.

It's too late today to write to you tomorrow day .... The evening time to wow.

It's too late today to write to you tomorrow day .... The evening time to wow.

Here, thank you first.

Demo Address http://www.colg.biz/demo/d1.php

Table structure and content



Show page code

 
 
 
 
 
 
 
 
  
 
 
 
Id Col1 Col2 Col3 Col4 Gender
          ManWoman




Ajax receive processing page code
 
  


Returns an array with JS analysis insert specified location No matter what structure you can achieve original aim

Do it with Ajax.

When you click on the left side of the record name, the record name with Ajax to the background to query the corresponding information returned after the Fill in the box

Demo Address http://www.colg.biz/demo/d1.php

Table structure and content



Show page code

 
 
 
 
 
 
 
 
  
 
 
 
Id Col1 Col2 Col3 Col4 Gender
          ManWoman




Ajax receive processing page code
 
  


Returns an array with JS analysis insert specified location No matter what structure you can achieve original aim


Thank you so much.
Yes, is learning "Zong", the details of the experience.

The outside box is missing? So you look closely at the HTML structure only changes need to change the data do not move the other things only the data will not cause the box to disappear unless the length of the height of the problem caused by CSS is not constrained to


2.eq (1) Looking for a second EQ (2) Looking for the third one, are you sure you're right?
In addition, you can write this

var type = Msg.type;
if (type = = 1)
{
$ (". Show_1 > Input[name= ' type ']:eq (1)"). attr ("Checked", "checked");
$ (". Show_1 > Input[name= ' type ']:eq (2)"). Removeattr ("checked");
}
Else
{
$ (". Show_1 > Input[name= ' type ']:eq (2)"). attr ("Checked", "checked");
$ (". Show_1 > Input[name= ' type ']:eq (1)"). Removeattr ("checked");
}

In addition, the type of keywords used to look very gripped ... I hope this place doesn't go wrong.

The outside box is missing? So you look closely at the HTML structure only changes need to change the data do not move the other things only the data will not cause the box to disappear unless the length of the height of the problem caused by CSS is not constrained to


2.eq (1) Looking for a second EQ (2) Looking for the third one, are you sure you're right?
In addition, you can write this

var type = Msg.type;
if (type = = 1)
{
$ (". Show_1 > Input[name= ' type ']:eq (1)"). attr ("Checked", "checked");
$ (". Show_1 > Input[name= ' type ']:eq (2)"). Removeattr ("checked");
}
Else
{
$ (". Show_1 > Input[name= ' type ']:eq (2)"). attr ("Checked", "checked");
$ (". Show_1 > Input[name= ' type ']:eq (1)"). Removeattr ("checked");
}

In addition, the type of keywords used to look very gripped ... I hope this place doesn't go wrong.

Thank you first.
This first option assigns a value of 1, and the second option assigns a value of 2. I ran the statement you gave me, the result is: each time the value is 2 o'clock, two options are empty, the value is 1 o'clock, the second option is selected (but in fact, the second option should be a value of 2).
I think there's something wrong with the details. 1. The following is the code (I changed the variable type to Drivertype):
var drivertype = Msg.type;
if (Drivertype = = 1)
{
$ (". Show_1 > Input[name= ' type ']:eq (1)"). attr ("Checked", "checked");
$ (". Show_1 > Input[name= ' type ']:eq (2)"). Removeattr ("checked");
}
Lse
{
$ (". Show_1 > Input[name= ' type ']:eq (2)"). attr ("Checked", "checked");
$ (". Show_1 > Input[name= ' type ']:eq (1)"). Removeattr ("checked");
}

2. As for the box is missing, the result of operation is:

But in fact, the original state is:

The code for the HTML section is:







Driver Type:





This is a whole section of this code, including the front and back of each box.
I wonder if...Included in Causes the content to be filled in with the Ajax return,...have also been replaced?

You used to be the border of input, and now you've replaced input.

There are two solutions. First, insert the value directly into the value of input

The second is to write it now and then give TD a border to make it look like before

Write to you td.html (XXX) does not have to be rigid so write your TD inside there is a change in content


You used to be the border of input, and now you've replaced input.

There are two solutions. First, insert the value directly into the value of input

The second is to write it now and then give TD a border to make it look like before

Write to you td.html (XXX) does not have to be rigid so write your TD inside there is a change in content

How do you change this value into the value of input?

You say "Write to you td.html (XXX) does not have to be rigid so write your TD inside has the content to change", the meaning is actually not only TD can use, like

That's all you can use, huh?

Also, I see the demo and I followed it with $ (". Show_6"). Text (..), but there is $.post () in Ajax, which seems to be written as $ ("#show_6"). Text (..), these two. Show_6 and #show_ 6 is not a mix, is it?

This question asks now, thanks very much.


You used to be the border of input, and now you've replaced input.

There are two solutions. First, insert the value directly into the value of input

The second is to write it now and then give TD a border to make it look like before

Write to you td.html (XXX) does not have to be rigid so write your TD inside there is a change in content

How do you change this value into the value of input?

You say "Write to you td.html (XXX) does not have to be rigid so write your TD inside has the content to change", the meaning is actually not only TD can use, like

That's all you can use, huh?

Also, I see the demo and I followed it with $ (". Show_6"). Text (..), but there is $.post () in Ajax, which seems to be written as $ ("#show_6"). Text (..), these two. Show_6 and #show_ 6 is not a mix, is it?

This question asks now, thanks very much.

When using $.ajax (), the area you need to fill with class= "..." To mark, while using $.post (), is used with id= "..." To mark. Can these two kinds of marking methods be mixed? or $.ajax () can also be used with $ ("#show_6"). Text (..), but you must use id= "..." at this time. To mark?

You can mix it up with selectors, and it doesn't make any difference to jquery.


such as $ (". Show_tr > Td:eq (1)"). Text (msg.col1);

Since you have input in TD and can't replace input rudely

Can be written as $ (". Show_tr > Td:eq (1) >input"). Val (msg.col1);

You first try the jquery selector is very flexible and can be applied in various

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.