-
Posts
3,145 -
Joined
-
Last visited
-
Days Won
37
Everything posted by cyberRobot
-
turning nested loops into a shorter algorithm
cyberRobot replied to help_me_with_php's topic in PHP Coding Help
It may be helpful to see some samples. Could you show an example of what the three lines of text might look like and what the resulting $strOut would be? -
If you're looking to retrieve the article IDs as the visitor is looking around the website, you could consider using a PHP session: http://www.php.net/manual/en/intro.session.php If you're looking to retrieve those article IDs after the visitor leaves the website and comes back a couple days later, for example, you could consider cookies: http://php.net/manual/en/features.cookies.php
-
You could utilize that counter variable ($i): <?php echo "<aside id='techSlide$i' class='ic_container'> //... ?>
-
How to select database from drop down selection
cyberRobot replied to m2244's topic in PHP Coding Help
Are you looking to keep this on the client side (JavaScript/AJAX)? If not, you could build a simple drop down menu in HTML and process the selection with PHP. The following tutorial may help: http://www.html-form-guide.com/php-form/php-form-select.html -
One option: http://disqus.com/
-
while click on checkboxs values should add using javascript
cyberRobot replied to ksumanth's topic in Javascript Help
Sorry for the double post. -
while click on checkboxs values should add using javascript
cyberRobot replied to ksumanth's topic in Javascript Help
You could start here: http://forums.phpfreaks.com/topic/170591-solved-checkbox-populating-a-text-area/#entry899820 -
To populate the anchor tag with a PHP variable, the variable needs to be enclosed in PHP tags: <td><a href="#" onmouseover="newPopup('<?php print $row['LocationPix']; ?>');"><img src='http://www.menuhead.net/Images/Buttons/PShotClear.png' /></a></td> Note that I moved the pop-up code to the "onmouseover" attribute.
- 5 replies
-
- php
- javascript
-
(and 1 more)
Tagged with:
-
You could try something like this: <script type="text/javascript"> window.onload = function() { document.getElementById('a1').submit(); } </script>
-
Multidimensional Arrays & foreach....loop?
cyberRobot replied to chris57828's topic in PHP Coding Help
You could try usort: http://php.net/manua...ction.usort.php -
It's a little difficult to tell what's going on without seeing the entire script (including the user-defined functions). Note that I don't have the time to do that. What I would suggest is to review the various functions associated with updating the database entry. Once you have a good sense of how it's updating the database, look for a place to use mysql_real_escape_string(). You'll also want to figure out what's going on with the str_replace() portions of the code. It looks like the previous person was trying to manually fix things. Side note: you may already be aware of this, but the mysql_ functions have been depreciated. At some point, you'll need to look into an alternative for the database connection. http://php.net/manual/en/function.mysql-real-escape-string.php
-
Have you looked through the user-defined functions? The prepararCadena() function, for example, looks like a good place to start.
-
I ran a quick search for $submiturl on your code and it looks like the ID was never added to the URL. <?php $submiturl = "./documents_add.php?id="; ?> Did you try adding the GET variable? <?php $submiturl = "./documents_add.php?id=" . $_GET['id']; ?>
-
Have you considered using array_rand()? http://php.net/manua....array-rand.php <?php $password = ''; $alphanum = array('a','b','c','d','e','f','g','h','i','j','k','m','n','o', 'p','q','r','s','t','u','v','x','y','z','A','B','C','D','E', 'F','G','H','I','J','K','M','N','P','Q','R','S','T','U', 'V','W','X','Y','Z','2','3','4','5','6','7','8','9'); $rand_keys = array_rand($alphanum, 6); foreach($rand_keys as $currKey) { $password .= $alphanum[$currKey]; } echo $password; ?>
-
Are you getting any errors? If so, what are they? Have you tried turning on all errors? <?php error_reporting(E_ALL); ini_set('display_errors', 1); ?> What does your current code look like? Answering those questions may help us get to the bottom of the problem.
-
Have you tried turning on all errors for PHP? <?php error_reporting(E_ALL); ini_set('display_errors', 1); ?> If $_POST['foo'] isn't set a notice will be shown about foo being undefined. To avoid that, the code could be modified to something like: <?php if(isset($_POST['foo'])) { $var = $_POST['foo']; //Do something } ?> Also, have you considered using $_POST['foo'] as the variable instead of $var?
-
In addition to moving the header redirects to the top of the script, the if statements are being overloaded. For example, the following only tests if $_GET["GET_VALUE_REGION"] is set. It ignores the last part. <?php if(isset($_GET["GET_VALUE_REGION"])== "SL") ?> The code could be rewritten as <?php if(isset($_GET["GET_VALUE_REGION"]) && $_GET["GET_VALUE_REGION"] == "SL") ?> ...but you've already tested the variable in the first if. The code could be streamlined to <?php if(isset($_GET["GET_VALUE_REGION"])) { if($_GET["GET_VALUE_REGION"]=="NCR") { header("Location: aocs_ncr.php"); exit(); } if($_GET["GET_VALUE_REGION"]=="NL") { header("Location: aocs_nl-pg.php"); exit(); } if($_GET["GET_VALUE_REGION"]=="SL") { header("Location: aocs_nl-pg.php"); exit(); } if($_GET["GET_VALUE_REGION"]=="VI") { header("Location: aocs_nl-pg.php"); exit(); } if($_GET["GET_VALUE_REGION"]=="NM") { header("Location: aocs_nl-pg.php"); exit(); } if($_GET["GET_VALUE_REGION"]=="SM") { header("Location: aocs_nl-pg.php"); exit(); } else { echo "error"; } } ?>
-
Now that I think about the function a little more, have you considered using range (http://php.net/manua...ction.range.php)? You could do something like <?php public function alphaCount() { return implode('', range('a', 'z')); } ?> If the string is always "abcdefghijklmnopqrstuvwxyz", you could just return the string. <?php public function alphaCount() { return 'abcdefghijklmnopqrstuvwxyz'; } ?>
-
That depends; the code looks to be expecting a string. <?php $row_class = " 'char-".$row. "-".$target." ' "; ?> The function could be modified to something like <?php public function alphaCount() { $output = ''; for ($i=65; $i<=90; $i++) { $output .= chr($i); } return strtolower($output); } ?> Note that I moved the strtolower() function to the return statement so that it's only executed once versus 24 times.
-
$var won't be set if the POST variable isn't set. In other words, if someone goes straight to the form processing page without even looking at the form, the POST variables won't be set.
-
The following line suggests that you're expecting alphaCount() to return the results: <?php $target = $this->alphaCount(); ?> The problem is that the function echos the results to the screen instead of returning them. <?php public function alphaCount(){ for ($i=65; $i<=90; $i++) { echo strtolower(chr($i)); } } ?> You might want to review the manual for returning values. http://www.php.net/m...ning-values.php
-
Only display when there is something there!
cyberRobot replied to latempest's topic in PHP Coding Help
For what it's worth, the first part of the if isn't necessary. <?php foreach($prop->epcs as $epc) { if(!empty($epc->epc)) { $html = $html . sprintf('<p><a href="%s">View EPC</a></p>',(string)$epc->epc); } } ?> -
Too be honest, I don't really work with BBCode beyond using it in message boards like this one. However, maybe the BBCode functions in PHP will help: http://php.net/manual/en/book.bbcode.php
-
The ID could be entered into the [vid] tag...similar to the BBCode for links (http://www.bbcode.org/examples/?id=9). [vid=KcuJAe3TrQw][/vid] The ID could be pulled from the tag and used for the string replace function. As for your other question, shouldn't the open center tag ( ) be replaced with an open HTML tag? The close tag would be replaced with the corresponding HTML close tag. For example <?php $r = "[center]Center this[/center] "; $r = str_replace(" [center]","<div align='center'>",$r); $r = str_replace("[/center] ","</div>",$r); print $r; ?>
-
The problem is caused by how you're concatenating multiple lines of code (see comment in the code below). <?php echo ' </td>' . "\n" . ' <td class="dataTableContent" align="right" valign="top">' . $currencies->format(tep_add_tax($order->products[$i]['final_price'], $order->products[$i]['tax']), true, $order->info['currency'], $order->info['currency_value']) . '</td>' . "\n" . //<-- the concatenation character here causes $num to be included in the echo $num = $order->products[$i]["qty"]; This type of problem is easier to avoid if you the usage of the concatenation character across multiple lines of code. My preference would be to do something like the following: <?php echo '</td>' . "\n"; echo '<td class="dataTableContent" align="right" valign="top">' . $currencies->format(tep_add_tax($order->products[$i]['final_price'], $order->products[$i]['tax']), true, $order->info['currency'], $order->info['currency_value']) . '</td>' . "\n"; $num = $order->products[$i]["qty"]; ?>