Psycho
Moderators-
Posts
12,157 -
Joined
-
Last visited
-
Days Won
129
Everything posted by Psycho
-
As kenrbnsn included in his code, but did not state, the second, optional, parameter for htmlspecialchars_decode is for "quote style": From the manual: quote_style constants Constant Name Description ENT_COMPAT Will convert double-quotes and leave single-quotes alone (default) ENT_QUOTES Will convert both double and single quotes ENT_NOQUOTES Will leave both double and single quotes unconverted
-
Just scroll down onthe manual page for htmlentities and you will see related functions. one of which is . . . html_entity_decode
-
What do you mean "it's not accepting it."? What is the HTML output? Is there is a value in the size field? If not, the value is not being set. But, you should not be using the FONT tag anyway - it has been deprecated since 1999.
-
[SOLVED] i have a table in php and i want to highligh every other row
Psycho replied to jeger003's topic in PHP Coding Help
How is that more efficient than this $bgcolor = ($bgcolor!='#94FF79') ? '#94FF79' : '#000000'; The code you posted requires the script to maintain a counter variable and perform a division on each loop. And, then you could determine the value for the background color. The code I posted only has to do a single comparison to determine the color. -
[SOLVED] i have a table in php and i want to highligh every other row
Psycho replied to jeger003's topic in PHP Coding Help
No offense taken. OK, I see the error. I changed some of the variable names for "consistency". For example, if you are doing two queries and you have completely consumed the results of the first query before running the second query I reuse the variable for the query results. I can't confirm this, but it would seem logical that this would be more efficient from a memory perspective. If the first set of results are in one variable and you create a second variable for the second reslut - all of that data is in memory. By reusing the variable the first set of data is removed from memory and replaced by the second set. Plus, if I do use mutiple variables for queries or query results I would to give them descriptive names instead of $results1, $results, etc. There's nothing wrong with using those - it's a preference thing. But, it does make it easier if you have to go back to code at a later time. Anyway, just change this //Display records while($LogF = mysql_fetch_array($result2)) To this //Display records while($LogF = mysql_fetch_array($result)) -
[SOLVED] i have a table in php and i want to highligh every other row
Psycho replied to jeger003's topic in PHP Coding Help
You could simply use the same kind of logic I used - check if there are any records in the result. If so, show the results. If not, show an appropriate message. When you say you couldn't get the code to work, what does that mean? Were there errors? If so, what? I don't have your database to test with so the code was just written "off the cuff" and I didn't even test it for syntax errors. Any code I provide is typically as a guide for the person to build on. Which is why my sig states "I do not always test the code I provide, so there may be some syntax errors.". If you want to provide some specifics I'll be happy to help troubleshoot. -
Well, this has been moved into the AJAX forum. But, depending on the amount of data it might be more efficient to just handle it in JavaScript. If you are dealing with a "relatively" small list of data, you could simply use the data in the database to create javascript arrays on the page for all of the select list options and swap out the values only using JavaScipt. I say relatively because how big is too big is up to you. You could run some tests to see if there are any performance issues, but you could probably have hundreds of options before you see anything noticable. If you do have a lot of options or just don't want all the options in the code, then you would want to use AJAX. however, you should include a way for users without JS to use the form too. Probably just keep the currentl functinoality you have, but instead of using javascript to change the page have a button to update the list that simple submits the form and checks the "make" field to redisplay the form with the appropriate values. So, if you do want to use AJAX, here is a tutorial for you: http://www.satya-weblog.com/2007/04/dynamically-populate-select-list-by.html
-
I am not completely understanding what you are describing. Let me paraphrase what I *think* you are doing. You have a PHP page (backstage.php) which in turn has numerous function on the page (backstagefunctions.php). There is also an AJAX page (whatever that means) which holds some variables. I don't know what you mean by calling that an AJAX page since it doesn't DO anything but set some variables. I would assume the term "AJAX page" to mean a PHP page that is called through an AJAX request and performs some actions. OK, on the main page there must be some actions which trigger an AJAX request. I *think* you have multiple forms on the backstage.php page and depending on which form is submitted (through AJAX) you want different processes to occur. If what I stated above is correct, there are two solutions that come to mind. 1) Have the "onsubmit" action for each form call a different page through AJAX to process the request. The "form variables" could then be included within each of those processing pages. 2) Continue to have a single processing page that is called through AJAX, but add a parameter to the request based upon the form (e.g. $_GET['mode']) so the processing page can determine which functions and variables to use.
-
[SOLVED] i have a table in php and i want to highligh every other row
Psycho replied to jeger003's topic in PHP Coding Help
This code is a little more efficient/flexible IMHO - and uses only one query and protects against SQL injection. I would highly suggest you use styles within your HTML. The FONT tag has been depricated since HTML 4.01 in 1999! Plus, you can use style classes that allow you to change the style for every cell with a single modification insterad of modifying each individual cell declaration in the HTML //Get the user records $query = "SELECT id, date, title, price, duration FROM classifieds JOIN sessions ON classifieds.seller = sessions.id WHERE sessions.session = '" . mysql_real_escape_string($_COOKIE['session']) . "'"; $result = mysql_query($query) or die(mysql_error()); if (!mysql_num_rows($result)) { echo "There were no results"; } else { //Create table header echo "<table style=\"font-size:10pt;" border=\"0\" cellpadding=\"2\">\n"; echo "<tr style=\"background-color:#009900;text-align:center;color:#FFFFFF;font-weight:bold;\">\n"; echo "<th>ID</th>\n"; echo "<th>Date</th>\n"; echo "<th>Title</th>\n\n"; echo "<th>Price</th>"; echo "<th>Duration</th>\n"; echo "</tr>\n"; //Display records while($LogF = mysql_fetch_array($result2)) { $bgcolor = ($bgcolor!='#94FF79') ? '#94FF79' : '#000000'; echo "<tr>"; foreach ($LogF as $field => $value) { echo "<td style=\"background-color:{#94FF79};\"> "; echo ($field!='title') ? $value : urldecode($value); echo "</td>\n"; } } echo "</table>"; } -
[SOLVED] can't get a simple form to input data into mysql database
Psycho replied to jeger003's topic in PHP Coding Help
I think a better option than running a new query would be to use mysql_affected_rows() which tells you the number of affected rows from the last executed query. -
[SOLVED] Drop Down Menu Hide Part When Admin Logged In
Psycho replied to karl_009's topic in PHP Coding Help
The problem you state appears to be due to lack of validation on the userinfo.php page. I would suggest NOT appending the username as a parameter to that link. Otherwise any user could append another user's name to that link and see any other user's information - a big security risk. Instead you should just have userinfo.php check the current user's name and use that. However, you might want to append the username to the link for an admin to be able to see other people's info - in which case that page should check if the current user is an admin before using the value on the query string. But, your problem was that '$session->username' is a PHP variable and you put it int he plain HTML code. You need to have it within PHP code to be processed. I showed how that would be done below, but I would still advise against that kind of method. <li><a href="#" onMouseOver="mopen('m5')" onMouseOut="mclosetime()">User Tools</a> <div id="m5" onMouseOver="mcancelclosetime()" onMouseOut="mclosetime()"> <a href="userinfo.php?user=<?php echo $session->username; ?>">My Account</a> <a href="useredit.php">Edit Account</a> <a href="process.php">Logout</a> </div> </li> -
[SOLVED] Drop Down Menu Hide Part When Admin Logged In
Psycho replied to karl_009's topic in PHP Coding Help
Simple, just enclose that section in a similar if statment. Only included the relevant code for brevity: <li><a href="#" onMouseOver="mopen('m5')" onMouseOut="mclosetime()">Contact</a> <div id="m5" onMouseOver="mcancelclosetime()" onMouseOut="mclosetime()"> <a href="#">E-mail</a> <a href="#">Submit Request Form</a> <a href="#">Call Center</a> </div> </li> <?php if($session->isAdmin()){ ?> <li><a href="#" onMouseOver="mopen('m6')" onMouseOut="mclosetime()">Admin Tools</a> <div id="m6" onMouseOver="mcancelclosetime()" onMouseOut="mclosetime()"> <a href="#">Admin Centre</a> <a href="#">Request User Form</a> </div> </li> <?php } ?> </ul> <div style="clear:both"></div> However, if it were my code, I woul rewrit ethe whole thing to be generated dynamically since each "option" is structured the same with different values. -
[SOLVED] Transfer data from one window to another
Psycho replied to M.O.S. Studios's topic in Javascript Help
Use "window.opener". Here's a quick example: page1.htm <html> <body> <a href="test2.htm" target="page2">Open page 2</a> <form name="form1"> Value from page 2: <input type="text" name="page2value"> </form> </body> </html> page2.htm <html> <head> <script type="text/javascript"> function sendToPageOne() { var thisValue = document.getElementById('page2Value').value; window.opener.form1.page2value.value = thisValue; } </script> </head> <body> <form name="form2"> <select name="page2Value" id="page2Value"> <option value="one">One</option> <option value="Two">Two</option> <option value="Three">Three</option> </select> </form> <button onclick="sendToPageOne();">Send to page 1</button> </body> </html> -
[SOLVED] can't get a simple form to input data into mysql database
Psycho replied to jeger003's topic in PHP Coding Help
INSERTS don't have where clauses. Except maybe when using sub-queries -
The first problem with the above is that 12:34 AM would be represented as 00:34. 12:34 would be 12:34 PM. So, assuming you are using 24 hour time, this would work (although I'm sure there is something more efficient): function timeDiff($startTime, $endTime) { $startTimes = explode(':', $startTime); $endTimes = explode(':', $endTime); $startMinutes = ($startTimes[0] * 60) + $startTimes[1]; $endMinutes = ($endTimes[0] * 60) + $endTimes[1]; if ($endMinutes > $startMinutes) { $diffMinutes = ($endMinutes - $startMinutes); } else { $diffMinutes = ((24*60) - $startMinutes + $endMinutes); } $hours = str_pad(floor($diffMinutes/60), 2, 0, STR_PAD_LEFT); $minutes = str_pad($diffMinutes-($hours * 60), 2, 0, STR_PAD_LEFT); return "{$hours}:{$minutes}"; } $wake = '00:34'; $sleep = '07:55'; echo timeDiff($sleep, $wake); // 16:39
-
OMG: letmegooglethatforyou.com Never saw that before - priceless.
-
Are you using MySQL? "TOP" is a SQL function not a MySQL function. You need to use LIMIT. SELECT * FROM `table` ORDER BY `column' DESC LIMIT 15
-
I would guess that within the data there might be two records that do not have a sub-element for "['cluster']['campus'][$campusID]['item']" or that element is not an array. Try changing that code to this: //Sort the types for each campus element //Use 'usort' if you do not need/want to maintain index associattions foreach ($arrayData['cluster']['campus'] as $campusID => $campusAry) { if (is_array($arrayData['cluster']['campus'][$campusID]['item'])) { usort($arrayData['cluster']['campus'][$campusID]['item'], "sortTypes"); } }
-
Thanks for that. Although I do see some inconsistencies when sorting anything with leading 0's. But, strcasecmp() does return what I expect to be the results wanted in 95% of cases.
-
Assuming $campusarray is the name of the array in question, this will do what you want: function sortNames($a, $b) { $strA = strtoupper($a['name']); $strB = strtoupper($b['name']); if ($strA == $strB) { return 0; } return ($strA < $strB) ? -1 : 1; } function sortTypes($a, $b) { $strA = strtoupper($a['type']); $strB = strtoupper($b['type']); if ($strA == $strB) { return 0; } return ($strA < $strB) ? -1 : 1; } //Sort the array by campus names //Use 'usort' if you do not need/want to maintain index associattions uasort($campusarray['cluster']['campus'], "sortNames"); //Sort the types for each campus element //Use 'usort' if you do not need/want to maintain index associattions foreach ($campusarray['cluster']['campus'] as $campusID => $campusAry) { uasort($campusarray['cluster']['campus'][$campusID]['item'], "sortTypes"); }
-
A checkbox value is the same whether the checkbox is checked or not. You need to test if the field is checked - not the value: else if(!this.elements['iagree'].checked) { alert("Please check the I AGREE box to accept the terms"); return false; }
-
how to retain drop-down menu selected state when the page reposts.
Psycho replied to louis_coetzee's topic in PHP Coding Help
$options = array ('One', 'Two', 'Three', 'Four'); echo "<select name=\"number\">\n"; foreach ($options as $optValue) { $selected = ($optValue == $_POST['number']) ? ' selected="selected"' : ''; echo "<option value=\"{$optValue}\"{$selected}>{$optValue}</option>\n"; } echo "</select>\n"; EDIT: Corrected a couple errors -
Take a look at this post that is 6 down from this one: http://www.phpfreaks.com/forums/index.php/topic,233619.0.html
-
<script type="text/javascript" language="javascript"> function validate(form2) { var valid = true; if (form2.username.value) { document.getElementById('username_error').innerHTML = ''; } else { document.getElementById('username_error').innerHTML = 'Please enter a username.'; valid = false; } if (!form2.password.value || !form2.confirm.value) { document.getElementById('password_error').innerHTML = 'You must enter a password and confirm it.'; valid = false; } else if (form2.password.value != form2.confirm.value) { document.getElementById('password_error').innerHTML = 'Passwords do not match.'; valid = false; } else { document.getElementById('password_error').innerHTML = ''; } return valid; } </script>
-
When positioning an element using absolute positioning it is done so relative to the top-left position of the element. So, if you used top:50% and left:50%, it will set the top-left corder of the element to the center of the page. But, to get the entire element positioned in the center you will need to offset half the height and half the width. That is what the negative values are for. Try removing those values from the attributes and you will see what I mean.