Jump to content

Psycho

Moderators
  • Posts

    12,159
  • Joined

  • Last visited

  • Days Won

    130

Everything posted by Psycho

  1. Why would you do that? I suggest always keeping your data in it's "raw" state. If you ever need to use that data as HTML code you will have a harder time converting that code back. A better solution, IMHO, would be to simply use htmlspecialchars() or htmlentities() to convert the text on-the-fly to replace the necessary characters.
  2. I really don't understand what the problem is based upon your description. But, looking at the code I think I know what the problem is. After you run the query and define the array $list, you then run a foreach loop on $list to output the records. But, inside that loop you are echoing $year and $month. Those variables were assinged values on each iterration of the while loop. So, when it comes time to run the foreach loop $month and $year will always display the last values defined in the previous while loop. You could solve this by modifying your foreach loops like this: foreach($list as $year => $years) foreach($months as $month => $item) But a better solution would be to revise your query and only process the records once $query = "SELECT title, id, dateColumn FROM theTable ORDER BY dateColumn ASC"; $result = mysql_query($query); $current_year = false; $current_month = false; while($row = mysql_fetch_assoc($result) ) { $year = date("Y", $row['dateColumn']); $month = date("m", $row['dateColumn']); if($current_year != $year) { echo "$year : "; } if($current_month != $month || $current_year != $year) { echo "$month : "; } $current_year = $year; $current_month = $month; echo "<a href=\"site address by {$row['id']}\">{$row['title']}</a>"; }
  3. I'm surprised your query isn't failing! You are trying to run the query in the variable $query - but it hasn't been defined. Instead you defined the query in the variable $sql. But, I am confused as to why you would be running mysql_num_rows() against the result since the query is to CREATE a table, so I don't see how there would be any rows returned.
  4. Either I am not understanding you or you are making this more difficult than it needs to be. You are apparently alble to convert the time entered by the user to the appropriate UTC timestamp. The whole point of using UTC is to ensure you are storing the time in a mormalized format. So, when you need to query the database, just offset the timestamps you use as needed for the local time of the server.
  5. In short no. I assume the PowerPoint is a prepatory document for the test and they are not supposed to refer to it during the test. Even if you could ensure they close the document or only made the content avaiable in a web page, you couldn't prevent the user from copying the content or taking screen captures of it.
  6. What do you mean by "...I am not getting anything.". Did you check that the query ran successfully? were there records returned? What? There is nothing in the code above that would DO anything. You need to echo/output the results in some way. Plus, the mysql_result() function above is trying to access the second record. Try the following: mysql_select_db($database_ballot, $ballot); $sql = "SELECT party, COUNT(party) as total FROM votes GROUP BY party"; $result = mysql_query($sql); if(!$result) { echo "The query failed: " . mysql_error(); } elseif() { echo "No results returned"; } else { while($row = mysql_fetch_assoc($result)) { echo "{$row['party']}: {$row['total']}<br />\n": } }
  7. Not sure what you are trying to achieve really. Why are you wanting to change the timezone setting at runtime for different regions in the same script? As stated above, a timestamp is relative to UTC time. Is there some reason you need the date/time as a timestamp (i.e. in an integer format)? If not, just store the date/time as a string or a Date/Time value in the database, so it will not be relative to UTC.
  8. Does no one read the manual anymore? So, if UTC is currently at 12:00:00 am and my local time is 5:00am and your local time is 7:00am, the timestamp returned by strtotime() would be exactly the same for both of us - since it is relative to UTC. If I waited until 7:00am my time to run strtotime() I woul dhave a timestamp that is 2 hours higher than the one you ran at 7am.
  9. Why are you making the query so complicated? Just use COUNT() with a GROUP BY. Just follow normal process of connecting to the database (look up a tutorial if needed). SELECT Party, COUNT(Party) as total FROM votes GROUP BY Party
  10. I suspect it is because your AJAX call is asynchronous? Not sure since I'm not going to try and decypher a 100 lines of code to understand what is calling what. The fact that you are putting in an alert gives enough time for the asynchonous process to complete before that block of code is executed.
  11. What Ignace is suggesting is using different submit buttons for the action to be taken. The problem with this approach is that pressing enter will submit a form and there will be no submit value to check on the receiving page. However, the only time you would even consider that is if you were using the same form fields for different operations. I can't believe you would be using the same form fields for a "reply" and a "delete". So the solution is as requinix suggested and have two separate forms. One form must be closed before you start another. <form name="reply"> // reply form goes here </form> <form name="delete"> // delete form goes here </form>
  12. This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=316055.0
  13. $input = "By rd, RaeAnn Martin, Emily Sheene and Ebony Alcorn.<br /><br /> <p>Danville High School students:"; $output = preg_replace('#<br \/>.*#', '', $input);
  14. Wow, that's some pretty rough code. I can't even follow what you are doing in some places. For example: $keywords = $getrow['keywords']; I don't see $getrow defined anywhere. Anyway, I think the problem is the consrtuction of your WHERE clause. You could have validated this easily enough by simply echoing the query to the page. It looks as if you are using the counter as the seach term not the actual search terms. Plus, there is a problem in the logic if you were to have two consecutive spaces. But, you are making it much more difficuly than it needs to be with all those loops. $button = trim($_GET['submit']); $search_phrase = trim($_GET['search']); if(strlen($search_phrase)<2) { echo "Search term too short"; } else { echo "You searched for <b>$search_phrase</b><hr size=\"1\">\n"; mysql_connect("localhost", "root", "supersham"); mysql_select_db("carbreaker"); $keywords = $getrow['keywords']; //explode our search term $search_words = explode(" ", $search_phrase); $like_parts = array(); foreach($search_words as $word) { if($word<>'') { $like_parts[] = "keywords LIKE '%" . mysql_real_escape_string($word} . "%'"; } } $where_clause = (count($like_parts)>0) ? "WHERE ".implode(' OR ', $like_parts) : ''; //echo out construct $construct = "SELECT * FROM stock $where_clause"; $run = mysql_query($construct); $foundnum = mysql_num_rows($run); if($foundnum==0) { echo "No Stock Found"; } else { echo "$foundnum results found<br />\n"; while($row = mysql_fetch_assoc($run)) { echo "<b>{$row['make']}</b> {$row['model']} {$row['year']} {$row['cc']} {$row['fuel']} {$row['doors']} {$row['body']} {$row['date']}<br />\n"; } } }
  15. Two problems: One you are running the query twice. Once before the condition test and once inside the IF condition test mysql_query ($query); if (mysql_query($query)) { die('Error: ' . mysql_error()); } Second, your IF condition is backwards. The way you have, it there will only be an error message if the query successfully completes! Use this: //mysql_query ($query); if (!mysql_query($query)) { die('Error: ' . mysql_error()); }
  16. @blink359's code will work, but it is not good programming. If you are not going to use the records where name!='' then don't pull them from the database. Otherwis,e you are just wasting system resources on the server. I just did a test and the solution I provided works to exclude records that have a name value of NULL or an empty string: $result = mysql_query("SELECT * FROM info"); while ($row = mysql_fetch_array($result)) { echo "id: {$row['id']}, name: {$row['name']}, number: {$row['number']}<br />\n"; }
  17. I think it depends on whether the ones you want to exclude have an empty string value or a null value - there is a diffrence. Try this: select * from info where name <> '' Edit: Actually I don't think nulls will matter since they won't be included in the result set or the excluded set since you can't compare null to a non null value.
  18. Impossible for us to day. Why don't you ask the SQL server what the problem is? mysql_query($sql) or die(mysql_error());
  19. No need to go remove the "+0000". That "string" can be easily converted to a timestamp using strtotime(). The +0000 is important and is used by strtotime() to convert the time based upon Greeenwich Mean Time (GMT) or UTC depending on what you like to call it. But, strtotime() will normalize the time according to the timezone of the server. If you remove the +0000 then the time is converted as if it was based in your timezone - which it isn't. So, removing the +0000 will result in the time being off by however many hours difference between GMT and the server's timezone: echo date('m-d-Y H:i:s', strtotime('Fri, 29 Oct 2010 11:22:58 +0000')); For me, that outputs 10-29-2010 06:22:58 because on October 29 there was a five hour difference between my timezone (Central Time) and GMT. However, if I ran that for today's date, there would be a 6 hour difference because we moved our clocks back one hour a week ago from daylight savings time to standard time.
  20. Not quite sure what you are trying to say there. Are you saying that each upload will consist of several fields: one for the actual file upload and additional fields to describe the upload? If so, then all the fields should be defined as arrays. Example File 1: <input type="file" name="files[]" /> Type: <select name="filetype[]"><option>Avatar</option><option></option>thumb</select> Name: <input type="text" name="file_name" /> File 2: <input type="file" name="files[]" /> Type: <select name="filetype[]"><option>Avatar</option><option></option>thumb</select> Name: <input type="text" name="file_name" /> //etc... Then, on the processing page, to access the fields for the first image you would use: $_POST['files'][0], $_POST['file_type'][0], $_POST['file_name'][0] For the second image: $_POST['files'][1], $_POST['file_type'][1], $_POST['file_name'][1] etc.
  21. First off a file upload field is not a text box - it is a file input that will include a browse button. Anyway, you can simply create your form with however many file input fields as you want. Then, using javascript, provide a method for the user to add more input fields. The key to this is to name the input fields as an array. Then you can reference the fields on the receiving page as an array <input type="file" name="files[]"
  22. I would suggest not validating the "format" of the phone number and instead validate that the phone number has the correct number of digits. Then you can store just the numbers in your database and use a consistent manner in which to display the phone number. For example (using US numbers), I would allow the user to enter in any value that consisted of 10 numeric digits OR 11 digits if the first number was a 1: - 123-465-7890 - (123) 456-789 - 123.456.7890 - 1-123-456-7890 Sampe code for validating function validPhone($phone) { //Remove all non digits $phone = preg_replace('/[^\d]/', '', $phone); //Test number of digits if(preg_match('/^1?\d{10}$/', $phone) !=1 ) { return false; } return $phone; } That function will return false if the number doesn't contain a valid number of digits, else it returns just the digits of the number. So, if validation passes I store just the numeric digits of the entered value. Then, whenever I need to display the value on the page I would have a function to format the phone numbers in a consistent format. function formatPhone($phone) { if(!$phone) { return false; } $format = (strlen($phone)==10) ? '(\2) \3-\4' : '\1 (\2) \3-\4'; return preg_replace('/(\d)(\d{3})(\d{3})(\d{4})/', $format, $phone); }
  23. No, I won't find that. I only have IE on my work PC and I refuse to test it at home on the basis that I might have to admit there is a problem with the code I submitted.
  24. Well, to answer the question originally posed - it is absolutely possible to change the source of an included javascript source file. Done this before. You just use javascript to change the src attribute for the script object. The easiest way to do this is to include an ID in the script tag. Here are a few test files to illustrate how it works. html document: <html> <head> <script id="jsInclude" type="text/javascript" src="one.js"></script> <script type="text/javascript"> function changeJS(jsFile) { document.getElementById('jsInclude').src = jsFile; } </script> </head> <body> <button onclick="changeJS('one.js');">Use JS1 Include</button> <button onclick="changeJS('two.js');">Use JS2 Include</button> <br /><br /> <button onclick="test();">Run the test function</button> </body> </html> JS source file one.js function test() { alert('This is test in include 1.'); } JS source file two.js function test() { alert('This is test in include 2.'); }
  25. Or, the problem could also be in the construction of the page. If you are using a lot of nested tables or there is invalid markup it could cause the browser to hang. You can easily test this by loading a page in the browser and then saving it locally to the client PC. Then reopen the page from the local copy. If there is still a problem in the page displaying it is with the content and not the creation.
×
×
  • 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.