claro Posted January 23, 2013 Share Posted January 23, 2013 (edited) 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. Edited January 23, 2013 by claro Quote Link to comment https://forums.phpfreaks.com/topic/273515-dynamic-content/ Share on other sites More sharing options...
requinix Posted January 23, 2013 Share Posted January 23, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/273515-dynamic-content/#findComment-1407635 Share on other sites More sharing options...
claro Posted January 23, 2013 Author Share Posted January 23, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/273515-dynamic-content/#findComment-1407640 Share on other sites More sharing options...
requinix Posted January 23, 2013 Share Posted January 23, 2013 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). Quote Link to comment https://forums.phpfreaks.com/topic/273515-dynamic-content/#findComment-1407645 Share on other sites More sharing options...
claro Posted January 23, 2013 Author Share Posted January 23, 2013 Thank you very much for that. I'm still confuse how to make this work. Selecting options from the left the action in the right. Quote Link to comment https://forums.phpfreaks.com/topic/273515-dynamic-content/#findComment-1407647 Share on other sites More sharing options...
requinix Posted January 23, 2013 Share Posted January 23, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/273515-dynamic-content/#findComment-1407769 Share on other sites More sharing options...
claro Posted January 24, 2013 Author Share Posted January 24, 2013 Ok I have a work around in my mind now. How about ajax call in getting id value in href? any idea? <li><a href="?page=page&id=<?php echo $val;?> " id="link1">Menu item</a></li> Quote Link to comment https://forums.phpfreaks.com/topic/273515-dynamic-content/#findComment-1407864 Share on other sites More sharing options...
requinix Posted January 24, 2013 Share Posted January 24, 2013 But you said you didn't want to do AJAX... I don't know what your question is. What about the ID needs AJAX? Quote Link to comment https://forums.phpfreaks.com/topic/273515-dynamic-content/#findComment-1407866 Share on other sites More sharing options...
claro Posted January 24, 2013 Author Share Posted January 24, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/273515-dynamic-content/#findComment-1407869 Share on other sites More sharing options...
claro Posted January 24, 2013 Author Share Posted January 24, 2013 (edited) 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 January 24, 2013 by claro Quote Link to comment https://forums.phpfreaks.com/topic/273515-dynamic-content/#findComment-1407871 Share on other sites More sharing options...
Christian F. Posted January 24, 2013 Share Posted January 24, 2013 (edited) 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 January 24, 2013 by Christian F. Quote Link to comment https://forums.phpfreaks.com/topic/273515-dynamic-content/#findComment-1407920 Share on other sites More sharing options...
claro Posted January 25, 2013 Author Share Posted January 25, 2013 What will this code do? I'm lost . Thank you Quote Link to comment https://forums.phpfreaks.com/topic/273515-dynamic-content/#findComment-1408089 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.