KevinM1
Moderators-
Posts
5,222 -
Joined
-
Last visited
-
Days Won
26
Everything posted by KevinM1
-
Remember, PHP scripts are executed from the top down. Having: $form_message = true; if ($form_message) { ?> <!-- html --> <?php } Will simply spit out the HTML where it is. Why does it work for $form? It works because you set $form as false before you check for it and try to output the form. Again, top-down execution.
-
The HTML will always show because you're always setting $form_message as true. What you need to do is check if the form has been submitted first, then set $form_message accordingly.
-
jQuery is worth using simply for its AJAX API.
-
First, never, ever, ever use 'global'. Parameters to functions should be passed in via the functions' argument list. That's why it's there. Functions have a public interface - their names and what parameters should be passed in. 'Global' adds an implicit requirement which is hidden to the system at large, since the requirement is not a part of the function's interface, and ties the function it's used in to the larger context of the system, which negates one of the points of using functions to begin with - modularity. I don't know where beginners get the idea to pass parameters in via 'global', but it's the absolute wrong way to do it. Find a better tutorial site/book/instructor. Second, with all that said, adding another if-conditional is easy: function metadescription($db) { //checks if it's our category page if (isset($_GET['cat_id'])) { $cat_id = mysql_real_escape_string($_GET['cat_id']); $query = "SELECT * FROM categories WHERE cat_id = '$cat_id'"; $result = $db->query($query); $result = $db->fetchrow($result); $metadescription .= $result['cat_meta_description']; if (empty($metadescription)) { // run additional query and do stuff } } return htmlentities($metadescription); }
-
I think you have to use count. feed[0][count(feed[0])-1] JavaScript, not PHP.
-
You don't need to use a loop. Just access the element at feed[0][feed[0].length-1], if your feed[0] is actually an array itself.
-
What is the second one then as it doesn't return any syntax errors when i run it... It's not returning any errors because you're using bitwise OR rather than logical OR. | is for bitwise operations, || is for logical operations. So, the following: if($fileExt != ('jpeg'|'jpg'|'png'|'gif'|'pjpeg')) Is saying "If $fileExt does not equal ('jpeg bitwise OR'd with 'jpg', bitwise OR'd with 'png', bitwise OR'd with 'gif', bitwise OR'd with 'pjpeg'), do the following...." For what bitwise OR actually is, see: http://en.wikipedia.org/wiki/Bitwise_operation#OR Suffice it to say, your particular OR's do a particular thing, which isn't what you want them to do.
-
We're not mind readers. Code and context is required.
-
Right, except the second one is not valid PHP and will not work.
-
Because it's not? You have two options - use double quotes and have the variable value automatically substituted for you, like: $s = "<a href='../u/{$r['feedusername']}'>"; Or use single quotes and concatenation: $s = '<a href="../u/' . $r['feedusername'] . '">';
-
That's not Flash, it's JavaScript. @web-developer - you need to tighten up the language you use on your pages, specifically with verb usage. Example: On your 'About Us' page, you have: 'is having', grammatically, makes no sense. What you need is: 'Has' denotes ownership, in this case. There are many other examples of that kind of thing sprinkled throughout the site. I realize that English is likely not your first language, but since the site is written in English, and is aimed at an English-speaking audience, you'll need to fix the grammatical oddities.
-
That's one way to get that variable, yes. Also, once again, your data members should either be private or protected, depending on whether or not you anticipate making child classes. Making them public breaks encapsulation. In other words, do this: class testClass { private $config; // rest of class }
-
The easiest way to do it is to fill a template with the data retrieved by the server. That's how the pros do it. Stores like Amazon don't have individual pages for each item they sell. Rather, they have a generic template which they fill with a particular item's info. shopping.php?item=0001 should essentially be something along the lines of (most general psuedo-code possible): if isset($_GET['item'])) { // query database for item based on the GET value passed in. // include item template, which will anticipate and display that info } That said, you'd probably be better off using a MVC framework for this, which would help automate and organize the process for you while making everything more extensible in the long run.
-
It's telling you that you haven't created an $array variable at that point. You can't use functions on something that doesn't exist.
-
Unless you plan on serving your pages as XML, there's no real point in writing XHTML anyway. XHTML is essentially dead. It never went anywhere, and I doubt there will ever be a new version of it. Stick with HTML 4.01, with some HTML 5 enhancements. It's far easier regarding doctype.
-
Then you read it incorrectly.
-
Re-read what it says. Only the name attribute for those particular elements has been deprecated. Note that input is not on the list.
-
That doesn't tell us much. Where is your JavaScript being invoked in relation to your HTML?
-
My parser class will not parse links properly.
KevinM1 replied to creata.physics's topic in PHP Coding Help
I don't know if this will help, or if it's something you already know, but your $inside variable must not be set in those cases. -
Like the sticky says, you can't have any output sent to the browser before attempting to send a header. Your form is output. You need to redesign your page. As a hint, well-formed PHP pages do all of their processing first, then show output.
-
My parser class will not parse links properly.
KevinM1 replied to creata.physics's topic in PHP Coding Help
Hmm... nothing is jumping out at me. You may want to double check your regex in do_clickable, since that seems to be the method that actually creates a clickable link. You can test regex here. -
That's because you have spelling errors. <inpuy type="hidden" id="cat" value="emf-meters" /> <orm action="" method="GET">
-
Please put all code in either tags or tags. I took the liberty of doing it for you above.
-
My parser class will not parse links properly.
KevinM1 replied to creata.physics's topic in PHP Coding Help
Have you manually tested one of your stored strings with just html_entity_decode to see if it's all being decoded properly? -
My parser class will not parse links properly.
KevinM1 replied to creata.physics's topic in PHP Coding Help
Which method is responsible for what you're trying to do: do_clickable or parse_message? Also, what's with all the globals? Globals and OOP should not be used together. Globals really shouldn't be used at all, regardless. Look into OO design patterns and concepts.