Solved

Call php in file

Posted on 2013-11-29
22
430 Views
Last Modified: 2013-11-30
Let's say I have a mostly html file with some php.

I have a form (all select values) and i want to call php when one of those is selected without going to an external file.

How do I do this? Function?
0
Comment
Question by:burnedfaceless
  • 14
  • 4
  • 4
22 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 39686135
PHP runs at the server - it doesn't exist in the browser.
If you want to run some php (for whatever reason) when a dropdown is changed then you either need to submit the page back to the server or use ajax to call a page on the server.
0
 

Author Comment

by:burnedfaceless
ID: 39686171
I'm having a problem where the following page

conutils.com/dist/rates

If you visit from a desktop it works. It's not supposed to do anything when you visit it from mobile, but it messes up the menu - if you could visit from mobile and look.

I've thought about messing around with the css but I figured the easiest thing to do would be echo html similar to our jquery example, without having to change the url of the user.

What would you recommend?
0
 

Author Comment

by:burnedfaceless
ID: 39686177
Even if it's not proper client server distribution my boss wants this part mobile so I need to get it done.
0
 
LVL 58

Expert Comment

by:Gary
ID: 39686182
Confused.
You have two dropdowns marked desktop and mobile (don't see the point)

It's not supposed to do anything when you visit it from mobile
What is supposed to happen on mobile then?
0
 
LVL 58

Expert Comment

by:Gary
ID: 39686183
Are we getting confused between the two questions?
0
 

Author Comment

by:burnedfaceless
ID: 39686186
It's mainly because the display will be different when I am finished.

It's not connected to jquery (consolidated.js) because the rendering error occurred when I displayed a water system. I isolated it to the select (form) itself by removing everything.
0
 

Author Comment

by:burnedfaceless
ID: 39686188
Basically I kept it simple and I know that the form is causing the css menu to screw up, so I have to either fix that in css, or find a way with php or ajax that will display systems.

I hope that I explained my problem.
0
 
LVL 58

Expert Comment

by:Gary
ID: 39686192
The question isn't about menus ::still confused::
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 39686375
There may be a lot of background information you need to understand before you can craft this question in a way we can help with an answer.

HTTP Client / Server Protocols
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/A_11271-Understanding-Client-Server-Protocols-and-Web-Applications.html

The Basics of PHP
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_11769-And-by-the-way-I-am-new-to-PHP.html

Using jQuery (or any AJAX action, for that matter)
http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Jquery/A_10712-The-Hello-World-Exercise-with-jQuery-and-PHP.html

Probably this last article is what you want to implement, but it will be easier for you if you understand the content of the first two articles.

Best of luck with the project, ~Ray
0
 

Author Comment

by:burnedfaceless
ID: 39686377
Thanks Ray. I'll read tomorrow.
0
 

Author Comment

by:burnedfaceless
ID: 39686379
Ray I wanted to make sure you were familiar with this thread before I start reading stuff that doesn't relate....

http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/CSS/Q_28306814.html#a39686204
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Author Comment

by:burnedfaceless
ID: 39686385
I'm assuming that you view this algorithm as the only possible solution...have php echo every detail. Unless you respond.
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 39686911
I read the other question and posted a comment there.  I don't think the articles listed here are "stuff that doesn't relate."  They are like arithmetic when the question is about finance -- fundamental things you must understand in order to communicate about the larger issues.  Take some time to read and understand, and experiment with the code examples.  You will have a much better understanding of what you're trying to do!  Then come back here and help me understand this:
... have php echo every detail
Please clarify?  I think the answer is probably, "yes," but I would like to have the dialog in more specific terms if possible.  Thanks, ~Ray
0
 

Author Comment

by:burnedfaceless
ID: 39687107
Well obviously that's the idea that someone who was on too much amphetamine would have (I'm not on that it's a joke).

My boss wants it done and having a php page that echoes the page with the menu would not distort the menu it just would take a long time.
0
 

Author Comment

by:burnedfaceless
ID: 39687108
This page works fine desktop.

It's the mobile version, which isn't tied into it anyways.

I will read what you put. But I know the form is causing the menu expansion - at the end of the day I have to get this shit done.
0
 

Author Comment

by:burnedfaceless
ID: 39687226
Actually don't answer that. Let me see if I can figure it out.
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 39687239
We understand that it's your responsibility, and we're trying to help, but it's also obvious that you're in over your head.  Example: Go to http://conutils.com/dist/rates/ and use view source.  Look at line 10 and 11.  Then look at line 211 and 212.  This just doesn't make any sense.  You may want one or the other, but not both of these tags.  The latest jQuery minified is available here:
http://code.jquery.com/jquery-latest.min.js

Next, look at http://conutils.com/dist/js/consolidated.js where it seems that the entire response set has been hardcoded into a JavaScript library in the form of lengthy HTML strings.  A better design would be an AJAX call to a PHP script that returned the HTML strings.  The PHP script could rely on a data base, and the table maintenance for the data base could be performed through simple HTML forms.  You would use this sort of design because the people who do rate setting are unlikely to be comfortable editing a JavaScript file.

Go back to the view source again and look at the select controls for "WaterSystem" and "WaterSystem2."  The option tags are exactly the same, strongly suggesting that this code fails the "don't repeat yourself" test.  This should be one select control, because there is no value added in the duplicated options.

It's this sort of thing that leads me to believe that the best way we can help you is to look back to the fundamentals and try to build up the application one piece at a time.  For example, you might want to have PHP generate all of the HTML document.  PHP can look at HTTP_USER_AGENT and make some intelligent determination about whether the browser is mobile or desktop.  PHP can use this information to tailor the generation of CSS and JavaScript, as well as the markup.
0
 

Author Comment

by:burnedfaceless
ID: 39687321
1. One thing at a time. Do we want the latest jquery? Would there be compatibility issues.

I'm a n00b when it comes to interaction between the web elements, but as someone said almost every programming concept was invented in the '70s. So I understand the thinking.

2. Would you provide examples on php generation of more of the page, either in Build Your Own Database Driven Web Site Using Php & MySQL?

Or on this page.

The jquery works fine on the desktop and I don't want to change what isn't broken but I'm interested in learning about the AJAX or php writing more of the page. I may make some major changes.

3. FWIW I am considering a minor or major change to computer science. Would a minor give me enough of a background to code a database?

One thing I learned in music is the first two classes (music theory) were the pertinent ones. The final two of the sequence just messed with your head.
0
 

Author Comment

by:burnedfaceless
ID: 39687324
And Ray I've debugged it, the issue is any form submission.

What you are suggesting won't fix the problem.

Trust me I've programmed in an academic setting with c++, pascal, and basic for robotics. I know how to isolate the problem.

edit: i'm interested in learning more about writing with php because I want to learn that.

Maybe it would fix the problem if it would rewrite the menu.

Let's go to some examples Ray this will be fun:
0
 

Author Comment

by:burnedfaceless
ID: 39687436
Look if nobody has any ideas I'll just echo the damn thing.
0
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 39687494
Do we want the latest jquery?
Yes.
Build Your Own Database Driven Web Site Using Php & MySQL?
There is an update to this book.  Ignore the hokey title; it's still a good learning resource.
http://www.sitepoint.com/store/php-mysql-novice-to-ninja/
Would a minor [in computer science] give me enough of a background to code a database?
Yes, if the only person who is using the database is you.  Otherwise you're competing against computer science majors from MIT, CalTech, Carnegie-Mellon, RIT, Virginia Tech, etc., and you will probably not earn the right to code a database until you have several years of experience.  

Example of how to use PHP to generate a web page:

<?php // RAY_html5.php
error_reporting(E_ALL);

// CREATE VARIABLES FOR OUR HTML
$dat = date('r');
$xyz = "Hello World.  It is $dat";

// CREATE OUR WEB PAGE IN HTML5 FORMAT
$htm = <<<HTML5
<!DOCTYPE html>
<html dir="ltr" lang="en-US">
<head>
<meta charset="utf-8" />
<meta name="robots" content="noindex, nofollow" />
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<title>HTML5 Page in UTF-8 Encoding</title>
</head>
<body>
<p>$xyz</p>
</body>
</html>
HTML5;

// RENDER THE WEB PAGE
echo $htm;

Open in new window

I'll sign off on this question now.  It seems to have morphed into a fishing expedition looking for interesting ideas in computer programming.  Nothing wrong with that, but it belongs in the classroom rather than in a Q&A forum like EE.

Best of luck with your project, ~Ray
0
 

Author Closing Comment

by:burnedfaceless
ID: 39687517
Thanks Ray I'm changing my minor.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now