Jump to content

mysqli results split over 2 divs ...


pepelepew1962

Recommended Posts

Hello:

I am having a brain fart on how to get this done and any ideas would greatly be appreciated. I am working on a in-house mailbox project and have my first problem. I am going to try and explain this a simple as possible as putting the words from my head to screen harder than I thought.

I have a page with 1 div called msgs_main. Inside of that div are 2 more, top one called msgs_msgs and the bottom called msgs_content. The msgs_msgs div contains a simple mysqli query displaying the records that correspond to the user. What I want/need is that when the user clicks one of the rows, the contents of the message are displayed in the msgs_content div.

I could provide the code, if it helps, but I am not really looking for answered code, but a process to learn from, like. "First, get a join and have all the records display in the msg_msgs div. Display them all to see that all the data is there. Later in production, remove the un-necessary fields from top div". Then research .... etc

Link to comment
Share on other sites

I see two solutions:

 

1. JavaScript only: Run one query to get all the messages for the user (with the content). Then display the list of messages in the top div.  You should put them in DIVs, or a list (<li>), or some other container. Those containers should have an onclick event which calls a function and passes the ID of the record. Now, in the bottom DIV, you will create the output for the content of ALL the records. But, you will put each in it's own container with an ID that contains the ID of the record and the containers will have a default style of "display:none". The onclick function will take the record ID passed in call, make all the content DIVs display=none and then make the container for the selected record to display=inline

 

2 The other option is to use AJAX (JavaScript + PHP). Just, populate all the records in the top DIV and include an onclick even to pass the record ID. When the onclick function is called it will do a call to a PHP page (passing the record ID). That page will look up the content of the record and return it to the calling JavaScript function. That function will then populate the content into the DIV.

 

Since you are already getting all the records to populate the top DIV, I would go with option 1.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.