Psycho
Moderators-
Posts
12,157 -
Joined
-
Last visited
-
Days Won
129
Everything posted by Psycho
-
You know that won't work, right?
-
$template_file_name = $data['lastname']."_".$data['firstname'].".htm"; Have you tried adding the path to the variable above which you are passing to the file_put_contents() function? Something like: $template_file_name = "subFolderName/" . $data['lastname']."_".$data['firstname'].".htm"; Or, my preference: $template_file_name = "subFolderName/{$data['lastname']}_{$data['firstname']}.htm";
-
alert message after delete not working properly
Psycho replied to cainam29's topic in Javascript Help
First off, the code you have posted is JavaScript and you posted in the PHP forum. << Moving to JS forum >> But, here is the code to determine the message that is displayed: if(data == 'true') { $('#'+id).remove(); alert('Record/s has been deleted!'); } else { alert('Record/s could not be deleted!'); } You are checking if the variable 'data' is equal to the string value 'true'. I don't see where data is defined (looks like it is passed into the function). But, it is obvious that it is not equal to the string 'true'. Either you meant to be checking if 'data' is the Boolean true if(data == true) better yet . . . if(data) Or, data doesn't have the value you think it does. -
I'm not understanding why we need to run a select query and THEN an update query. The select query is pulling all the records where the left or right id's match a particular value. Then, it increments the left or right values by one based upon the left or right id that matched. All of that logic can be done with a single query (at least for a single level). Just like in PHP you can create a condition statement and a true is interpreted as 1 and false as 0. This will replace the SELECT statement and the two associative UPDATE queries ,as well as the logic that goes with them. UPDATE binaries SET left_num = left_num + (left_id = '$psBinID'), right_num = right_num + (left_id = '$psBinID') WHERE left_id = '$psBinID' OR right_id = '$psBinID' Hmm . . . I guess you'd still have to do a SELECT query afterwards in order to get the ID of the records updated in order to get the child records though.
-
Here's a function I had lying around: //Function to determine a textual representation of the time between two events function time_since ($startTimeStr, $allUnits=false, $endTimeStr=false) { //Set start and end times in seconds $endTimeInt = (!$endTimeStr) ? time() : strtotime($endTimeStr); $startTimeInt = strtotime($startTimeStr); if($endTimeInt===false || $startTimeInt===false) { return false; } //Calculate the difference $timeDiff = $endTimeInt - $startTimeInt; //Get the difference in seconds $measurements = array ( 'year' => 31536000, 'month' => 2592000, 'week' => 604800, 'day' => 86400, 'hour' => 3600, 'minute' => 60, 'second' => 1 ); $returnValues; foreach ($measurements as $label => $measurement) { if ($timeDiff >= $measurement) { $units = floor($timeDiff/$measurement); $plural = ($units>1) ? 's' : ''; $returnString = $units . ' ' . $label . $plural; if(!$allUnits) { return $returnString; } $timeDiff -= $units * $measurement; $returnValues[] = $returnString; } } if(!count($returnValues)) { return false; } return implode(', ', $returnValues); } ## USAGE $postedDateTime = '2012-09-24 13:14:02'; echo 'This post was updated ' . time_since($postedDateTime) . ' ago'; // This post was updated 2 days ago echo '<br><br>This post was updated ' . time_since($postedDateTime, true) . ' ago'; // This post was updated 2 days, 19 minutes, 33 seconds ago
-
Correction to the code I provided. The value you want will be in $match[1]
-
Assuming that: 1. The only variability in the opening CODE tag is the number 3: The text in the CODE tags will always have two colons and you want everything up tot he first three characters after the 2nd colon preg_match("#\[code=auto:\d\]([^\:]*:[^\:]*:.{3})#is", $input, $match); echo $match[0];
-
Even with a DOM parser, I think you're still going to end up with the string he showed above. At that point, you need to find the text within [code=auto:0]13c5e209f938eb123026e88a96b628f70db8c792:746573:tescrack time: 7.39 ms[/code] Assuming those CODE tags are in the content and not a forum error, and If those "tags" are not variable (always the same), then you can use string functions to extract that text - otherwise RegEx is probably the solution.
-
You need to pay closer attention to your code. 1. Your query is malformed. $sql = "ELECT forum_id, forum_navn, FROM forum"; There should not be a comma after the last field (forum_nav) and the "FROM" keyword 2. To create code blocks, you use the curly braces, {}, not parent (). You are using parens to create the code blocks for the IF/ELSE conditions
-
Then the content should be put in a paragraph tag, <P>, and it should be styled with appropriate line height properties. Then the <BR> tag will generate the appropriate height. Using an empty <DIV> tag is very poor form. In fact, that could cause very different display on different browsers.
-
Yeah, why not just replace the double linebreaks in the source with a <br> tag (or two if needed)
-
Look at your SELECT query . . . $sql1="SELECT * FROM $tbl_name1 WHERE confirm_code ='$passkey'"; . . . and your DELETE query $sql3="DELETE FROM $tbl_name1 WHERE confirm_code = '$confirm_code'"; notice anything different?
-
What, exactly, are you trying to accomplish? It seems you are replacing linebreaks in the source and converting them to <br> tags - which causes a line break in the HTML content. But, it seems that is creating some undesired output. Looking at this sample output: I have a room available in my 2 bed flat in Ashgrove. The flat is in a quiet block of six units and is an older style flat so nice and roomy. The room is unfurnished, but I can source a bed if you need. There is great storage in the room with built in cupboards, and the room is large enough to fit a queen bed, chest of draws and bedside table. It seems that the source content has linebreaks that you don't want included in the output. We really need to see a sample of the actual source content and how you want it to be displayed to provide a good answer. Based on the above, I *think* the answer might to convert double linebreaks in the source to an HTML <BR> tag and leave the rest alone.
-
why radiobutton onclick function is not working?
Psycho replied to masnobi's topic in Javascript Help
Somewhat off topic, it's not clear from the sample code provided, but are you using a single radio button or doe the page actually have multiple options? If you only have one option, then you should be using a checkbox, not a radio button "group". More on topic, you should really dissociate the JavaScript code from the triggers.Your trigger should just call a function or, even better, use a framework like JQuery to dynamically set the trigger. Putting all that "logic" in your HTML code makes it difficult to debug and maintain your code. Also, you define the onclick trigger using single quotes and then you defined the message for the alert within single quotes. That will cause an error because the JavaScript parser will interpret the start of the alert message as the end of the onclick trigger definition. You need to use single quotes for one and double quotes for the other (or properly escape one set).- 3 replies
-
- php
- radiobutton
-
(and 2 more)
Tagged with:
-
How to Prevent While Loop from Affecting Last DB Result
Psycho replied to sandbox's topic in PHP Coding Help
There are two (well, three actuall) methods I can think of: 1. Don't echo the values to the page directly. Instead append the text to a variable. Then when the loop completes, use substr() to remove the last three characters from the variable before echoing to the page. 2. Create the code for the individual links as elements in an array - then implode the results using the delimiter of " | ". 3. The third solution is to use GROUP_CONCAT in the query to return the results as a single concatenated value. But, you would also have to use string functions to have the query automatically generate the HTML code. That's possible, but it's not a good idea to hard-code presentation logic into your DB queries. So, while this is possible, probably not a good idea. I prefer #2 <?php $sql = "SELECT * FROM `navigation` ORDER BY position ASC"; $qry = mysql_query($sql); confirm_query($qry); $links = array(); while ($res = mysql_fetch_array($qry)) { $links[] = "<a href=\"{$res['url']}\">{$res['page']}</a>"; } echo implode(" | ", $links); ?> -
Also, why are you storing the item description in the invoice table. You should be able to get that info from the item table using the item ID. And, the same goes for the item line total. You are already storing the quantity and item price - no need to store the total.
-
Use a for() loop: http://php.net/manual/en/control-structures.for.php
-
Exists clauses in where is taking 60+ seconds to run
Psycho replied to cs.punk's topic in MySQL Help
First, you would do yourself, and others, a huge favor by formatting your queries in your code for readability. A little extra whitespace characters would have no performance degredation but you will gain much in the way of debugging your code. SELECT * FROM accommodation INNER JOIN address ON accommodation.address_id = address.address_id INNER JOIN country ON address.country_id = country.country_id INNER JOIN establishments ON accommodation.accommodation_id = establishments.child_id INNER JOIN person ON establishments.person_id = person.person_id LEFT JOIN establishment_attribute AS attr1 ON attr1.establishment_id = accommodation.accommodation_id AND WHERE ( EXISTS ( SELECT 1 FROM establishment_attribute WHERE establishment_id = accommodation.accommodation_id AND attribute_id = 11 ) OR EXISTS ( SELECT 1 from establishment_attribute WHERE establishment_id = accommodation.accommodation_id AND attribute_id = 13 ) OR EXISTS ( SELECT 1 from establishment_attribute WHERE establishment_id = accommodation.accommodation_id AND attribute_id = 12 ) ) AND ( EXISTS ( SELECT 1 from establishment_attribute WHERE establishment_id = accommodation.accommodation_id AND attribute_id = 139 ) ) Second, those first three EXISTS subqueries could be replaced with 1 queries using an IN condition for the three attribute_id values AND attribute_id IN (11, 12, 13) Third, Don't use '*' in your SELECT statement if you don't really need all the data. I highly doubt you need every field from all those joined tables. Fourth, You can still do a JOIN and also a GROUP BY to prevent duplicates. Running subqueries when not needed is a bad idea. I like to have test data when constructing involved queries, so I can't verify this is what you need, but I think so SELECT * FROM accommodation INNER JOIN address ON accommodation.address_id = address.address_id INNER JOIN country ON address.country_id = country.country_id INNER JOIN establishments ON accommodation.accommodation_id = establishments.child_id INNER JOIN person ON establishments.person_id = person.person_id LEFT JOIN establishment_attribute AS attr1 ON attr1.establishment_id = accommodation.accommodation_id AND attr1.attribute_id IN (11, 12, 13) LEFT JOIN establishment_attribute AS attr2 ON attr2.establishment_id = accommodation.accommodation_id AND attr1.attribute_id = 139 GROUP BY attr1.establishment_id, attr2.establishment_id WHERE attr1.establishment_id NOT NULL AND attr2.establishment_id NOT NULL -
confused... not sure how to go about this. do not echo if same.
Psycho replied to loren646's topic in PHP Coding Help
Assuming you are getting this from a DB query - you should handle the logic int he query to only return unique values. But, you also probably have a problem with your database design. Your "supervisors" should be listed in a separate table. Then your records for the buildings should have a foreign key to reference back to the respective supervisors One way with the current table structure you probably have SELECT DISTINCT supervisor FROM buildings -
Not nearly enough information to provide any help. What I see is two arrays that are created (given the extraordinarily intuitive names of $arr_val1 and $arr_val2) which are populated with the 'quantity' and 'amount' of each record from an apparent database query. There is also a "flag" variable, $is_handeling, which is set to 1 if there were any records in the result set. What happens after that is impossible to determine. Perhaps the code to actually calculate the handling isn't checking the contents or number of items in the array and is only checking the $is_handeling variable.
-
How to do Multiple Condition in SQL query using PHP and Ajax
Psycho replied to vishalonne's topic in PHP Coding Help
I don't know, can you? -
How to do Multiple Condition in SQL query using PHP and Ajax
Psycho replied to vishalonne's topic in PHP Coding Help
As long as you are going to treat all of the conditions as AND or OR conditions (which it correct based on your examples), it's simple. All of the fields are going to be passed in the POST data, so you need to just ignore the ones that are blank. Then create conditions for the ones which are not blank and then concatenate them with AND conditions. This assumes that the "default" options for the select lists have an empty value. Here is some sample code using just four fields as an example //Preprocess the post data $branch = isset($_POST['branch']) ? trim($_POST['branch']) : ''; $year = isset($_POST['year']) ? trim($_POST['year']) : ''; $course = isset($_POST['course']) ? trim($_POST['bcourse']) : ''; $class = isset($_POST['class']) ? trim($_POST['class']) : ''; //Determine WHERE conditions $where = array(); if(!empty($branch)) { $where[] = "branch = '$branch'"; } if(!empty($year)) { $where[] = "year = '$year'"; } if(!empty($course)) { $where[] = "course = '$course'"; } if(!empty($class)) { $where[] = "class = '$class'"; } //Create query - concatenating all the WHERE clauses $query = "SELECT * FROM table_name WHERE " . implode(' AND ', $where); -
How to combine date and time in one mysql query
Psycho replied to shebbycs's topic in PHP Coding Help
Barely. You can try and concatenate a bunch of different variables inside the query for a single field value. But, that's a poor process in my opinion. I would suggest you concatenate the variables outside the query as the complete value and then use that inside the query. And, anyways, what you have will not work. You use the period to concatenate string in PHP. But, you have two variables inside a quoted string - so the period would be interpreted as a literal character of the period. $sql = mysql_query("INSERT INTO task_report (ID,DATE) VALUES ('ID','$DATE.$TIME')") If $DATE = '2013-04-08' and $TIME = '2:45 pm' the quwery would end up as INSERT INTO task_report (ID,DATE) VALUES ('ID','2013-04-08.2:45 pm') 1) You need a space between the date and time 2) The period is out of place 3) '2:45 pm' is not a valid time. You will need to convert any PM time to be +12 hours Example code $date = date('Y-m-d'); $hour = ($_POST['period']=='pm') ? intval($_POST['hour']+12) : intval($_POST['hour']); $minutes = intval($_POST['minutes']); $datetime = sprintf("%s %2d:%2d:00", $date, $hour, $minutes); $query = "INSERT INTO task_report (ID,DATE) VALUES ('ID','$datetime')"; $sql = mysql_query($query); -
Seriously?! Learning to do something is not about simply storing a bunch of facts that you regurgitate back. You need to understand WHY something is the best approach. Did you ever bother to ask why you should verify why someone is on the same browser as they registered on? There are some security concerns with verifying someone is on the same PC as the one they registered on and giving them a way to register a new PC, this probably isn't one of them
-
Run this query first. If the count is not 0 then don't insert SELECT COUNT(*) FROM `friendships` WHERE (`sender` = $senderID AND `recipient` = $recipientID) OR (`sender` = $recipientID AND `recipient` = $senderID)