Jump to content

Psycho

Moderators
  • Posts

    12,157
  • Joined

  • Last visited

  • Days Won

    129

Everything posted by Psycho

  1. That code makes no sense to me, so I can't determine what it's supposed to do. 1. Where is the initial value of i defined? 2. The regular expression is crafted to search for the string 'i' not the variable i; so what is the purpose of the loop? It's just checking the same string over and over for the same search value 3. The code will return true if the search value is found. But, I see no "return false" if it does not. Please explain what you are wanting the code to do along with some sample input and outputs you would expect to use.
  2. Here's the problem: var euro = Math.round((amt * .0.636821) * 100) / 100; Remove the extra decimal!
  3. Just "read" the file as text and then echo to the page: "stolen" example from tizag.com: http://www.tizag.com/phpT/fileread.php $myFile = "testFile.php"; $fh = fopen($myFile, 'r'); $theData = fread($fh, filesize($myFile)); fclose($fh); echo "<pre>$theData</pre>";
  4. Put the html in a more logical format and it will be easier: <?php // Get all the data from the "example" table $result = mysql_query("SELECT * FROM example ORDER BY score DESC") or die('O no. Theres an error'); echo "<table border='1'>"; echo "<tr><th>ID</th><th>Name</th><th>Score</th></tr>"; // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table echo "<tr>\n"; echo "<td>".$row['id']."</td>\n"; echo "<td>".$row['name']."</td>\n"; echo "<td>".$row['score']."</td>\n"; echo "</tr>\n"; } echo "</table>"; ?>
  5. By "cell" do you mean "row". If so, your post makes sense. If not, then I don't know what you mean. To alternate colors in a table you could do the following: echo "<table>"; while ($row = mysql_fetch_assoc($result)} { $bgcolor = ($bgcolor=="#cecece")?"#696969":"#cecece"; echo "<tr style=\"background-color:$bgcolor;\">"; echo "<td>".$row['name']."</td>"; echo "<td>".$row['phone']."</td>"; echo "<tr>"; } echo "</table>";
  6. Here is a javascript solution. Of course you SHOULD create the same functionality in PHP in case users have JS disabled - the same logic will apply. But, for situations like these I think the addition of Javascript is a definite benefit: I'm sure this could be done more efficiently, but based upon the time I was willing to invest in this it does work. <html> <head> <script type="text/javascript"> function validateCheck() { formObj = document.getElementById('grid'); var totalCount = 0; var rowCount = new Array(); rowCount[0] = 0; rowCount[1] = 0; rowCount[2] = 0; for (var i=1; i<=9; i++) { if (formObj['B'+i].checked) { totalCount++; rowCount[(Math.ceil(i/3)-1)]++; } } var disableState = new Array(); disableState[0] = false; disableState[1] = false; disableState[2] = false; //Determine rows to disable if (totalCount==4) { disableState[0] = true; disableState[1] = true; disableState[2] = true; } else { if (rowCount[0]==2 || (rowCount[0]==1 && (rowCount[1]==2 || rowCount[2]==2))) { disableState[0] = true; } if (rowCount[1]==2 || (rowCount[1]==1 && (rowCount[0]==2 || rowCount[2]==2))) { disableState[1] = true; } if (rowCount[2]==2 || (rowCount[2]==1 && (rowCount[0]==2 || rowCount[1]==2))) { disableState[2] = true; } } //Disable/enable unchecked boxes for (var i=1; i<=9; i++) { if (!formObj['B'+i].checked) { formObj['B'+i].disabled = disableState[(Math.ceil(i/3)-1)]; } } return; } </script> </head> <body> <form name="grid" id="grid"> <table border="1"> <tr> <td><input type="checkbox" id="B1" name="B1" value="B1" onclick="validateCheck();" />B1</td> <td><input type="checkbox" id="B2" name="B2" value="B2" onclick="validateCheck();" />B2</td> <td><input type="checkbox" id="B3" name="B3" value="B3" onclick="validateCheck();" />B3</td> </tr> <tr> <td><input type="checkbox" id="B4" name="B4" value="B4" onclick="validateCheck();" />B4</td> <td><input type="checkbox" id="B5" name="B5" value="B5" onclick="validateCheck();" />B5</td> <td><input type="checkbox" id="B6" name="B6" value="B6" onclick="validateCheck();" />B6</td> </tr> <tr> <td><input type="checkbox" id="B7" name="B7" value="B7" onclick="validateCheck();" />B7</td> <td><input type="checkbox" id="B8" name="B8" value="B8" onclick="validateCheck();" />B8</td> <td><input type="checkbox" id="B9" name="B9" value="B9" onclick="validateCheck();" />B9</td> </tr> </table> </form> </body> </html>
  7. And you are unable to load the site...? Are you sure 1) It is not your IP, 2) Assuming it is not your IP, that your "fix" is only blocking that IP?
  8. This appears to work. It worked for strings with multiple instances, but I hav enot done extensive testing. <?php function q($q_str) { global $db_name $q_str = eregi_replace(" / [^']*", '', $q_str); $r = mysql($db_name, $q_str); return $r; } ?>
  9. Well, part of your post makes no sense. If you put the variables as list items where the variables equal 1, then you will just have a list of 1's. Do you want the variable name as the list item? I would suggest changing the variables to array elements. <?php $vars['var1'] = 0; $vars['var2'] = 1; $vars['var3'] = 0; $vars['var4'] = 1; echo "<ul>"; foreach ($vars as $varname => $varValue) { if ($varValue==1) { echo "<li>$varName</li>"; } } echo "</ul>"; ?> The output would look like this: var2 var4
  10. And...? What values are you wanting to count?
  11. The <? ?> are the "short" tag version of <?php ?> and yes, there is a setting that needs to be enabled to support the short tags. It's best to just always use the full tags.
  12. I "think" I undersand what you want. What you are asking for is pretty much a JavaScript solution. I would suggest making each cell a form input field. When unselected make the field disabled. When selected make it enabled. Simply add an onclick trigger to change the disabled state. When a form is submitted disabled fields are not inlcuded in the submission. You can also use style properties so they doesn't "look" like input fields. Here's a quick example. You would also want to create an onsubmit trigger to diable any fields that do not have the class of "active" <html> <head> <style> input { border:0px; } .active { background-color:yellow; } .inactive { background-color:#cecece; } </style> <script type="text/javascript"> function changeState(fieldObj) { if (fieldObj.className=='active') { newClass = 'inactive'; } else { newClass = 'active'; } fieldObj.className = newClass; return; } </script> </head> <body> <table> <tr> <td><input type="text" class="inactive" value="Cell Data" onclick="changeState(this);"></td> <td><input type="text" class="inactive" value="Cell Data" onclick="changeState(this);"></td> </tr> <tr> <td><input type="text" class="inactive" value="Cell Data" onclick="changeState(this);"></td> <td><input type="text" class="inactive" value="Cell Data" onclick="changeState(this);"></td> </tr> </table> </body> </html>
  13. I ran your post through a translation and it didn't help much. But, from looking at your code I think the problem is that you are trying to add the single quotes when dynamically referring to the array index. Here are some examples that may help explain <?php $array['test'] = "The array value"; $index1 = "'test'"; $index2 = "'".$name."'"; $index3 = "test"; // NO ' (single quotemarks) echo "Test1: " . $array[$index1] . "<br>"; echo "Test2: " . $array[$index2] . "<br>"; echo "Test3: " . $array[$index3] . "<br>"; //Output //Test1: //Test2: //Test3: The array value ?>
  14. mysql_fetch_row() returns th results in an enumerated array (i.e. $row[0], $row[1], $row[2], etc.). You want to use mysql_fetch_assoc() to have the results returned in an associative array (i.e. $row['name'], $row['email'], $row['phone'], etc.)
  15. No, in the method I proposed above the global variable "playing" would detemine if the clip was playing or not. When the page first loads the variable is set to 'false'. When you click the link it will first determine the current value of 'playing'. If it is false it will start the clip and change the value of the variable to 'true'. If the value is already 'true' it will stop the clip and change the value to 'false'. If you are trying to control multiple clips on the same page you will need to have several control variables or use an array.
  16. The code you posted does not help. Does the soundmanager script have a method for stopping the sound? If so, I wold create an intermediary function that does the switching. Here is an example based upon the premise that you can stop the sound via soundManager.stop(). However, that is complete conjecture. Create the following function (and global variable): var playing = false; function playMusic(soundID, path) { if (playing) { soundManager.stop(soundID); playing = false; } else { soundManager.play(soundID, path); playing = true; } } Change the link above as follows: <a href=\"javascript:playMusic('mySound0','/clips/RickCarterJessica.mp3')\">< EDIT: Based upon a quick review of the soundmanager methods it appears there is a stop() method, but requires you to pass the id. Modified the code above
  17. To get the ID3 info from audio files is easy with the free getID3() class. http://getid3.sourceforge.net/
  18. I just realized I left some debugging code in. Anyway, here is the loop w/o the debugging code and with the necessary step to calculate total size of all files: // fetch entries while($fileName = readdir($myDirectory)) { //Only process files if (!is_dir($path.'/'.$fileName)) { //Only process files with valid extensions $ext = strtolower(array_pop(explode(".", ($fileName)))); if (in_array($ext, $valid_extensions)) { $fileIdx = count($dirArray); $size = filesize($fileName); $totalSize += $size; $dirArray[$fileIdx]['name'] = $fileName; $dirArray[$fileIdx]['ext'] = $ext; $dirArray[$fileIdx]['dateSort'] = date('Ymd', filemtime($fileName)); $dirArray[$fileIdx]['date'] = date('m/d/Y', filemtime($fileName)); $dirArray[$fileIdx]['size'] = round(($size / 1024 / 1024), 2); } } } $totalSize = round(($totalSize/ 1024 / 1024), 2);
  19. OK, yet another new approach. This time we are going to use usort() which requires a user defined function. Also, you do not need to put upper-case and lower-case values in the valid extensions list. I force the actual extension to lower-case when doing the check. So, just enter the values into the $valid_extensions array in lower case and you are all set. <?php function sortByDate($a, $b) { if ($a['dateSort'] == $b['dateSort']) { return 0; } return ($a['dateSort'] < $b['dateSort'])? -1 : 1; } //Valid extensions $valid_extensions = array ('mp3', 'wma'); $path = '.'; $dirArray = array(); // open dir $myDirectory = opendir($path); // fetch entries while($fileName = readdir($myDirectory)) { //Only process files if (!is_dir($path.'/'.$fileName)) { //Only process files with valid extensions $ext = strtolower(array_pop(explode(".", ($fileName)))); echo $ext; if (in_array($ext, $valid_extensions)) { echo ": True"; $fileIdx = count($dirArray); $dirArray[$fileIdx]['name'] = $fileName; $dirArray[$fileIdx]['ext'] = $ext; $dirArray[$fileIdx]['dateSort'] = date('Ymd', filemtime($fileName)); $dirArray[$fileIdx]['date'] = date('m/d/Y', filemtime($fileName)); $dirArray[$fileIdx]['size'] = round((filesize($fileName) / 1024 / 1024), 2); } echo "<br>"; } } // close dir closedir($myDirectory); //Sort by key usort($dirArray, 'sortByDate'); echo "<font face=verdana size=3 color=#F8F304><B>"; echo ":: To download right click on a track and 'save as...'</B><br>\n"; echo ":: To upload click the link at the top-right.<br><br>\n"; echo ":: Current Track Count: " . count($dirArray) . "</font>\n"; // print header row echo "<center>\n"; echo "<table width=\"95%\" border=\"1\" align=\"left\" cellpadding=\"0\" cellspacing=\"0\" bordercolor=\"#183041\">\n"; echo "<tr align=\"left\" background=\"http://bridgey.net/img/row_bg.gif\">\n"; echo " <th>Name</th>\n"; echo " <th>Type</th>\n"; echo " <th>File Size</th>\n"; echo " <th>Date Added</th>\n"; echo "</tr>\n"; // print results foreach ($dirArray as $file) { echo "<tr background=\"http://bridgey.net/img/row_bg.gif\">\n"; echo " <td align=\"left\" background=\"http://bridgey.net/img/row_bg.gif\">"; echo "<font face=\"verdana\" size=\"2\" color=\"#D9F4FD\"><b> "; echo "<a href=\"{$file['name']}\"><img src=\"../img/star.gif\" border=\"0\">"; echo $file['name'] . "</a></b></font></td>\n"; echo " <td background=\"http://bridgey.net/img/row_bg.gif\">{$file['ext']}</td>\n"; echo " <td background=\"http://bridgey.net/img/row_bg.gif\">{$file['size']}</td>\n"; echo " <td background=\"http://bridgey.net/img/row_bg.gif\">{$file['date']}</td>\n"; echo "</tr>\n"; } echo "</table>\n"; echo "</center><br clear=\"all\">\n"; ?>
  20. Oh, I see. Because I used the file date as the array index, if there are multiple files with the same date they will overwrite one another. give me a few minutes and I'll post a fix.
  21. Ah hell, if you're going to do that then I would go with a different appraoch. You can have the results sorted by whatever you define as the $fileIdx value. <?php //Valid extensions $valid_extensions = array ('mp3', 'php'); $path = '.'; $dirArray = array(); // open dir $myDirectory = opendir($path); // fetch entries while($fileName = readdir($myDirectory)) { //Only process files if (!is_dir($path.'/'.$fileName)) { //Only process files with valid extensions $ext = strtolower(array_pop(explode(".", ($fileName)))); if (in_array($ext, $valid_extensions)) { $fileIdx = date('Ymd', filemtime($fileName)); $dirArray[$fileIdx]['name'] = $fileName; $dirArray[$fileIdx]['ext'] = $ext; $dirArray[$fileIdx]['date'] = date('m/d/Y', filemtime($fileName)); $dirArray[$fileIdx]['size'] = round((filesize($fileName) / 1024 / 1024), 2); } } } // close dir closedir($myDirectory); //Sort by key ksort($dirArray); echo "<font face=verdana size=3 color=#F8F304><B>"; echo ":: To download right click on a track and 'save as...'</B><br>\n"; echo ":: To upload click the link at the top-right.<br><br>\n"; echo ":: Current Track Count: " . count($dirArray) . "</font>\n"; // print header row echo "<center>\n"; echo "<table width=\"95%\" border=\"1\" align=\"left\" cellpadding=\"0\" cellspacing=\"0\" bordercolor=\"#183041\">\n"; echo "<tr align=\"left\" background=\"http://bridgey.net/img/row_bg.gif\">\n"; echo " <th>Name</th>\n"; echo " <th>Type</th>\n"; echo " <th>File Size</th>\n"; echo " <th>Date Added</th>\n"; echo "</tr>\n"; // print results foreach ($dirArray as $file) { echo "<tr background=\"http://bridgey.net/img/row_bg.gif\">\n"; echo " <td align=\"left\" background=\"http://bridgey.net/img/row_bg.gif\">"; echo "<font face=\"verdana\" size=\"2\" color=\"#D9F4FD\"><b> "; echo "<a href=\"{$file['name']}\"><img src=\"../img/star.gif\" border=\"0\">"; echo $file['name'] . "</a></b></font></td>\n"; echo " <td background=\"http://bridgey.net/img/row_bg.gif\">{$file['ext']}</td>\n"; echo " <td background=\"http://bridgey.net/img/row_bg.gif\">{$file['size']}</td>\n"; echo " <td background=\"http://bridgey.net/img/row_bg.gif\">{$file['date']}</td>\n"; echo "</tr>\n"; } echo "</table>\n"; echo "</center><br clear=\"all\">\n"; ?>
  22. I cleaned up a lot of your code, but not all of it. For example, the FONT tag has been deprecated for several years now. Just create style classes instead. Anyways, thsi shoudl be very close to what you are wanting: <?php // open dir $path = '.'; $myDirectory = opendir($path); // fetch entries while($entryName = readdir($myDirectory)) { if (!is_dir($path.'/'.$entryName)) { $dirArray[] = $entryName; $fileDates[] = date('Ymd', filectime($entryName)); } } // close dir closedir($myDirectory); //Sort by date array_multisort($fileDates, $dirArray); echo "<pre>".print_r($dirArray)."</pre>"; echo "<font face=verdana size=3 color=#F8F304><B>"; echo ":: To download right click on a track and 'save as...'</B><br>\n"; echo ":: To upload click the link at the top-right.<br><br>\n"; echo ":: Current Track Count: " . count($dirArray) . "</font>\n"; // print header row echo "<center>\n"; echo "<table width=\"95%\" border=\"1\" align=\"left\" cellpadding=\"0\" cellspacing=\"0\" bordercolor=\"#183041\">\n"; echo "<tr align=\"left\" background=\"http://bridgey.net/img/row_bg.gif\">\n"; echo " <th>Name</th>\n"; echo " <th>Type</th>\n"; echo " <th>File Size</th>\n"; echo " <th>Date Added</th>\n"; echo "</tr>\n"; // print results foreach ($dirArray as $file) { $ext = array_pop(explode(".", ($file))); $date = date('d/m/Y', filectime($file)); $sizeinmb = round((filesize($file) / 1024 / 1024), 2); echo "<tr background=\"http://bridgey.net/img/row_bg.gif\">\n"; echo " <td align=\"left\" background=\"http://bridgey.net/img/row_bg.gif\">"; echo "<font face=\"verdana\" size=\"2\" color=\"#D9F4FD\"><b> "; echo "<a href=\"$file\"><img src=\"../img/star.gif\" border=\"0\">"; echo $file . "</a></b></font></td>\n"; echo " <td background=\"http://bridgey.net/img/row_bg.gif\">$ext</td>\n"; echo " <td background=\"http://bridgey.net/img/row_bg.gif\">$sizeinmb</td>\n"; echo " <td background=\"http://bridgey.net/img/row_bg.gif\">$date</td>\n"; echo "</tr>\n"; } echo "</table>\n"; echo "</center><br clear=\"all\">\n"; ?>
  23. Did it work before you modified it? Are you getting any errors after the modification?
  24. Try this: <script type="text/javascript"> function validate_url(o,e){ var patu = /^(((ht|f)tp(s?))\:\/\/)?(www.|[a-zA-Z0-9].)[a-zA-Z0-9\-\.]+(\.[a-zA-Z]{2,4}){1,2}(\:[0-9]+)*(\/($|[a-zA-Z0-9\.\,\;\?\'\\\+&%\$#\=~_\-]+))*$/i; var patd = /^[a-zA-Z0-9][a-zA-Z0-9]+(\.[a-zA-Z0-9]+)+$/i; R=$("#frm1url").val(); if(R && R.length>0 && R.match(patu)!=null){ return true; }else if(R && R.length>0 && R.match(patd)!=null){ return true; }else{ alert("Invalid url entered"); return false; } } </script>
  25. Actually, I think making the file into a PHP file is a good idea. If you were to make the file a simple PHP file which was nothing more than an array conatining the usernames & passwords, then only scripts including that file on your server would "obtain" the values. Anything trying to access the file externally would only get a blank page (because it would be interpreted by the server first) Example: <?php $users = array ( ['username1'] = 'password1', ['username2'] = 'password2', ['username3'] = 'password3' ); ?>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.