Jump to content

sgiandhu

Newly Registered
  • Posts

    13
  • Joined

  • Last visited

Everything posted by sgiandhu

  1. I used the following recently on a site, which allowed me to choose the most recent items and display them randomly: [code]SELECT tblName.item FROM tblName WHERE MONTH(itemDate) = MONTH(CURDATE()) AND YEAR(itemDate) = YEAR(CURDATE()) ORDER BY RAND()  LIMIT 0, 5[/code] I used WHERE instead of ORDER to select the items I wanted. HTH. Joss
  2. [!--quoteo(post=333563:date=Jan 5 2006, 08:26 AM:name=sgiandhu)--][div class=\'quotetop\']QUOTE(sgiandhu @ Jan 5 2006, 08:26 AM) 333563[/snapback][/div][div class=\'quotemain\'][!--quotec--] Meantime I'm off to read the PHP Manual - Again!! I found my answer in the SQL manual, and am posting it here for anyone who might be interested: SELECT * FROM tblNews WHERE MONTH(newsDate) = MONTH(DATE_ADD)CURDATE(),INTERVAL -1 MONTH)) Here's the reference to [a href=\"http://dev.mysql.com/doc/refman/5.0/en/date-calculations.html\" target=\"_blank\"]date calculations[/a] And thanks again, to degsy, for pointing me in the right direction Joss
  3. [!--quoteo(post=333515:date=Jan 5 2006, 06:25 AM:name=degsy)--][div class=\'quotetop\']QUOTE(degsy @ Jan 5 2006, 06:25 AM) 333515[/snapback][/div][div class=\'quotemain\'][!--quotec--] I think you are looking for something similar to <?php if($totalRows_Recordset1 > 5){ ?> <p><a href="newslinkpage.php" title="link to news articles pages">More articles</a></p> <?php } ?> Thanks, this worked wonderfully. Now if you happen to know the right way to bring up stuff from LAST MONTH.. a sort of CURDATE() -1 ........ Meantime I'm off to read the PHP Manual - Again!! Joss
  4. [!--quoteo(post=322188:date=Nov 26 2005, 02:19 AM:name=binime)--][div class=\'quotetop\']QUOTE(binime @ Nov 26 2005, 02:19 AM) 322188[/snapback][/div][div class=\'quotemain\'][!--quotec--] session_start should often go straight after the opening php tags <?php session_start(); in your next page if(isset($_COOKIE['UserName'])) { echo "welcome back ". $_COOKIE['UserName']; } else { echo "No user cookie found"; } Thanks - working properly now! Cheers, Joss
  5. I have a page which shows up to 5 news links from a regularly updated database, using a repeat region. When there are more than 5, the oldest link drops into an archive page which is specific to the current month. At the bottom of the 5 items, I have an html link to the archive page, which works fine as is. However, now I want to make this link's visibility conditional on the number of links on the main page - as in show if there are more than 5 items, and hide if there are 5 or less. Hopefully this makes sense, if not, please ask! Currently the db query for the items to display is this: SELECT * FROM tblNews ORDER BY tblNews.newsID DESC with a repeat region of only 5 items. This is the part I want to tie to the recordset: <p><a href="newslinkpage.php" title="link to news articles pages">More articles</a></p> I've tried LIMIT, which doesn't seem to like the idea, and I'm a bit stumped as to where to look next. Anyone able to point me in the right direction for wording the queryset? Many thanks. J
  6. [!--quoteo(post=314046:date=Nov 2 2005, 09:25 AM:name=Enc0der)--][div class=\'quotetop\']QUOTE(Enc0der @ Nov 2 2005, 09:25 AM) 314046[/snapback][/div][div class=\'quotemain\'][!--quotec--] 2. a function (I believe it's just a sql-query, actually) that will get all the items from a specific month only. Remember that's every item have a 'date' as a unix timestamp.. Do you have any idea on how to make that in an efficient way ? I can supply this as far as the query to the DB structure goes, but I think someone else might have to help you with the rest..... SELECT * FROM tableNews WHERE YEAR(Date) = YEAR(CURDATE()) AND MONTH(Date) = 8 ORDER BY Date ASC Depending on how your DB is set up, the above should give you all the listings from August for the current year - adjust the MONTH(Date) = X accordingly. Hope this helps J
  7. Can someone please check over my DW generated syntax and let me know if I've got the bits all in the right place? I'm mostly concerned about the position of the cookie in relation to both the call for the secure site and the connection... <?php //made sure we go to the secure server include_once ('../igosecure.php'); //connect to the DB require_once('../Connect/myDB.php'); // save the username information for the login form if (isset($_POST['Login'])) { if (isset($_POST['storeprofile'])) { setcookie("UserName", $_POST['username'], time()+86400*30); } else { setcookie ("UserName", "",time()-43200); } } // *** Validate request to login to this site. session_start(); $loginFormAction = $_SERVER['PHP_SELF']; if (isset($accesscheck)) { $GLOBALS['PrevUrl'] = $accesscheck; session_register('PrevUrl'); } if (isset($_POST['username'])) { $loginUsername=$_POST['username']; $password=$_POST['password']; $MM_fldUserAuthorization = "access"; $MM_redirectLoginSuccess = "https://www.mysite.com/others/theirpage.php"; $MM_redirectLoginFailed = "login.php?failed=true"; $MM_redirecttoReferrer = false; mysql_select_db($database_myDB, $myDB); $LoginRS__query=sprintf("SELECT username, password, m_access, memberID FROM members WHERE username='%s' AND password='%s'", get_magic_quotes_gpc() ? $loginUsername : addslashes($loginUsername), get_magic_quotes_gpc() ? $password : addslashes($password)); $LoginRS = mysql_query($LoginRS__query, $myDB) or die(mysql_error()); $loginFoundUser = mysql_num_rows($LoginRS); if ($loginFoundUser) { $loginStrGroup = mysql_result($LoginRS,0,'m_access'); //declare two session variables and assign them $GLOBALS['MM_UserName'] = $loginUsername; $GLOBALS['MM_UserID'] = mysql_result($LoginRS,0,'memberID'); $GLOBALS['MM_UserGroup'] = $loginStrGroup; //register the session variables session_register("MM_UserName"); session_register("MM_UserID"); session_register("MM_UserGroup"); if (isset($_SESSION['PrevUrl']) && false) { $MM_redirectLoginSuccess = $_SESSION['PrevUrl']; } header("Location: " . $MM_redirectLoginSuccess ); } else { header("Location: ". $MM_redirectLoginFailed ); } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> etc etc etc. If I want to now carry that username cookie over to the next page, do I also need to put in a set cookie command? Many thanks J
  8. [!--quoteo(post=318842:date=Nov 15 2005, 09:38 AM:name=obsidian)--][div class=\'quotetop\']QUOTE(obsidian @ Nov 15 2005, 09:38 AM) 318842[/snapback][/div][div class=\'quotemain\'][!--quotec--] you're not telling SQL what to update as NOW()... you have to assign it to a column just like all your other updates: [!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']UPDATE[/span] tableName SET `[span style=\'color:blue;font-weight:bold\']update[/span]_time` = NOW() WHERE... [!--sql2--][/div][!--sql3--] Thank you .. how obvious! I did actually figure this out by looking at another post, however, having my thought process confirmed is very nice. I appreciate the help. That's twice in 2 days I've had help here, so I'm off to make my donation. Cheers and many thanks again J
  9. Hi there, I am updating some information in a DB with a short form. However, inserting the date into the update field is being a bit of a trial. partial code posted: the problem is evidently in this section if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "formname")) { $updateSQL = sprintf("UPDATE tblName SET access=%s, uname=%s, password=%s, NOW() WHERE memberID=%s", GetSQLValueString($_POST['access'], "int"), GetSQLValueString($_POST['uname'], "text"), GetSQLValueString($_POST['password'], "text"), GetSQLValueString($_POST['info_update'], ''), GetSQLValueString($_POST['memberID'], "int")); mysql_select_db($database_name, $dbname); $Result1 = mysql_query($updateSQL, $dbname) or die(mysql_error()); I get an error message saying MySQL doesn't like my use of NOW() where it is in relation to the WHERE command... Anyone able to correct me here? Many thanks J
  10. [!--quoteo(post=318532:date=Nov 14 2005, 02:43 PM:name=ryanlwh)--][div class=\'quotetop\']QUOTE(ryanlwh @ Nov 14 2005, 02:43 PM) 318532[/snapback][/div][div class=\'quotemain\'][!--quotec--] the mysql manual suggested the following: [!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']SELECT[/span] * FROM tblName WHERE YEAR(itemDate) = YEAR(CURDATE()) AND MONTH(itemDate) = MONTH(CURDATE()) ORDER BY itemDate DESC LIMIT 5, 9999999999999999999 [!--sql2--][/div][!--sql3--] this would fetch all the rows after the 5th to the 9999999999999999999999th row (which i think is more than enough) Perfect! Thank you. I was trying to navigate my way around the MySQL manual, but wasn't sure what to look for exactly! As far as the script goes, it works just fine at DESC LIMIT 5, 100! Now onto the next one... how to do the same thing for some other month! Appreciate the help. ! Now where is that button - this one is solved. Many thanks J
  11. [!--quoteo(post=318465:date=Nov 14 2005, 12:38 PM:name=ryanlwh)--][div class=\'quotetop\']QUOTE(ryanlwh @ Nov 14 2005, 12:38 PM) 318465[/snapback][/div][div class=\'quotemain\'][!--quotec--] how many records are you going to fetch? you could specify the offset of LIMIT to 4 so it ignore the first 4 elements. I'm using 5 on the main page, with a "more" link to the second page. On the second page I want to display the rest of the links, but the number becomes variable, depending on how many new items get added to the first page. So if I do this: SELECT * FROM tblName WHERE YEAR(itemDate) = YEAR(CURDATE()) AND MONTH(itemDate) = MONTH(CURDATE()) ORDER BY itemDate DESC LIMIT 5 Then I only get the most recent 5 ..which is great for the front page... but not what I need for the 2nd page! Thanks. J
  12. Hi everyone. I am using a query to place news items on a link page. Items are in the DB and I can get at them using: SELECT * FROM tblName WHERE YEAR(articleDate) = YEAR(CURDATE()) AND MONTH(articleDate) = MONTH(CURDATE()) What I would like to also do, is limit this query to not include the 4 most recent (they are being displayed on another page). I can of course, sort by other criteria in the DB, such as title, source ID etc, but thought this way would be the best for what I want With my experimenting, I've found that LIMIT isn't quite what I want. Is there something else that would do what I need? Many thanks J
×
×
  • 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.