Jump to content

BoarderLine

Members
  • Posts

    140
  • Joined

  • Last visited

    Never

Everything posted by BoarderLine

  1. No, turns out it is still not returning all categories
  2. Ok got it, thanks anyway. Needed an additional GROUP BY field. SELECT count(posts.postID) AS count, categories.CatID, categories.category, cat_type_link.CatType FROM ((cat_type_link RIGHT JOIN categories ON categories.CatID = cat_type_link.Link_CatID) LEFT JOIN posts ON posts.Post_CatID=categories.CatID) WHERE cat_type_link.CatType = '1' AND posts.status = '1' GROUP BY categories.CatID, cat_type_link.CatType ORDER BY categories.category ASC
  3. Im not the best at this, however will attempt to add some thoughts as it appears no one else is willing to help you here. You have mixed your php in with your mysql statement which I cant see working. You need to first set the PHP values outside the MySql statement. eg. [code=php:0] $surname = "%".strtoupper(str_replace(" ", "", $_SESSION["Surname"]))."%"; $postcode = "%".strtoupper(str_replace(" ", "", $_SESSION["Postcode"]))."%"; [/code] And then call them in your MySql like this: SELECT '$something' FROM '$surname' WHERE etc. And to get the upper and lower case of database fields in Mysql you need to use lcase() and ucase() functions, although I don't believe the match here is case sensitive, nor should you require a str_replace for spaces if you are using wildcards.
  4. Or is it a SELECT within the COUNT i need?
  5. I have 3 tables as follows: +-----------+--------------+ table1> categories +-----------+--------------+ | CatID | category +-----------+--------------+ | 1 | category1 | | 2 | category2 | | 3 | category3 | | 4 | category4 | etc.. +-----------+--------------+ +-----------+--------------+--------------+ table2> cat_type_link +-----------+--------------+--------------+ | linkID | Link_CatID | CatType +-----------+--------------+--------------+ | 1 | 1 | 1 | 2 | 1 | 2 | 3 | 2 | 1 | 4 | 3 | 2 | 4 | 4 | 1 etc.. +-----------+--------------+--------------+ +-----------+--------------+--------------+ table3> posts +-----------+--------------+--------------+ | postID | Post_CatID | status +-----------+--------------+--------------+ | 1 | 1 | 0 | 2 | 2 | 1 | 3 | 2 | 1 | 4 | 1 | 1 | 3 | 3 | 1 | 4 | 1 | 1 etc.. +-----------+--------------+--------------+ I am trying to get the count() result for the number of posts (table posts) within each category which has a cat_type_link.CatType value of 1 and posts.status=1. The required result I am needing from the above example would output : category1 (# of posts 2) category2 (# of posts 2) category4 (# of posts 0) However my query below outputs: category1 (# of posts 2) category2 (# of posts 2) As you can see the empty count() on category4 is missing. If I remove the WHERE posts.status=1 part of the WHERE clause the result is what I require (however I don't want a count of posts that don't have a status of 1). It seems this is because the WHERE clause is over riding the LEFT JOIN. Do I need a sub SELECT in the query to achieve this? Thanks heaps for anyone that may offer advice. Here's what i've currently got: SELECT count(posts.postID) AS count, categories.CatID, categories.category, cat_type_link.CatType FROM ((cat_type_link RIGHT JOIN categories ON categories.CatID = cat_type_link.Link_CatID) LEFT JOIN posts ON posts.Post_CatID=categories.CatID) WHERE cat_type_link.CatType = '1' AND posts.status = '1' GROUP BY categories.CatID ORDER BY categories.category ASC
  6. Also if my cookie settings were not correct then other browsers would also fall over on this.... No no, I am now convinced that the reason that this is not working is because IE is S#*t.
  7. Here are my settings, which seem to have worked well up till now: Session Support enabled Registered save handlers files user Registered serializer handlers php php_binary wddx Directive Local Value Master Value session.auto_start On On session.bug_compat_42 Off Off session.bug_compat_warn Off Off session.cache_expire 180 180 session.cache_limiter nocache nocache session.cookie_domain no value no value session.cookie_httponly Off Off session.cookie_lifetime 0 0 session.cookie_path / / session.cookie_secure Off Off session.entropy_file no value no value session.entropy_length 0 0 session.gc_divisor 1000 1000 session.gc_maxlifetime 1440 1440 session.gc_probability 1 1 session.hash_bits_per_character 5 5 session.hash_function 0 0 session.name PHPSESSID PHPSESSID session.referer_check no value no value session.save_handler files files session.save_path /var/lib/php/session /var/lib/php/session session.serialize_handler php php session.use_cookies On On session.use_only_cookies On On session.use_trans_sid 0 0
  8. PHP 5.3.3 I am trying to redirect a user (currently logged in) to a page where they are able to edit a posted comment. To keep things secure I am using a forms hidden input value to pass the {postID} to a redirect page <form name="post_edit" method="post" action="post-edit-redirect.php" > <input type="hidden" name="local" id="local" value="<?php echo $row_rsPosts['postID']; ?>" /> <input type="image" src="../imgs/managepost.png" name="submit" /> </form> On the redirect page (simplified below) I am setting the {postID} in a SESSION before redirecting to the user to the page to edit their post with the new $_SESSION val for {postID} set. session_start(); $id = $_REQUEST['local']; $_SESSION['postID']=$id; header("Location: edit-post.php"); This is working fine in every browser except IE (some one please just put an end to it), where when the edit-post.php page is reached the $_SESSION['postID'] is empty. If I regenerate the session ID from the redirect page as below IE then sets the SESSION ok. session_start(); session_regenerate_id(); $id = $_REQUEST['local']; $_SESSION['postID']=$id; header("Location: edit-post.php"); However there should be no need to do this and would rather not if there is no need. Any help on why IE is not setting the SESSION is appreciated, and I hope I am not covering old ground here however I am unable to find a solution anywhere. - Cheers
  9. Hi. I can currently fumble around a bit with php however am wanting to know if someone can point me in the right direction as to the best book to teach myself properly how to code php from basic to pro for php5.3+. Does anyone have any suggestions? Many Thanks.
  10. Hi all. I have a video upload page utilizing ffmpeg to convert to .flv format via ajax with progress bar. Currently I am having an issue where the user uploads the video however the same upload script also converts to .flv format (exec("ffmpeg -i etc..")) after the file is uploaded. This is working fine however if the user selects to move away from the page after the video is uploaded it is causing the users browser to lockup (and sometimes crash). How can I make the exec() command to convert the video format strictly run server side and allow the user to move away from the page even though the conversion is still processing? Thanks for any advise on how to handle this issue.
  11. try changing to this [code=php:0] do { echo '<table><tr> <td align="left">' . $row['scientific_name'] . '</td> <td align="left">' . $row['common_name'] . '</td> <td align="left">' . $row['leaf_shape'] . '</td> <td align="left">test' . $row['leaf_margin'] . '</td> <td align="left">' . $row['leaf_color'] . '</td> </tr>'; } while($row = mysql_fetch_array($result)); [/code]
  12. Thanks litebearer, 1. Date type is 'date' 2. I have adjusted my query [code=php:0] mysql_select_db($database); $query_rsFirst = "INSERT INTO event_date (dateID, eventID, event_dtl_ID, date_start, date_end) VALUES (NULL, '$event', '$d', '$date', '$date')"; $rsFirst = mysql_query($query_rsFirst) or die(mysql_error()); [/code] Still getting error:- Catchable fatal error: Object of class DateTime could not be converted to string in htdocs/Insert/Date_Redirect.php on line 160 Line 160 is : [code=php:0] $query_rsFirst = "INSERT INTO event_date (dateID, eventID, event_dtl_ID, date_start, date_end) VALUES (NULL, '$event', '$d', '$date', '$date')"; [/code]
  13. I am using the following code to get the third sunday of every month for +6 Months from todays date. I have put together the following code which works perfectly when the date is echoed however when it comes to inserting those dates into mysql db it throws a unable to convert to string error. Im new to this and my head is in a spin as to why those dates can't be inserted if they can echoed ok. I have spent 2 days at it now and searched many forum however they seem to get side tracked from my issue (or do they)??????? I figure I can't go mixing DateTime and date() the way I have? Please help??? [code=php:0] $month=date('F'); $now=date('Y-m-d'); $year=date('Y'); $num='3'; //example only this will be a $_POST value 0-3 $day='Sunday'; //example only this will be a $_POST value Monday-Sunday $start= date('Y-m-d', strtotime('+'.$num.' week '.$day.' '.$month.' '.$year.'')); if($start>$now) { $begin=strtotime('+'.$num.' week '.$day.' '.$month.' '.$year.''); } else { $d = new DateTime( $start ); $d->modify( 'first day of next month' ); $nextmonth = $d->format( 'F' ); $year = $d->format( 'Y' ); $begin=strtotime('+'.$num.' week '.$day.' '.$nextmonth.' '.$year.''); } $date=date('Y-m-d', $begin); # insert into db first occurance //mysql_select_db($database); //$query_rsFirst = "INSERT INTO event_date VALUES (NULL, '$event', '$d', '$date', '$date')"; //$rsFirst = mysql_query($query_rsFirst) or die(mysql_error()); echo $date.'<br/>'; for($i = 0; $i <= 4; $i++) { $d = new DateTime( $date ); $d->modify( 'first day of next month' ); $nextmonth = $d->format( 'F' ); $date=date('Y-m-d', strtotime('+'.$num.' week '.$day.' '.$nextmonth.' '.$year.'')); # insert into db //mysql_select_db($database); //$query_rsDate = "INSERT INTO event_date VALUES (NULL, '$event', '$d', '$date', '$date')"; //$rsDate = mysql_query($query_rsDate) or die(mysql_error()); echo $date.'<br/>'; if($nextmonth=="December") { $d = new DateTime( $date ); $d->modify( 'first day of next year' ); $year = $d->format( 'Y' ); } } [/code]
  14. So it seems trying to increment by +2 was just causing $date_begin to repeat in a constant loop (obviously as it was never reaching <= $nbrweek. Ugly I know however the only way I could get it to work was by doing this: [code=php:0] $date_begin=strtotime('this Friday'); $nbrweek=52; $i = 0; do { # 52 week in one year of course $nextweek[$i]=date('Y-m-d', strtotime('+'.$i.' week',$date_begin)); echo $nextweek[$i].'<br/>'; $i++; $i++; } while ($i <= $nbrweek); exit; [/code]
  15. Still can't find a solution here. I have tried changing number of weeks, incrementing by anything other than +1 but for some reason the script is freezing like it is causing a continuous loop. I have tidied up the trouble code below as the original above was a bit messy. Any assistance on what may be causing this issue or a way to debug this script is appreciated as this is causing me serious pain. [code=php:0] # function function nextWeeksDay($date_begin,$nbrweek) { $nextweek=array(); for($i = 2; $i <= $nbrweek; $i+2) { # 52 week in one year of course $nextweek[$i]=date('Y-m-d', strtotime('+'.$i.' week',$date_begin)); } return $nextweek; } # end function # example of a select date $date_begin=strtotime('this Friday'); $nbrweek=52; # call function $result=nextWeeksDay($date_begin,$nbrweek); for($i = 2; $i <= $nbrweek; $i+2) { echo $result[$i]."<br/>"; } [/code]
  16. Thanks Paul, I will look into this as an alternate. However I would love to know why the function is not working as surely all logic suggests that if the the function is working correctly incrementing by +1 weeks it should also work incrementing by +2 weeks should it not?
  17. Sorry forgot to add im using PHP version 5.3.3
  18. Hi, I am using this function to output a list of dates for every friday over the next 12months. This is working fine. [code=php:0] //function function nextWeeksDay($date_begin,$nbrweek) { $nextweek=array(); for($i = 1; $i <= $nbrweek; $i++) { // 52 week in one year of course $nextweek[$i]=date('Y-m-d', strtotime('+'.$i.' week',$date_begin)); } return $nextweek; } /// end function /// example of a select date // var $date_begin=strtotime('this Friday'); $nbrweek=52; // call function $result=nextWeeksDay($date_begin,$nbrweek); // Insert //$date1=date('Y-m-d', $date_begin); for($i = 1; $i <= $nbrweek; $i++) { //$date=$result[$i]; echo $result[$i]."<br/>"; } [/code] My problem is that when I alter the code to try and get the date for every second Friday for the next year the script freezes. [code=php:0] //function function nextWeeksDay($date_begin,$nbrweek) { $nextweek=array(); for($i = 2; $i <= $nbrweek; $i+2) { // 52 week in one year of course $nextweek[$i]=date('Y-m-d', strtotime('+'.$i.' week',$date_begin)); } return $nextweek; } /// end function /// example of a select date // var $date_begin=strtotime('this Friday'); $nbrweek=52; // call function $result=nextWeeksDay($date_begin,$nbrweek); // Insert //$date1=date('Y-m-d', $date_begin); for($i = 2; $i <= $nbrweek; $i+2) { //$date=$result[$i]; echo $result[$i]."<br/>"; } [/code] I really don't understand why?? Does anyone know why? Thanks
  19. hmmmm that just returned the date variable without adding the 6 months....... however thanks I appreciate the assist. I must figure another way
  20. Thanks rwwd, I should have explained a little more about the problem. In the example given I am using $today=date("Y-m-d") however in my code the $today variable can be substituted for any date not just today. So really what I am needing is the strtotime() function to generate +6 months from a dynamic date.
  21. PHP 5.3.3 I am using this to get a date 6 months from:- $today=date("Y-m-d"); $newdate=strtotime(date("Y-m-d", strtotime($today)) . " +6 months"); However I am getting the output format:- 1299495600 (or similar) The strange thing is this did work with PHP4. Does anyone know why??????????? Cheers
  22. I used this: simple_mail("us@url.co.nz", "name@address.com", "subject", "message");
×
×
  • 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.