Jump to content

Dynamic Content


claro

Recommended Posts

Greetings!I think I'm on the most bloody part of my project, I have no idea how to work it out.

I'm not good in explaining that's why I attached my illustration to show what my problem really is.

 

I'm looking for frame-like effects in php for dynamic content. Like when I hit option from the left

div ,action will display in right div. I'm in a computer laboratory inventory. Thank you in advance.

 

the illustration has two blocks, my problem is in the right. Really need your advice.

post-123592-0-22094000-1358911334_thumb.jpg

Edited by claro
Link to comment
Share on other sites

Unless you want to drive it entirely with Javascript, AJAX is your best option. Your tasks are:

1. Make a page (doesn't have to be PHP) that outputs the right HTML. Put some placeholder content in the right DIV so you can see what it looks like.

2. Remove that placeholder stuff.

3. Make a PHP script, or reuse the one from before, that outputs only the HTML needed to replicate that placeholder HTML. Doesn't need the and

and all that, just the DIV content.

4. Learn how to use AJAX, maybe get yourself a Javascript framework along the way. Use that to call your PHP script: pass in the value from the SELECT and fill that DIV with whatever HTML it returns.

5. Other stuff, because I'm pretty sure you want to do more than just make it look that way.

Link to comment
Share on other sites

Not really a fan of ajax, since it is javascript. I don't want my project be dependent by it in terms of functionality. But, if it's the only way then I should convince myself to use it. Now I'm looking for simple script to work around. Thanks for the response. Enlighten me more about my project.

Link to comment
Share on other sites

If you don't want AJAX (I applaud your decision to not rely on it) then you'll have to settle for a page refresh, in which case it's basically just a normal PHP page with a form that submits to itself. That could very well be fine for your purposes - it just wasn't what you initially described.

Well... there's also vanilla Javascript, but it sounds like your objection is less about AJAX and more about Javascript.

 

What I said about mocking up the page still stands except now it's a lot easier to make it work. For the textboxes on the right you do a loop according to whatever number came from the form, but only if the form was submitted and if the number is a valid choice (a positive number within reason, that kind of thing).

Link to comment
Share on other sites

It's a normal form submission. You might want to brush up on how to do that before continuing.

 

The form is on the left and it has the text box and the submit button. It posts back to itself. Besides showing the form the script will also check if the form was submitted: if so then it puts HTML on the right, otherwise it does not.

Link to comment
Share on other sites

I'm in dead end now I think, I must convince myself just to meet my needs. As long as I can avoid AJAX and js, I will. But I think this time is different now.

 

Yes, I must get the value of my href attributes via ajax. I tried pure js but my page refresh after clicking the link, and my php values are affected.

Link to comment
Share on other sites

Ok, hope this will make my self clear.

 

Optimized-1.bmp

 

1. On this part the user will select the name of laboratory as well as the number of pc that will mount.

 

Optimized-2.bmp

 

2. On this part, The laboratory name is displayed as well as the total number of pc. Also the generated pc list on the right. When the user click any on the list, the computer parts will appear on the right ( which is a form to be fill in), but as of now I start to get the list ID.

 

Optimized-3.bmp

 

3. This part is my problem. The name of laboratory, and number of pc is gone. But I got the list Id.

 

I am thinking that ajax or jquery can help me out on this problem.

Any advice?

Optimized-1.bmp

Optimized-2.bmp

Optimized-3.bmp

Edited by claro
Link to comment
Share on other sites

You need to add the choice from step 1 into the links in step 2, and the choices from both step 2 and step 1 into the links on step 3 (if any).

This means that your step 1 links will look like this, assuming you're echoing them out in a (foreach) loop:

<li><a href="?lab=<?php echo $id;?>"><?php echo $name; ?></a></li>

 

Then, in step 2, you need to do something like this:

<?php
$lab_id = intval ($_GET['lab']);

// TODO: Check that the lab exists, and fetch the computers associated with it.
$data = get_computers ($lab_id);

// Generate the computer links.
$links = '<ul id="menu">'."\n";
$links_template = "\t".'<li><a href="?lab='.$lab_id.'&pc=%1$d">%2$s</a></li>'."\n";
foreach ($data as $id => $name) {
   $links .= sprintf ($links_template, $id, htmlspecialchars ($name));
}
$links .= "</ul>\n";
?>

 

Then just echo out $links where you want them to show. The same process should be used to generate the links in step 1.

Edited by Christian F.
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.