-
Posts
3,145 -
Joined
-
Last visited
-
Days Won
37
Everything posted by cyberRobot
-
Undefined index error where it should not be
cyberRobot replied to Codin2012's topic in PHP Coding Help
Have you tried outputting $request to see what it contains? public function __construct($request){ print '<pre>' . print_r($request, true) . '</pre>'; //... -
Checking the value of a dropdowns in sql php
cyberRobot replied to sarojthapa60's topic in PHP Coding Help
To set the color based on the GET variable, you could run a switch statement after $capacity is set. if (isset($_GET['id'])) { $id = $_GET['id']; $stmt = $conn->prepare("SELECT * FROM MATRIX WHERE OBJECTID=:id"); $stmt->execute(array(':id' => $id)); $row = $stmt->fetch(PDO::FETCH_ASSOC); $object_id = $row['OBJECTID']; $capacity = $row['Capacity']; $ownership = $row['Ownership']; } //DETERMINE DROPDOWN COLUMN COLOR $bgColor = 'grey'; //whatever you want to use for the default color switch($capacity) { case 'green': $bgColor='green'; break; case 'amber': $bgColor='yellow'; break; //etc... } ?> Then you can use the new $bgColor variable in your HTML code. <td style="background-color:<?=$bgColor;?>"><label> <select name="txt_capacity" class="textfields" id="capacity"> <option id="0">Select One</option> <?php require_once('include/database.php'); $stmt = $conn->prepare("SELECT * FROM MATRIX_DROPDOWNS"); //... -
Help with getting sub-category jquery drop-down menu to populate
cyberRobot replied to Chrisj's topic in Javascript Help
Do you have any other JavaScript on the page? If so, does that code stop working also when the jQuery code is present? When a browser comes across a JavaScript error, the rest of the JavaScript code tends to stop working also. Have you looked in your browser's Console to see if it's throwing any JavaScript errors? -
Just be aware that the for attribute in the <label> tag needs to match the id attribute in the <input> tag. Otherwise, the <label> tag won't do anything. Or, if you want, the <label> tag can be wrapped around the <input> tag. Then the for and id attributes are not needed. More information can be found here: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/label
-
Checking the value of a dropdowns in sql php
cyberRobot replied to sarojthapa60's topic in PHP Coding Help
I just re-read Reply #5. Are you looking to limit the number of options displayed in the dropdown based on the color selected in index.php? Or are you just trying to change the background color of the dropdown? -
Checking the value of a dropdowns in sql php
cyberRobot replied to sarojthapa60's topic in PHP Coding Help
Let's deal with the GET variable from index.php first. You are utilizing the variable here: $object_id=''; $capacity = ''; $ownership = ''; if (isset($_GET['id'])) { $id = $_GET['id']; $stmt = $conn->prepare("SELECT * FROM MATRIX WHERE OBJECTID=:id"); $stmt->execute(array(':id' => $id)); $row = $stmt->fetch(PDO::FETCH_ASSOC); $object_id = $row['OBJECTID']; $capacity = $row['Capacity']; $ownership = $row['Ownership']; } And it sounds like $capacity is the variable that indicates which color was selected, correct? If so, are you able to incorporate $capacity into the following query? $stmt = $conn->prepare("SELECT * FROM MATRIX_DROPDOWNS"); Does $capacity match the values stored in your "colors" column in the MATRIX_DROPDOWNS table? -
If you haven't already, you could try Reply #3.
-
Instead of using the placeholder attribute, have you tried putting the instructions outside of the <input> tag? Maybe something like this: $attr_input = "<input type='text' id='attribute_$tracker_alert_attribute_id' name='attribute_$tracker_alert_attribute_id' value='$value' $trigger_on_change_html> $entry_instructions";
-
You could use explode() again. <?php function func($text) { $array = explode(' ', $text); foreach($array as $currArg){ $currArg = explode('=', $currArg); print '<pre>' . print_r($currArg, true) . '</pre>'; } } func("arg1=Test1 arg2=test1 arg3=test3"); ?>
-
Checking the value of a dropdowns in sql php
cyberRobot replied to sarojthapa60's topic in PHP Coding Help
I'm not sure what you are asking. Are you looking to incorporate a dropdown into the code above? Is there a dropdown somewhere else on your website that connects to the above code? -
Basically, you could do something like this //Explode $str to an array, each line separated by line breaks \n $arr = explode("\n", $str); $values_withCommas = array(); //If row contains "," add it to an array and print it foreach ($arr as $currLine) { if (strpos($currLine, ',') !== false) { $values_withCommas[] = $currLine; } } //Display result echo implode('<br>', $values_withCommas);
-
To loop through the array, you could use a foreach loop: http://php.net/manual/en/control-structures.foreach.php That way you wouldn't need to worry about a counter. But if you need the counter, for whatever reason, you could use the count() function. http://php.net/manual/en/function.count.php To determine if a line contains a comma, you could avoid regular expressions by using strpos() instead. http://php.net/manual/en/function.strpos.php Note that you'll want to read the warning under the Return Values section.
-
Do you know if the value variables (eg. $value1) contain arrays? You could check using code like this: echo '<pre>' . print_r($value1, true) . '</pre>'; Also note that the following line is missing dollar signs before the value variables: $array = array(value1, value2); And with the following line, do you expect a comma-separated list of both $value1 and $value2? echo $comma_separated = implode(",", $array); In other words, do you expect the following output: asasas,sdsddd,asasas,sdsdsd If so, you could use array_merge() to combine the arrays. More information can be found here: http://php.net/manual/en/function.array-merge.php Note that the following line just creates an array of arrays: $array = array_merge($value1, $value2);
-
Did you post your code or the thing you found on the internet? It will be easier to help if we see the problem code.
-
Retrieve multiple data and display to a single row
cyberRobot replied to davinci29's topic in PHP Coding Help
You could assign all the data, in the while loop, to a multidimensional associative array. And then loop through the multidimensional associative array to generate the HTML table. If done correctly, you can use the count() function to determine how many rows to span the "OnGoing" value, for example, across. More information about multidimensional arrays and multidimensional associative arrays can be found here: http://webcheatsheet.com/php/multidimensional_arrays.php On a related note, you could use the nl2br() function instead of all those calls to str_replace(). -
Note: the original post was made in April 2012.
-
Have you tried something like this $xmlstr = '<property>'; foreach ($files as $file) { $xmlstr .= '<prop_detail>'; combineXML($file); $xmlstr .= '</prop_detail>'; } $xmlstr .= '</property>';
-
For what it's worth, you are assigning a string to $message on the following line: $message = " Since your string starts with a double quote ("), PHP will look for the next double quote to determine where the end of the string is. So basically, PHP thinks this is the string to assign to $message: " <!DOCTYPE html " ...and it's not going to know what to do with the rest, hence the error. To prevent PHP from cutting the string off early, you need to use care with double quotes that appear within the [double-quoted] string. You could replace them with single quotes ('), where possible. Or you can escape the double quotes (\"). Or you could even consider using the heredoc or nowdoc syntax. More information about all of these tactics can be found here: http://php.net/manual/en/language.types.string.php
-
For what it's worth, here's a quote from the forum rules:
-
Is your form and the final destination (website.com/abc.php) under the same domain name? If so, is there a reason you don't want to use a header() redirect?
-
Instead of passing the data directly to "website.com/abc.php", you can pass it to a PHP script that processes the data and displays the CAPTCHA. The CAPTCHA form would then send the data, maybe through $_SESSION variables to a script that validates the CAPTCHA response. If everything checks out, the script could perform a header() redirect to "website.com/abc.php".
-
echo many same id numbers from mysql database
cyberRobot replied to sungpeng's topic in PHP Coding Help
You could give it a shot <?php $sql = mysql_query("SELECT * FROM database where id=$id"); while($do=mysql_fetch_array($sql)){ echo "<div>{$do['id']}</div>"; } ?> Note that I added a semi-colon after the call to mysql_query(). And in case you are not aware, the mysql_* functions have been removed from the newest version of PHP. You need to switch to PDO or MySQLi soon. More information can be found here: http://php.net/manual/en/mysqlinfo.api.choosing.php -
Help with media screen style link for PHP web script
cyberRobot replied to Chrisj's topic in CSS Help
Is the href attribute pointing at the correct location for the file? Have you tried using a root-relative link? More information can be found here: http://www.motive.co.nz/glossary/linking.php?ref#root