Jump to content

1internet

Members
  • Posts

    136
  • Joined

  • Last visited

Everything posted by 1internet

  1. Ok, what if we just keep the query as: "SELECT * FROM `hotels` WHERE `city`='$city $search' AND `name` LIKE '%$search%' ORDER BY `name`" Then if $search is not set, then it will = '', and all queries will match that search. Is that a good way?
  2. concatenating is a nice idea, but I also need ORDER BY too, so I won't be able to concatenate that to the query.
  3. So I have a results page, e.g. a list of all the hotels for a specific city coming from the database: "SELECT * FROM `hotels` WHERE `city`='$city'" I want to also include a search form. They way I have tried, and assume would be the standard way is: if(isset($_GET['search'])) { $search = $_GET['search']; $search = "AND `name` LIKE '%$search%'"; } else { $search = ''; } So it checks if the search has been set, and if it has it then creates the msql code for it. I then adjust the sql query like so: "SELECT * FROM `hotels` WHERE `city`='$city $search'" 1. The search variable is not creating the correct sql result, so I think I may have done something wrong there. 2. Is this the usual way a search is added into the sql results? Would it be better to have" if(isset($_GET['search'])) { $search = $_GET['search']; $qry = ""SELECT * FROM `hotels` WHERE `city`='$city $search'" AND `name` LIKE '%$search%'"; } else { $qry = "SELECT * FROM `hotels` WHERE `city`='$city $search'"; } Or is there an even better way?
  4. I understand WHERE statments, but I just don't know what the query would be if I wanted to search multiple fields. WHERE `firstName` LIKE '%".$searchFirstName."%, but what if I wanted to search other fields, and how do I priortize one over the other, without duplicate entries?
  5. I am trying to create a search form with one field that will search through one table, but through all the columns. I just can't seem to work it out. Also is there some way to prioritize the results, e.g. if the keyword is in the title then rank it above the results that have the keyword in the description?
  6. right, thats what I thought. Thanks
  7. Right, I was thinking it would be something like that, is this standard practice what everyone does? It won't work on the local server though will it?
  8. So my site has a template, and each page plugs into it. But the pages are made dynamically, and some have directories, e.g. /directory/page, /directory2/page2, /directory2/sub-directory2/page3, etc. If I want to include my template so the include function will display the template for every page, no matter how large the directory, how should it be coded? I thought if I had include '/template.php' , then it would be the same as mydomain.com/template.php and work on every level, but this doesn't appear to be the case.
  9. I currently dont use a redirect for the errors, if there are no errors it redirects to another page, but if there errors it will remain on the same page from the form action="", with the $errors loaded in the array and displayed to the user. Is this approach acceptable?
  10. Thanks Russel, what if I don't use the same page as the recipient, or when I do, the form is no longer shown?
  11. So if I have multiple forms performing different functions on the same page, is it best to put all the php code at the top of the page before I declare the doctype? Oppossed to the php code above each form? Is this considered best practice? Is this also what prevents the header already assigned errors that need to be corrected with the ob_start, etc functions?
  12. Ok, I am beginning to think this impossible, but people do it, so there must be a way. I have a blog, and want to have the option to add the blog to multiple categories, through multiple select box. I have created a new table to match each blog id with the corresponding category ids. Now when I try to create a new blog, and add the categories to the database I can't work out how to, because I don't know the id of the blog as it doesn't have one until it is created. What am I doing wrong?
  13. So if you have a form, that also has an image upload facility, but on submit there are some errors so the form doesn't submit, but holds all the values that were there before submission - how can you hold the image value. i.e. do you have to always upload the image again? At least without the use of ajax.
  14. Sorry, I thought I hard worked it out, but after more and more thorough testing, I think I would rather bang my head against the wall!!! So how do you add multiple options to a database? What are the proper methods for sanitization, etc?
  15. I am trying to add multple selections from a drop down box to a mysql database. The user makes multple selections, and they become an array, then I implode the array to a string and add it to the database. But also if the page has an error, I want to keep those selection values there when the page refreshes. Here is my my form: <select name="category[]" multiple="multiple"> <option disabled <?php if($category == 0) {echo 'selected="selected"';} ?> value="select">Select a Category</option> <option disabled >-------------------------------</option> <?php $cateogry = is_array($category) ? $category : explode(',',$category); $categoryResult = mysql_query("SELECT * FROM `blog_categories` ORDER BY name", $connect); while($categoryRow = mysql_fetch_assoc($categoryResult)){ $categoryId = $categoryRow['id']; $categoryName = $categoryRow['name']; if ($id != $categoryId) { ?> <option value="<?php echo $categoryRow['id']; ?>" <?php if (in_array($categoryId, $category)) echo 'selected="selected"';?>><?php echo $categoryName; ?></option> <?php }} ?> </select> And here is the code for adding to the database, I run it through the foreach loop to sanitize it, I then implode it to a string and add it to the database: if(isset($_POST['submitPage'])) { $category = $_POST['category']; foreach ($category as $cat) { $cat = (int)($cat); $category[] = $cat; } if($category == 0) { $error[] = 'Please select a category'; } $category = implode(',', $category); if(count($error) == 0) { $addResult = mysql_query("INSERT INTO `blog`(`category`) VALUES ('$category')", $connect); } I have been testing lots of different variations, and searching how this is done, but I just can't work it out. Also when I do manage to add something to the variable it seems to add the value twice. And when the page refreshes the drop down list items are all errors, in_array() expects parameter 2 to be array, string given in add-blog.php on line 142 So how do you add multiple drop down lists to a database properly?
  16. Yes, but what if they clicked on a link from the updated page, and then hit back again, it is still going to show the message, it's not professional. How can it be overcome?
  17. e.g. a member updates their details and are redirected to the homepage, index.php?message=updated. The page gets the variable $_GET['message'], and sees that it equals updated, which makes it display "You information has been updated" in the update div. Now whenever that page is refreshed or the visitor goes to it again, i.e. index.php?message=updated, then it will always display that message. Even if you use jquery for the message to timeout. What is the best practice for such messages, am I right to assume sessions are involved?
  18. Ok, I seem to be running into a lot of issues with the headers, particularly with code like: header('location:index.php'); I am trying to use the ob_start() function, amongst others, but am really lost, as I really don't understand quite what is going on. Can anyone explain it to me in a simple way?
  19. Ok, so I can determine it through the database. So if we run something like $result = mysql_query(SELECT * FROM `restaurants`); while ($row = mysql_fetch_assoc($result)) { rename('images/$row['image']', $row['name']) } So there will be some sort of function (rename), that locates the image, and then the second argument gives its name to rename. Sure some valdation is necessary for $row['name'], but thats easy so dont worry about that, lets assume the name is e.g. my-restaurant.jpg
  20. No, that would be too easy. I want to actually create thumbnails. More like imagejpeg()
  21. So I have a folder of images e.g. /images/ and I want to run a script that goes into all the images, and creates new images into /images/thumbs/, which resizes the images into thumbnails. Any ideas on the best way to to achieve this?
  22. I am trying to work out a mysql query that will give a random order of results, and every time you refresh the order will change. Any ideas?
  23. Right ok sorry for the confusion. Say I have a directory of restaurants, and they have images like img_003452.jpg, and I want to rename it to the restaurant name, then how would I do that?
  24. I have about 500 images that are named like img_04352.jpg for example. I want to rename them all the the name of the page e.g. my-restaurant.jpg. Is there some script I can run to go through all the images and rename them?
  25. oh ok so I will just need to replace < > with <> ?
×
×
  • 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.