Jump to content

dan2684

Members
  • Posts

    37
  • Joined

  • Last visited

    Never

Everything posted by dan2684

  1. No worries - good luck! :-)
  2. I think my question is being completely misunderstood - I realise this is probably due to a bad explanation on my part. Thank you for your advice, I'll mark this as solved and go with building a dynamic query string using the products' PK to determine which row to update. In this instance, in your opinion, is there any point in even appending the WHERE clause? It seems irrelevant because we already know exactly which rows are going to be updated (using the PK). Just in case there's the possibility of anyone making sense of my ramblings, I'll just have one last attempt in explaining... - The array holds values that I intend to update in specific "position" fields in my "products" table. - The arrays' values appear in the exact same order as their respective rows in the "products" table. - When using the WHERE clause, the amount of affected rows will be the exact same length as the values in the array (I know this because the array only holds values for that specific group of products). The idea is to get a query running through the table updating the "position" fields in the table using the each value from the array. I am basically putting my trust in the fact that the current amount of affected rows (while the SQL query is executing) will be the exact key to use in the array, due to it being the exact same length and the values being in the exact order that the "products" appear in the table. Thanks again for your time! :-)
  3. If you just want to use your $session object in the query can't you do it like this? SELECT * FROM `".TBL_EVENTS."` WHERE `archived` = 0 AND CASE WHEN ('".$session->logged_in."' = 1) THEN type >0 ELSE type != 11 AND type != 12 END Do you get an error? What does it say?
  4. I mean, the answer might simply be to loop through the array and run a different query each time - I don't actually know, hence the reason I am asking! Is it that bad to do that? I always thought it was better to try and get everything into one query - please tell me if I'm wrong...
  5. OK, I understand where the confusion lies now. The catId field is NOT a unique id for each row. catId refers to the id of the category that the product sits in. So, for example, that query might be, "update all products in the 'mens' category". This is not a made up example, this is my code!! The only part I made up is the array because it comes from a query string and there's hundreds of products in there... but it will look exactly like that, just larger.
  6. Hi, thanks for your response. I want to take these values... $positions = array(3,1,2); ...and put them into the position field... $sql = "UPDATE products SET position = ??????? WHERE catId = $catId"; ...but I don't want to smash the database with hundreds of queries in a for loop. (PS the array will be much larger than the example above).
  7. Cool, well thank you for your time - I appreciate it! :-)
  8. I do want to update the values in a database using the values in an array. The thing is, it's going to be hundreds of records at a time and I don't want to query the database hundreds of times in a loop like you have in your example. Is there a way to use an incrementing value in one query?
  9. I'm sort of getting somewhere... although I realise now that this probably isn't the right approach, as I'm never going to be able to call a different part of the array using a SQL variable... damn it! Any help would be greatly appreciated... $sql = "SELECT @i:=0"; if(!mysql_query($sql)) die(mysql_error()); $sql = "UPDATE products SET position = $positions[@i:=@i+1] WHERE catId = $catId"; if(!mysql_query($sql)) die(mysql_error());
  10. Hello all, I'm going to update the display order of a bunch of products in a category (by the way, if I'm doing this wrong, please tell me!). I have an array which is consists of all the "position" fields in the correct order. I want to update all the relevant rows in one statement... something like this: "UPDATE products SET position = $positions[CURRENT_INCREMENT] WHERE catId = $catId" CURRENT_INCREMENT being the amount of rows it's currently updated... which obviously doesn't exist because I just made it up! I can't seem to find anything like this online. Any ideas? Thanks in advance, Dan
  11. Again, one of those situations where I'm not thinking properly. Classic example of having all the tools but not knowing how to use them! PFMaBiSmAd - I can't believe I've never thought of that before. I've been using an "image name" column in my applications for about 3 years!!! Thanks a lot guys. Much appreciated!
  12. Hello All, What's the best way to generate a unique image name? My initial thought was to use the time() but I'd rather use something more relevant to the actual image. I know you can use mysql_insert_id() but surely this means adding all information apart from the image name to the database, getting the insert id and then returning to the database again with the unique image name... Is there a way of using the current insert id? Thanks, Dan
  13. Good point Thank you!
  14. Hello all, I need to get the first row of a result set at one part of my page and then all rows further down the page. I only want to make one trip to the database so I thought I could fetch the result set and then display various different parts of it. The problem I'm having is, I'm using mysql_fetch_array() to display the first row but when I use the same function on the result set further down the page, the marker has moved showing all results from the second row onwards. Enough rambling! Basically, I do this: $sql = "SELECT * FROM categories"; $result = mysql_query($sql); $cat = mysql_fetch_array($result); $catId = $_POST['catId'] ? $_POST['catId'] : $cat['id']; And then this doesn't work properly: while ($category = mysql_fetch_array($result)) { echo "<option value=\"{$category['id']}\">{$category['name']}</option>"; } Any help would be greatly appreciated. Thanks, Dan
  15. Great - thank you, I'll bare that in mind :-)
  16. Hello all, My client has a list of email addresses stored in a database and I want to be able to send them all an email at the same time. The only way I know of is to get the data into a while loop - with msql_fetch_array() - and just send them all the email using the Mail() function. Is there a more efficeint way of doing this? I'm not sure how many customers they're going to have in the future, but definitely a few hundered... Thanks in advance, Dan
  17. PFMaBiSmAd - you are a genius, thank you! I can sleep well now. (It's 00:20 here in London!) Thanks again :-)
  18. Again, I'd really appreciate any suggestions! This is seriously doing my head in...!
  19. You're absolutely right - it should!! I don't know why I did that... That's not the problem though :-/ ! FYI - I've changed it to: $fromDate = "2009-10-20"; $toDate = "2009-10-20";
  20. I'm trying to insert data into a table in my databse and it's proving to be more diffucult that it should be! Here is my code: $fromDate = "20-20-2009"; $toDate = "20-20-2009"; $sql = "INSERT INTO shows (from, to, venue, stand, area) VALUES ('$fromDate', '$toDate', '{$_POST['venue']}', '{$_POST['stand']}', '{$_POST['area']}')"; if(!mysql_query($sql)){ echo mysql_error(); } It's giving me this error: "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'from, to, venue, stand, area) VALUES ('20-20-2009'..." Any help would be greatly appreciated! Thanks in advance, Dan
  21. I really didn't know you had to put it in the same directory! Thank you revraz - you are a genius :-)
  22. I've just checked my cookies folder - it IS there and it has the correct value. It's just not echoing out... what's also weird is that it echoes out on the page where I set the cookie, but not the homepage.
  23. Apologies for not being clear. Product page: setcookie("lastViewed",$_GET['prodId'],time()+3600); Homepage: echo $_COOKIE["lastViewed"];
  24. Yup - I know. The cookie isn't there. Does that fact that it's running locally make a difference? I know that sometimes things like mail() don't work until I make it live. ie. are there settings in Apache that I can change?
  25. Maq- no errors revraz - because I'm trying to echo it out on another page
×
×
  • 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.