
Psycho
Moderators-
Posts
12,160 -
Joined
-
Last visited
-
Days Won
130
Everything posted by Psycho
-
how to search only letters and numbers in tables
Psycho replied to jason310771's topic in MySQL Help
Look into FULL-TEXT searching. It allows you to search for matches that are 'similar' but don't have to be exact matches and it supplies a match quotient as to how close the match is. -
+1 for the use of the word "tomfoolery".
-
Well, let's start at the beginning. Where is the data coming from?
-
Put a form with a button on whatever page you want: <form action='deleteLog.php' method="POST"> <input type="submit" value="Delete Log"> </form> deleteLog.php file <?php unlink('logs.html'); ?> Of course that would have absolutely no security and request to deleteLog.php will delete the file.
-
Can you please share the site that you are working on? I want to make sure to never visit it. You state there is a dev/test environment but that you would have to clone the whole site and database. If there is a dev/test environment then doesn't it already have the code and DB for the site?. Otherwise the dev/test environment isn't serving it's purpose. Well, actually you need several such environments - including a stage environment. My company has very strict rules about code progression to production as well as a full auditing system for code check-in and test sign off. Every once in a while someone says there is a 'simple' fix with little to no regression risk that has to get put out without going through the process. More often then not it causes more problems than it was supposed to resolve. FYI: You should NEVER clone production data to your test environments - big no, no. The code is fine, but the database should not. There needs to be processes in place so that the access to the production database is limited to only those individuals that must have it. If data is needed from production,troubleshooting for example, then the specific data should be retrieved w/o any user personal information. Or, if that information is needed, there must be an audit process.
-
Having duplicate code in a method for expiration date dropdown
Psycho replied to eldan88's topic in PHP Coding Help
Never duplicate code - I don't care how compact it is. The primary reason is maintainability. If you ever need to make a change to how the duplicative functionality works, you have to go find all instances and update them. Or, if a bug is found you only have one place to fix the bug for all places where it would be. Otherwise, you may only fix it in the one place the bug was discovered and it would exist elsewhere. In this case, more code is a good thing. As to this specific example, I typically create a function specifically for creating select options that I use for all the select fields on a site. For example, I see a flaw with what you have above in that if there is an error in the form you should reload the form and make the previously selected values 'sticky'. There is no logic in the above to accomplish that. Also, I would not put the actual <select> tags in the function. Instead, those should be included in the presentation code (i.e. HTML). Make the code reusable! Example: <?php public function createOptions($optionList, $selectedValue=false) { $options = ''; foreach($optionList as $value => $label) { $selected = ($selectedValue==$value) ? ' selected="selected"' : ''; $options = "<option value='{$value}'{$selected}>{$label}</option>\n";; } return $options; } public function month_options($selectedMonth=false) { //Create a list of select options for month $months = array(); for($month = 1; $month <= 12; $month++ ) { $months[$month] = date("M", mktime(0, 0, 0, $month, 1, 2000)); } return createOptions($months, ($selectedMonth); } public function year_options($selectedYear=false, $count) { //Create a list of select options for year $years = array(); $this_year = date("y"); for($i = 0; $i <= $count; $i++) { $years[$this_year + $i] = $this_year + $i; } return createOptions($years, $selectedYear); } ?> <select name="exp_month"> <?php echo month_options($_POST['exp_month']); ?> </select> <select name="exp_year"> <?php echo year_options($_POST['exp_month'], 15); ?> </select> -
What do you mean "The method you've suggested posts echo's out all results one after another". You asked for a way to put the results of the query into an array and that was what I provided. If you are talking about my comment Then one of us is failing to understand (hint: it's not me). Whether you output the results while retrieving the records from the query result or if you output then from an array makes absolutely no difference. There are valid reasons to drop results from a query into an array, but the reason you are supposing is not one of them. See adam's example above.
-
You could just create the output when you retrieve the records from the database result - no need to create an array as that only adds overhead. But, it is simple enough $query = "SELECT * FROM table"; $result = mysql_query($query); $dataArray = array(); while($row = mysql_fetch_assoc($result)) { $dataArray[] = $row; }
-
There's definitely something wrong with that query. But, to be honest, I don't understand much of it: (('month',CURRENT_DATE) + CAST(FLOOR(s.idx / 5) || ' day' as interval))::DATE AS data, I have no clue what that is trying to retrieve. For example, what is ('month',CURRENT_DATE) supposed to do? I'm thinking you are missing a MySQL function for that parenthesized section. Also, the ::DATE is something I've never seen before. 'descricao' as descricao, No need to alias something as the same name it already is. CASE WHEN random() < 0.5 THEN ROUND(150 + (random()*100)::numeric,2) ELSE ROUND(150 + (random()*100)::numeric,2) * -1 END as valor I don't use CASE statements in MySQL very often, so I can't say if that syntax is correct. But, a CASE statement should be used when you have many options. For that, I would just use an IF() statement. But, regardless of which one you use I see a problem. You are using random() as part of the condition and then use it within the value. I am pretty sure that each instance of random() will be different. For example, you are using a "* -1" if the first random() is less than .5, but the random()'s used in the calculation can be different values entirely. I'm guessing there is a better way to accomplish that so the random() value for each record will be the same random. But, one solution I can think of is to create a temporary table with a single random value for each record. Then run a second query to do the calculations. FROM lc_movimento(1,24) as s(idx) I have no idea what the (idx) is for
-
You do realize that there is not one format for how things are displayed in an "online shop", don't you? You have an idea in your head on how you want the output to be, but you are using generalized terms to explain it to us. I've seen many, many different ways that items are displayed on shopping sites - and some do use a simple table display. Perhaps if you were to link to a site with a similar format that you want to use. But, if that was the case you could inspect the HTML source yourself to see how they accomplish it. But, if I think what you want is correct, yes DIVs is the way to go. But, there are still other considerations that you have to decide before we could even propose something. For example, do you want the number of items per row to be fixed or would you want the number of items per row to increase/decrease as the window size is expanded/reduced by the user? If you want the former, then enclose the X numebr of product DIVs in a parent div. <div class="product_row"> <div class="product">Details of product go here</div> <div class="product">Details of product go here</div> <div class="product">Details of product go here</div> <div class="product">Details of product go here</div> </div> <div class="product_row"> <div class="product">Details of product go here</div> <div class="product">Details of product go here</div> <div class="product">Details of product go here</div> <div class="product">Details of product go here</div> </div> If you don't want a fixed number of products for each row don't use the "product_row" divs. Then, whichever format you use, you will need to create CSS classes for the divs used to define the style properties. For example the 'product' divs will have a specified height and width, maybe certain colors, etc. etc. Then, inside each product div you will include all the details about the product you want displayed: image, name, description, price, buy button, etc., etc. So, one product dive might look like this <div class="product"> <img src="image.jpg" class="prod_img" /> <div class="title">Title of product</div> <div class="description">Description of product</div> <div class="price">$15.00</div> <div class="buy"><a href="buy.php?id=12">Buy</a></div> </div> You then need to define the classes and properties for all those elements. To do that you need to understand CSS and all the relevant properties you need to use. If you don't know CSS you will need to do some research. Since this is NOT a PHP issue, I am moving this thread to the CSS forum.
-
To expand on mac_gyver's response: It is impossible to display an image on a web page and to protect it from someone who want to have a copy of it. First off, if an image is displayed to a user in a web page, it has already been downloaded to their computer. That is how it works. The image is sitting their in the user's cache. Many users may not know where the cache is or how to access it, but the reality is that it is already there. I see some sites go to great lengths in trying to prevent users from copying images. In some cases those measures actually cause more problems than the one they are trying to solve. A couple examples: JavaScript to prevent right-clicking so the user can't do a "Save as" on the image. OK, but that also prevents the user from using the other features in the context menu that they should be able to use. This behavior only pisses me off. Plus, users could simply disable JavaScript Putting a transparent image on top of the 'protected' image. This is done so when the user tries to copy the image they are really only copying the transparent image on top. This can cause problems with page layouts because of the idiosyncrasies between web browsers with the more complicated positioning and layering used to accomplish this - especially with smart phones and tablets. Plus, a user can simply do a screen capture to get the image. What should you do (in my opinion). 1. Watermark the images. That way someone can't reuse your images without people knowing they copied it from someone. 2. Prevent hot-linking to your images. The watermark really makes this less about protecting the image than about not letting someone to use your bandwidth. In other words, if someone has already decided to use your image on their site, preventing the hot-linking will require them to copy it and host it themselves instead of just including an image tag on their site pointing to your server. So, to reiterate, you cannot prevent someone from copying the images if you are going to make it available on the internet - period. All you can do is make it marginally harder. But, even doing those things adds a lot more work and complexity that really doesn't accomplish anything because it would take someone with just a little knowledge no more than a couple seconds to still get the image.
-
So, your problem is solved? Don't know why you marked it as such. Thanks for the additional info, but I still don't see an explanation for the duplication of the data in the tables. I have never seen two tables that are joined by two separate columns. Not saying that wouldn't necessarily be valid, but it doesn't seem so in this case and it is creating a much more complicated configuration. For example, you have 'term' located in a lot of these tables. That doesn't make sense. You should have a record when a student registers for a course that has a reference to the course and the term that they registered for. The billing table should only include a reference to the table that holds the registration record and NOT include a reference to the term since that can be derived from the registration info. I would love to help, but the configuration of the tables is making this more complicated than I am willing to invest time into. I suggest you review some tutorials on Database Normalization if you want to clean up the database schema.
-
Can you explain in lay terms what you are trying to accomplish? And can you explain the purpose for each table (e.g. bill vs. billing_table)? I think there are some problems with your database schema. For example, why do you need two columns to JOIN some of the tables? FROM bill a LEFT JOIN student_fee b ON a.stuID = b.stuID AND a.ID = b.billID I would think that the student ID only needs to exist in one of those tables - not both - and that they could be JOINed using just the bill ID. Can multiple students be associated with the same bill record? Definitely seems you have duplicated data throughout your tables making this more complicated than it needs to be. FYI: I'll also add that using aliases in a query (i.e. LEFT JOIN student_fee b) is there to add clarity. Using values like a, b, c, d, etc. only makes it harder.
-
Basic Loop and Itterational Variable Question!
Psycho replied to laraggg111's topic in PHP Coding Help
Hmm . . . not homework you say? Then what? Did you just pick some code out of the air and write yourself a requirement to ? Where exactly did you find the challenge? I'm not accusing you of anything and am happy to help, but I do not appreciate people coming here wanting their homework to be done without actually learning. Or worse, someone trying to get help with an employment evaluation assignment. Again, I would advise figuring out the math first. Look at what is being produced and decide how you would approach it mathematically. You have three loops, each one repeats 0 - 5. The outer loop repeats 0-5 one time. The first inner loop repeats 0-5 six times. And the most inner loop repeats 0-5 36 times (6 for the outer loop time 6 for the first inner loop). So, the outer loop is executed a total of 6 times, the first inner loop 36 times (6 * 6) and the most inner loop 216 times (6 * 6 * 6). That would be your first clues on how to approach this. The other clue I will provide is to use the modulus operator. FYI: I already solved this before I responded to your first post. If you were to actually post some code showing you made an attempt or asked some specific questions I would provide more help. But, as of yet, you haven't showed any effort to trying to solve it yourself. Maybe you have done quite a bit and just haven't shared it. As I said, I won't just provide a solution for something that looks like homework - even if you say it isn't. EDIT: I did some searching and see where this exact problem had been posted other places at least a year ago and there was one search result that linked back to the Careers page for a firm that has PHP developer positions. Again, not accusing, but I don't think you're telling the whole truth. I'm interested in seeing what you come up with. -
Don't take things so personal. I did say I said that for a reason. I help a lot of people on these forums and I'm not going to waste my time trying to phrase things to not hurt peoples feelings. If I see a problem I will call it out. I will also call out something that the OP could have discovered themselves. For example, you state that you're not a PHP coder so it seemed reasonable. I don't follow that logic. If I am doing something I am not familiar with I will look at the documentation to see if I am doing it right. So, I called out the fact that simply looking at the manual for those two functions should have let you know right away that was not the way to accomplish what you wanted. The PHP manual is an excellent resource that I use all the time. I don't memorize every parameter and expected result. As to your problem, I did provide a solution: use PHPMailer. It is a free class that makes sending emails much easier than trying to roll your own code. You can get it here: http://sourceforge.net/projects/phpmailer/ Attachments can be tricky and error prone. However, if you really feel like trying to code it yourself, along with having to debug it, then take a look at this page: http://webcheatsheet.com/php/send_email_text_html_attachment.php#attachment Also, here is a forum post on another site with comments and example code both with using PHPMailer and with built-in PHP functions: http://stackoverflow.com/questions/12301358/send-attachments-with-php-mail
-
And, why would you think that? Did you verify what $result contains? Sorry, if I'm being a little rude, but if you had done even a modicum of due diligence you would have seen the fallacy of that assumption. 1) In the code $result is defined by the returned value of file_put_contents. If you had looked at that function in the manual you would see that the return value is So, I don't see how you would think that a number would be displayed as a picture. 2) You are then using $result in the mail function here: mail("$formatted_number", "SMS", "$message", "$result"); The fourth parameter is for additional headers of the email - not for including attachments. You should probably look into something like PHPMailer instead of trying to code it yourself.
-
So, does the "No" above mean you don't see the employee IDs in the database as you would expect? If so, then that would definitely be why using the other employee IDs is not generating the result you want. And, why the hell would you need a 300 character field for employee IDs?
-
I have no idea. I am unfamiliar with the oci_ functions and what would be expected as return values. Have you added code to debug the problem and, if so, what were the results? For example, are you getting a value displayed for $numrows? Did you look at the HTML source code to see if any of the code for the options is there? I'm not 100% certain, but I think this may be invalid code while ($row = oci_fetch_array($paint_parse)!= false) I would wrap the assignment portion within parens to ensure the order of operations is as I would expect. while (($row = oci_fetch_array($paint_parse))!= false)
-
Basic Loop and Itterational Variable Question!
Psycho replied to laraggg111's topic in PHP Coding Help
I assume it is homework. So, rather than just giving you the answer why don't you explain what you have tried or what you think may be the right approach. We like to see people at least put forth the effort when asking for help with homework. But, I will offer the following. This is more about a math problem than it is a programming problem. You do need to know how to implement the coding to implement the math solution, but you must first understand the math. A very large portion of programming involves mathematics and logic. Just knowing the functions is a small portion of being able to program. So, pull out a sheet of paper and determine a mathematical formula to solve the problem. -
I ran a test using the following query that worked. I will defer to Barand that this may not be the preferred approach, but it worked for me. UPDATE wp_postmeta AS wp1 JOIN wp_postmeta AS wp2 ON wp1.post_id = wp2.post_id AND wp1.meta_key = '_sale_price' AND wp2.meta_key = '_regular_price' SET wp1.meta_value = IF(NOT wp1.meta_value, wp2.meta_value, wp1.meta_value) However, this would not resolve the problem of a scenario where a _sale_price record does not currently exist for a specific post_id where a _regular_price record does exist. You could run an INSERT query first to add those missing records if you need them.
-
I would ask why you are storing the data like that rather than separate columns for price, regular_price, sale_price, etc. but I will assume you are using some pre-built application and that is the only way for you to add additional details that were not supported by the app. But, if this is not the case, then you should definitely fix the table. OK, I will also assume that this will be a one-time operation. Therefore, I am not going to try and figure out the most efficient solution, but instead focus on getting a working solution. You don't state if _sale_price and _regular_price exist for all unique post_id's. Your example data above seems to indicate that they may not. So, if _regular_price does not exists do you need to INSERT a record for it?
-
What type of field is the empid in the database? Are the letter values there?
-
Why do you need an ID property for the option tags? It is not sent in the form data. Do you have additional JavaScript that uses the ID's of the options for something? If you really need it - add it back.
-
I can't tell what you are trying to do based upon your "explanation" or from the code you have provided.
-
If you were to look at the HTML source code that is created from the above it would become obvious what the problem is. The options are getting created something like this <option value="Bob Smith>"Bob Smith</option> Note the closing double quote and '>' at the end of the opening OPTION tag. This is why I use double quotes to define my strings and put the variables inside the string instead of concatenating them - it makes it easier to see what the output would be. Also, you should be using the employee_id as the VALUE of the options and the name as the label/text. Plus, I don't know why you would order the values based on the ID since that would not be of any value to the user. Lastly, it's best to put the logic (i.e. PHP at the top of the page [or in a separate file]) and then only output the results in the HTML code. Makes it much easier to maintain. <?php ## All of this code should be in the top of the script, not in the output of the page. // Connect to the db. require ('mysqli_connect.php'); // Create and run the query: $query = "SELECT employee_id, employee_name FROM employee WHERE dept_id=3 ORDER BY employee_name ASC"; $result = mysqli_query ($dbc, $query); if(!$result) { //Query failed - add some error handling here } else { //Create the options for the select list $staffOptions = ''; while ($row = mysqli_fetch_array($result)) { $staffOptions .= "<option value='{$row['employee_id']}'>{$row['employee_name']}</option>\n"; } } mysqli_free_result ($r); // Free up the resources. mysqli_close($dbc); // Close the database connection. ?> <!-- this goes down in the HTML code for your page --> <select name="employee_name"> <?php echo $staffOptions; ?> </select>