Jump to content

Psycho

Moderators
  • Posts

    12,146
  • Joined

  • Last visited

  • Days Won

    127

Everything posted by Psycho

  1. You didn't state whether all clients have at least one object and, if they don't, whether you want clients without any objects to be displayed. If all clients have objects OR if you don't want to show ones that don't ahve any objects, remove the "LEFT" part of the JOIN. This is just an example since I don't know your table structure. It will get one object for each client based on the object with the lowest ID. This would select only the first object SELECT * FROM clients LEFT JOIN objects ON clients.client_id = objects.client_id AND objects.object_id IN ( SELECT MIN(object_id) FROM objects GROUP BY client_id )
  2. Well, that code works for me. I don't work with images much. I just took the example code from the manual and then made one change after another to meet the intent of your original code. That's what I was expecting you would do. If you are getting a broken image, then an error is occurring, but because the header is forcing the output to be an image you see a broken image. Comment out the following line to see the errors header('Content-Type: image/jpg'); Are you sure the two directories where you are trying to save the photos exist where you think they do? Also, your comments above still don't explain why you need to save two instances of the photo. makes no sense. Just create one file.
  3. Do "what" exactly with JQuery? You could superimpose text on top of an image using CSS (no JavaScript involved). Or, if you are talking about using JQuery to perform AJAX calls to PHP, yes. But, not knowing how you want to use it, I can't give you any input. I will say this, however: I don't see why you are creating the image, writing it to two different places and then also outputting it directly to the browser. It would make more sense to me to write the image ONCE to the file system and then have a normal IMG tag for displaying it. <?php if (isset($_GET['image'])) { ## Hard coded values $images_folder = ''; $font_path = '../fonts/Timeless-Bold.ttf'; $font_size = 10; $top_margin = 50; $bottom_margin = 50; $photo_directory = '../photos/'; $upload_directory = '../useruploadedphotos/'; #Variable values $image_name = $_GET['image']; $topcaption = $_GET['topcaption']; $bottomcaption = $_GET['bottomcaption']; $image_path = "{$images_folder}{$image_name}"; //Create image resource from source image $imageRes = imagecreatefromjpeg($image_path); //Determine the image hieght & width $image_x = imagesx($imageRes); $image_y = imagesy($imageRes); //Create color identifier for the text $black = imagecolorallocate($imageRes, 0, 0, 0); //Create bounding box for the top caption $bbox = imagettfbbox($font_size, 0, $font_path, $topcaption); //Calculate cordinates for X and Y of top caption $x = $bbox[0] + (($image_x-$bbox[4]) / 2); $y = $top_margin - $bbox[5]; //Write top caption to image imagettftext($imageRes, $font_size, 0, $x, $y, $black, $font_path, $topcaption); //Create bounding box for the bottom caption $bbox = imagettfbbox($font_size, 0, $font_path, $bottomcaption); //print_r($bbox); //Calculate cordinates for X and Y of bottom caption $x = $bbox[0] + (($image_x-$bbox[4]) / 2); $y = $image_y - $bottom_margin; //Write bottom caption to image imagettftext($imageRes, $font_size, 0, $x, $y, $black, $font_path, $bottomcaption); //Write image to file system imagejpeg($jpg_image, "{$photo_directory}{$image_name}"); imagejpeg($jpg_image, "{$upload_directory}{$image_name}"); //Output to browser header('Content-Type: image/jpg'); imagejpeg($imageRes); imagedestroy($imageRes); // header("location: success.php"); } ?>
  4. So, where is the modified code you've made and where is the problem you are now facing?
  5. Did you look at the code in the manual?
  6. You'll also need to use imagettfbbox() first. That function will give you the bounding box size. From that you can calculate where to put the text so it will be centered. Look at the example code for that function.
  7. What do you mean they are "linked from another table". Are you saying the image you provided is the result of a query with a JOIN? You'll need to provide the data from the relevant tables and the query you are using if we are to understand the details.
  8. Perhaps all of the values have a line break at the beginning?
  9. I stand corrected. I could have sworn it did not do that.
  10. EDIT: NEVER put user entered data into a query (unless you are using prepared statements). In this case you can use intval() on the value $id = intval($_GET['data']); $statement = "SELECT * FROM table1 WHERE id={$id}"; As to your issue, MySQL does not return NULL for a NULL field. Just check if the value is not empty. Plus, there are no quotes around the value if (!empty($row['img'])) { echo "<img src=\"{$row['img']}\">"; }
  11. Works for me on my FTP server. Are you getting any output for the var_dump()? You should get a Boolean false if the function is failing.
  12. Did you turn on error reporting? If not, turn it on. If so, what errors are you receiving? Heck, you may be using the commands wrong for all we know, but since you failed to provide a single line of code we would only be guessing.
  13. $value = (isset($_POST['hidden'])); $querys = "SELECT * FROM kommentarer where img_id = $value"; $value is being set to a Boolean (i.e. True/False) not to the value passed in the hidden field. That is probably the source of your problem. Try $value = isset($_POST['hidden']) ? intval($_POST['hidden']) : 0;
  14. Did you consider asking the author of that API?
  15. That is so the "label" of the options will be "Jan", "Feb", "Mar", etc. but the values for the options will still be 1, 2, 3, . . . Because the function to create options uses the INDEX of the array as the value and the VALUE of the array as the label. The function can be used to create options for any select list. Say you have a list of users in your database, you would use the UserID as the value and the User's name as the text/label. Seriously? I don't think you looked at the sample code very well. Those two functions will call the createOptions() function as I showed. I also showed how you would actually implement the functions in the HTML code.
  16. You are looking at it completely wrong. A database is not meant ot be viewed directly. Anything you use to "look" at the database is simply doing a query and outputting the data in some format. You know, you can store whole images in your database, but you aren't going to "see" an image if you were to inspect the contents. You would just see a string of random characters. It is when you retrieve the content and format it back as an image that it would be viewable as an image. Stop thinking of the database as an Excel document. As for storing data you simply choose the appropriate field type. For something that can be a very long article you would use the BLOB or TEXT types. http://dev.mysql.com/doc/refman/5.0/en/blob.html
  17. So the PHP code just spontaneously generates data? Let's start again. I *think* you are having the data submitted via a form by the user. OK, instead of taking that data, creating HTML and writing to a file you should instead save it to a database. It can be a little intimidating to get started but, honestly, once you start using a database that is when things get fun (at least I think so). You just have individual records, so you would only need one table. I can't really go over everything that you need to do to get started in a forum post, so go find a tutorial. But, I'll provide some basics for you based upon what I see above. First, you will create a table with the following fields: id: This will be an INT type field set to be auto-incremented. You will not need to set it as it will be set automatically. You will use this field to reference the records. date: this should be a timestamp field with a default value of NOW(). This way you never have to actually set it - it will be done automatically when you create the record referrer: This will be a varchar with a length big enough to hold whatever the longest value may be ip: This will be a varchar with a length of 15 characters account: This will be a varchar with a length big enough to hold whatever the longest value may be password: This will be a varchar with a length big enough to hold whatever the longest value may be Once the DB is set up you can then process a form post to insert the record into the database as follows. Note: the mysql_ functions have been deprecated, but I know them without having to check syntax. You'll want to use the mysqli_ functions instead. Just check the manual to check the differences mysql_connect('DB_URL', 'DB_UserName', 'DB_PassWord'); mysql_select_db('name_of_database'); $referrer = $_SERVER['HTTP_REFERER']; $ip = $_SERVER['REMOTE_ADDR']; $account= mysql_real_escape_string($_POST['name']); $password= mysql_real_escape_string($_POST['pass']); $query = "INSERT INTO table_name (referrer, ip, account, password) VALUES ('$referrer', '$ip', '$account', '$password')"; $result = mysql_query($query); That's just very, very basic code, but should get you started.
  18. 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.
  19. +1 for the use of the word "tomfoolery".
  20. Well, let's start at the beginning. Where is the data coming from?
  21. 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.
  22. 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.
  23. 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>
  24. 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.
  25. 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; }
×
×
  • 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.