-
Posts
5,717 -
Joined
-
Last visited
-
Days Won
6
Everything posted by Adam
-
If you're going to go down the road of parsing templates like that, then you're also going to need to think about how you'll interpret control structures; like if conditions, loops, includes, etc. If you plan on using normal PHP for those, then what's the point in the overhead of parsing templates just to replace variables? You'd may as well just use PHP-based templates in that case.
-
You're just echoing out a static value: public function display($filename) { echo "hello"; } Plus it doesn't make logical sense to try and display() the template, before you've assign()ed your vars..? $template->display(); $template->assign("hello", "test");
-
Then PFMaBiSmAd was right. Use glob to loop through the files: foreach (glob('./aircraft/' . $_GET['reg'] . '*.jpg') as $file) { echo '<li class="active"><img src="' . $file . '" alt="test" /></li>'; } Although I'd remove any slashes within the 'reg' parameter, to prevent the user viewing other directories (although they're limited to .jpg files only) on your file system.
-
I'd leave the function to just validate the format of the string and return true/false, then check the return value within your main 'application' code: if (!validatePostcode($postcode)) { $_SESSION['add_customer_errors']["post_code"] = "Please enter an appropriate Post Code"; } That way you keep any of the application logic out of your functions, leaving them reusable and your code easier to follow..
-
Oh, I copied the loop from a previous post. It's missing the semi-colons between the expressions: <?php while($i=0; $i < 9; $i++) { echo '<li class="active"><img src="./aircraft/' . $_GET['reg'] . $i . '.jpg" alt="test"><br />'; } ?> As PFMaBiSmAd said though, this assumes the values are there. Although I'm not sure if glob is what you're after? You seem to be passing the images via a GET parameter..
-
Personally I'd structure it like this: if (!empty($_POST['selectroom'])) { $room = htmlentities($_POST['selectroom']); $_SESSION['room'] = $room; } elseif (isset($_SESSION['selectroom'])) { $room = $_SESSION['selectroom']; } else { $room = "RoomNameA"; } Perhaps drop the htmlentities call if you escape the value somewhere else.
-
Each time you set $file you were overwriting the previous $file, an array would be best. However a foreach() is definitely the preferred way to loop through it, not a while(). Although I'm wondering if you need two loops? Do you loop through the second time later in the code, but just posted them together on here? If not, then why not just echo out from the first loop..? while($i=0 $i < 9 $i++) { echo '<li class="active"><img src="./aircraft/' . $_GET['reg'] . $i . 'jpg" alt="Flowing Rock" style="width: auto; height: 70px; margin-left: -28.5px; display: block;" class="thumb" /></li>'; } Also if you're asking for tips, using single quotes to echo out HTML is much easier to read and write. Plus would it not be better to place the styles in a CSS class? Edit: Missed ninedoors' comment about using 2 loops before.
-
Expanded Radio Buttons - Using other objects as them.
Adam replied to Jumpy09's topic in Javascript Help
The last code you posted seems to work for me - even deselecting. As for clicking the label, there's nothing in the labels to click? I wouldn't give up and attach the events using (obtrusive) HTML attributes though, you're nearly there! -
Could be a million things. Would be much quicker if (when you have it) you provided the code.
-
Expanded Radio Buttons - Using other objects as them.
Adam replied to Jumpy09's topic in Javascript Help
Oh yeah, my mistake. Try this then: <html> <head> <script type="text/javascript" src="jquery.js"></script> <style type="text/css"> .hovered { background-color: #FFF58F !important; } .selected { background-color: #ADFF6F; } </style> </head> <body> <form method="post" action=""> <div class="radio"> <input type="radio" name="foobar" id="foo" value="foo" /> <label for="foo">Foo</label> </div> <div class="radio"> <input type="radio" name="foobar" id="bar" value="bar" /> <label for="bar">Bar</label> </div> </form> <script type="text/javascript"> $('.radio').hover(function() { $(this).addClass('hovered'); }, function() { $(this).removeClass('hovered'); }).click(function() { $(this).addClass('selected').children('input:radio:first-child').attr('checked', true); $(this).siblings('div.radio').removeClass('selected').children('input:radio:first-child').attr('checked', false); }); </script> </body> </html> -
I had a quick look on Google (guessed you may look) and the first result isn't the best way of doing it. This would be better (and quicker, in most cases): function validatePostcode($str) { $str = strtolower($str); $str = str_replace(' ', '', $str); switch (strlen($str)) { case 5: // A9 9AA return preg_match('/^[a-z][0-9][0-9][a-z]{2}$/', $str); case 6: // A99 9AA // AA9 9AA // A9A 9AA return preg_match('/^[a-z]([0-9]{2}|[a-z][0-9]|[a-z][0-9][a-z])[0-9][a-z]{2}$/', $str); case 7: // AA99 9AA // AA9A 9AA return preg_match('/^[a-z]{2}([0-9]{2}|[a-z][0-9])[0-9][a-z]{2}$/', $str); } return false; }
-
Read here for possible UK postcode formats. As for the PHP, have a bash and see what you can do..
-
How to automatically reload main page after redirected back to it
Adam replied to geekisthenewsexy's topic in Javascript Help
Personally I'd avoid using JS' history.go() method, or any form of JS based redirection for that matter. Can you not do this without needing to use JS? -
Expanded Radio Buttons - Using other objects as them.
Adam replied to Jumpy09's topic in Javascript Help
Try running this and see if it's what you're after.. <html> <head> <script type="text/javascript" src="jquery.js"></script> <style type="text/css"> .hovered { background-color: #FFF58F !important; } .selected { background-color: #ADFF6F; } </style> </head> <body> <form method="post" action=""> <div class="checkbox"> <input type="checkbox" name="foo" id="foo" /> <label for="foo">Foo</label> </div> <div class="checkbox"> <input type="checkbox" name="bar" id="bar" /> <label for="bar">Bar</label> </div> </form> <script type="text/javascript"> $('.checkbox').hover(function() { $(this).addClass('hovered'); }, function() { $(this).removeClass('hovered'); }).click(function() { var input = $(this).children('input:checkbox:first-child'); if (input.attr('checked')) { input.attr('checked', false); $(this).removeClass('selected'); } else { input.attr('checked', true); $(this).addClass('selected'); } }); </script> </body> </html> -
How to select the child of the selected element only in jQuery
Adam replied to Noskiw's topic in Javascript Help
Okay. What do you mean by selected element? If you can explain the problem in a little more detail, should be able to help you. -
How to select the child of the selected element only in jQuery
Adam replied to Noskiw's topic in Javascript Help
Have you read up on .children()? -
If you use Firebug, you can view a tree-menu style list of an object, plus it's children and parents, by adding a 'watch expression'. Assuming you have it installed, open it on the page you wish to debug and select the 'Script' tab. In the left panel you'll see the JavaScript for that page, and within in the left margin of that panel, on the line containing a reference to the object, click in the left margin and a red dot should be appear. Run the code again, either by refreshing or calling the event that triggers the code, and in the right panel you should see the object. It's not the most straight-forward tool to use, but it means you don't have to add debug functions or output to find the problem.
-
Only requests matching the rewrite rule (a basic regex) will be rewritten: RewriteRule ^([a-zA-Z0-9_\.-]+)$ profile.php?username=$1 That means requests containing only the following characters will be treated as usernames "a-z A-Z _ . -" .. Otherwise the normal 404 error will be thrown. You can customize that to match your own needs; add a prefix like "user/", reduce the characters allowed, or add other rewrite conditions. For usernames that do match the pattern but don't exist, you want to throw a 404 header response code to tell the bwoser/search engines that page isn't found: if (/* username not found */) { header("HTTP/1.0 404 Not Found"); }
-
The rewrite conditions below check to make sure the requested URL isn't an existing file name or directory: RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d
-
Sorry but you're wrong. Perhaps you're using double-quotes?
-
Variables within single quotes aren't parsed.
-
I really don't see why anyone would ever want to d that... especially using a looped query.
-
Using an array here would be much appropriate - is there a particular reason why you need to use variables? I'm a little confused by what you're asking though. I've already told you about extract(), that should be all you need..? // assume we have a valid mysql result resource called $query while ($row = mysql_fetch_assoc($query)) { // $row now contains an array indexed by the column names extract($row); // we now have a series of variables named after the indexes (the column names) } If anybody were to alter the table structure (and you either add it to the select SQL or you're using *) that variable would be created too.
-
Do you get an error, or do you just not receive the email?
-
In answer to this by the way, not quoting the index will make PHP think you're referencing a constant. If it's not found it will assume the string value, but if you have notice level errors enabled you'll get a notice like: