Jump to content

GeoffOs

Members
  • Posts

    24
  • Joined

  • Last visited

Everything posted by GeoffOs

  1. Because your grouping clause only specifies firstname then duplicates will be removed from the results where the firstname matches. I would have thought you would not need group by, unless you specify all the fields. The group by clause is explained http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html Are you expecting duplicates across all the name fields?
  2. Try: SELECT convert(varchar(20), text_date_updated, 20), convert(varchar(20), text_date_created, 20) FROM table
  3. Sounds good but I think: SELECT TheBlogTable.BlogId, TheBlogTable.BlogPost FROM TheBlogTable INNER JOIN TheTagTable on TheBlogTable.BlogId = TheTagTable.BlogId WHERE TheTagTable.TagText = "TagToCheckFor" I am not a big fan of sub queries, you cannot easily predict the performance......
  4. What about "SELECT ads.*, ad_maincat.maincat_name, ad_subcat1.subcat1_name, ad_subcat2.subcat2_name FROM ads INNER JOIN ad_maincat ON ads.maincat_id = ad_maincat.maincat_id INNER JOIN ad_subcat1 ON ads.subcat1_id = ad_subcat1.subcat1_id INNER JOIN ad_subcat2 ON ads.subcat2_id = ad_subcat2.subcat2_id WHERE ad_id = $_GET[ad_id] AND approved='Y' ORDER BY submitted DESC"; Though this expects to always have a main_cat, subcat1 and subcat2. If these are not always present then switch the join to be a LEFT OUTER JOIN so that the ads record is always returned irrespective of the existing of if the categories have been assigned. Though you should always check the $_GET variable is what you expect before putting it into a query.. Also have you read http://www.phpfreaks.com/tutorial/data-joins-unions
  5. That would be fine for showing the post, but what about listing all (paged) posts with a specific tag?
  6. but this would be inefficient if you have more than one tag per post. A one to many relationship with a Tags table would be much better and allow as many tags against a post as you wanted.
  7. If this was SQL Server something like: select count(ItemId), count(ItemId) as 'FailCount' FROM TestResults a inner join TestResults b on a.ItemId = b.ItemId and a.TestID = b.TestId WHERE TestFail = TRUE group by ItemId, TestId having count(ItemId) >= 3 Would be more efficient. I am not sure if the above would work in access. Though if you remove the bits that don't help the results in your existing query it should work a bit quicker: SELECT count(ItemId) from TestResults a where ResultId IN ( SELECT Top 3 ResultID from TestResults b Where a.ItemId = b.ItemId AND a.TestID = b.TestId ORDER BY TestDate DESC ) AND TestFail = true ) group by ItemId, TestId having COUNT(ItemId) >= 3
  8. I think your error is in this bit WHEN ISDATE (T1.[DocDate]) <> 1 THEN COALESCE (CAST (T1.[DocDate] as datetime),'NOT') You have already determined that T1.[DocDate] is null (or at least not a date) so you need to do this: WHEN ISDATE (T1.[DocDate]) <> 1 THEN COALESCE (T1.[DocDate],'NOT') Or Even WHEN ISDATE (T1.[DocDate]) <> 1 THEN 'NOT')
  9. try wrapping your date field with the following: select convert(varchar(50), getdate() , 20) For me this produces: 2009-04-22 12:24:23
  10. Why not calculate the $_SESSION bit before into a different variable: [code] if ($_SESSION['e_commerce_check'] == 'yes') { $check = ($_SESSION['turnaround_time+e-com']); } else { $check = ($_SESSION['turnaround_time']); } $message = " Order Number : ".$_SESSION['order_no']." Order Date : ".date("F jS, Y")." Development time guaranteed : ".$check." Days Name : ".$_SESSION['name']." Address : ".$_SESSION['address1'].";[/code] Or have I not understood the question?
  11. It would be handy to be able to view un-answered posts, that way, we attempt to answer them. Way back when I first created my account this was possible, but now seems to have disappeared.
  12. Have you installed SQL Server SP3a this fixes this issue on pre SP 2 versions of SQL Server on Windows XP / 2003
  13. Where is the SQL Server Located? Can you use extended stored Procedures. If so you could use a stored proc to send an email. Have a look here: [url=http://support.microsoft.com/kb/312839/en-us]http://support.microsoft.com/kb/312839/en-us[/url] Or you could configure SQL Mail, though this requires a MAPI profile from memory.
  14. You can use the group by clause. So your SQL would look something like this: [code] $query = "select * from ingredients, production, recipes, recipeMakeup where production.productionDate = '$today'"; $query.= "AND recipes.recipeID = recipeMakeup.recipeID"; $query.= "AND recipeMakeup.ingredientID = ingredients.ingredientID"; $query.= "AND production.recipeID = recipes.recipeID "; $query.= "GROUP BY ingredientName"; $query.= "ORDER BY ingredientName ASC;"; [/code] (I think)
  15. You could write two queries and union the results together [url=http://dev.mysql.com/doc/refman/5.0/en/union.html]http://dev.mysql.com/doc/refman/5.0/en/union.html[/url] For Example [code] select date from my table where date >= now() order by date desc UNION ALL select date from my table where date <= now() order by date asc [/code] Or something like that
  16. You could use the convert function on your datetime column to change it into a date only column, for example [code]select convert(varchar(11), getdate(), 106)[/code] which returns [code]17 May 2006[/code] More details are available from msdn here [a href=\"http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_ca-co_2f3o.asp\" target=\"_blank\"]Cast and Convert MSDN Article[/a] I think you can use this result within your group by clause, though I have not tested this.
  17. You can use a query like this: [code]select * from information_schema.columns where table_name = '<<your table name>>'[/code]
  18. At the end of you select line put LIMIT 0, 10 This will limit the records returned to 10 starting with the first record.
  19. I think you need to provide more information. But if you look at your code you are specifying that insert.php is in the directory above, I think you need to change: <form method="POST" action="./insert.php" name="form"> to <form method="POST" action="insert.php" name="form"> Quick google search returned this tutorial: http://hotwired.lycos.com/webmonkey/99/21/...?tw=programming
  20. GeoffOs

    mysql select

    Not quite sure why you would need to do what you are talking about. Could you not iterate through the recordset you already have. You have specified a date order so the next record in the recordset would be the next record by date. If not I would do something like this Select the record Display the current record Move to the next record and get an id column stored as a var This would allow you to page through the results. Though this should be a good tutorial for you :http://www.phpfreaks.com/tutorials/73/0.php
  21. Try the union clause. If all the tables have the same definition then you can add mulitple selects together to become one recordset: SELECT ... UNION [ALL] SELECT ... [UNION SELECT ...] Have a look at the mySQL Help here : http://www.mysql.com/doc/en/UNION.html Though somebody posted on the mysql web site this work around if you are working on mysql 3.... An alternative, rather simpler (especially with very complex select statements) way to \'use union\' in 3.x might be the following: Build a nice union query. (save it somewhere, so you can use that if you upgrade) If you would say that query was \'(*cool_select_statement_1*) UNION (*cool_select_statement_2*) *order_and_group_by_stuff*\'. You could make an replacement set of query\'s like this: CREATE TEMPORARY TABLE temp_union TYPE=HEAP *cool_select_statement_1*; INSERT INTO temp_union *cool_select_statement_2*; SELECT * FROM temp_union *order_and_group_by_stuff*; DROP TABLE temp_union; Note that I\'ve use a HEAP and TEMPORARY table because that combination is rather fast and, well, temporary. You can\'t execute these query\'s on one line (well I coudn\'t), so it would look like this in PHP: mysql_query(\'CREATE..\', $connection); mysql_query(\'INSERT..\', $connection); $query = mysql_query(\'SELECT..\', $connection); mysql_query(\'DROP..\', $connection);
  22. It sound like you need a where clause on your query Your query should be something like this: $select = "SELECT * FROM orders"; $select .= " where orders_status = 1"; $select .= " and DATE(date_purchased) = DATE(sysdate())"; The DATE returns only the current date and not the time, so the query will return all records that were created today and have a status of 1
  23. When i wanted a daemon to start on boot up, i created a script file within the rc.d tree. Have a look here on how to do it: http://www.redhat.com/docs/manuals/linux/R...wn-process.html
×
×
  • 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.