Muhammad Mustafa Posted September 8, 2006 Share Posted September 8, 2006 hello allplz every body help me to edit this query[code]$SQL = '' . 'SELECT * FROM articles WHERE category=\'' . $_GET['cat_id'] . '\' AND type=0 AND status=1 AND tim<' . $_GET['tim'] . ' ORDER by tim DESC LIMIT 10';[/code]i use the limit with this query in numbers but i want it to show me the articles from last 7 daysi mean i use limit 10;this will show me last 10 articles if i change it to[code]limit 20;[/code]will show me last 20 insert in this tablei want to show all inserts in the last 7 daysi don't know how to write iti think it will be something like[code]limit 7days;[/code]or in any another way i don't howplz help me fastthx :) Quote Link to comment Share on other sites More sharing options...
jefkin Posted September 8, 2006 Share Posted September 8, 2006 [quote author=Muhammad Mustafa link=topic=107390.msg430845#msg430845 date=1157744605]hello allplz every body help me to edit this query[code]$SQL = '' . 'SELECT * FROM articles WHERE category=\'' . $_GET['cat_id'] . '\' AND type=0 AND status=1 AND tim<' . $_GET['tim'] . ' ORDER by tim DESC LIMIT 10';[/code]*snip*[/quote]Assuming $_GET['tim'] and database tim is in mysql database date form.[code]$SQL = '' . 'SELECT * FROM articles WHERE category=\'' . $_GET['cat_id'] . '\' AND type=0 AND status=1 AND tim<' . $_GET['tim'] . ' AND datedif(' . $_GET['tim'] . ', tim) <= 7 ORDER by tim DESC LIMIT 10';[/code]Jeff Quote Link to comment Share on other sites More sharing options...
radalin Posted September 9, 2006 Share Posted September 9, 2006 then just write "SELECT * FROM articles WHERE category='" . $_GET['cat_id'] . "' AND type=0 AND status=1 ORDER by tim DESC LIMIT 10";this will get the lastest 10 entries. You do not need to put a time clause to the where again. You are not making a search from this date to that date. Just want the latest ones. And for that you order them by tim value. If you get an error about the sql syntax instead of limit 10 try limit10,0 (10 rows begining from 0th) Quote Link to comment Share on other sites More sharing options...
Muhammad Mustafa Posted September 17, 2006 Author Share Posted September 17, 2006 sorry guysbut both edits didn't work good with medown is the whole function, in attach is the whole file that contains this fun.thanks alot for your effortsand hope to find a solution sooooon :)[code] function typical_article () { include 'lang/' . language; if ($_GET['tim']) { $SQL = '' . 'SELECT * FROM articles WHERE category=\'' . $_GET['cat_id'] . '\' AND type=0 AND status=1 AND tim<' . $_GET['tim'] . ' ORDER by tim DESC'; } else { $SQL = '' . 'SELECT * FROM articles WHERE category=\'' . $_GET['cat_id'] . '\' AND type=0 AND status=1 ORDER by tim DESC'; } if (!($result = mysql_query ($SQL))) { exit ('<b>Error:</b>' . mysql_error ()); ; } $row = mysql_fetch_array ($result); if (!($result = mysql_query ($SQL))) { exit ('<b>Error:</b>' . mysql_error ()); ; } if ($dir = @opendir ('upload/cat_images/')) { while (($file = readdir ($dir)) !== false) { if (strpos ($_GET['cat_id'], '~')) { $patt = substr ($_GET['cat_id'], 0, strpos ($_GET['cat_id'], '~')); } else { $patt = $_GET['cat_id']; } if (strstr ($file, $patt)) { echo '<IMG SRC="upload/cat_images/'; echo $file; echo '" width="100%" border=0>'; continue; } } closedir ($dir); } echo ''; if ($_GET['tim']) { $SQL0 = '' . 'SELECT * FROM articles WHERE instr(category,\'' . $_GET['cat_id'] . '\') AND type=2 AND status=1 AND tim<' . $_GET['tim'] . ' ORDER by tim DESC'; } else { $SQL0 = '' . 'SELECT * FROM articles WHERE instr(category,\'' . $_GET['cat_id'] . '\') AND type=2 AND status=1 ORDER by tim DESC'; } if (!($result0 = mysql_query ($SQL0))) { exit ('<b>Error:</b>' . mysql_error ()); ; } $row0 = mysql_fetch_array ($result0); if (!($result0 = mysql_query ($SQL0))) { exit ('<b>Error:</b>' . mysql_error ()); ; } if ($row0) { echo ' <table width="150" border="0" cellspacing="0" cellpadding="7" align="right" style="border: '; if (typical_headlines_border == 1) { echo 1; } else { echo 0; } echo 'px solid '; echo typical_headlines_border_color; echo '; background: '; echo typical_headlines_bg_color; echo ';"> <tr bgcolor="'; echo typical_headlines__bg__color; echo '"><td align="center" valign="top"><font STYLE="color:'; echo typical_headlines__color; echo '; font-family:'; echo typical_headlines__font; echo '; font-size:'; echo typical_headlines__font__size; echo '; font-weight:'; echo typical_headlines__font__weight; echo ';">'; echo $text__Headlines; echo '</font></td></tr> <tr><td valign="top"> '; while ($row0 = mysql_fetch_array ($result0)) { echo '<a href="index.php?id='; echo $row0['id']; echo '" STYLE="color:'; echo typical_headlines_title_color; echo '; font-family:'; echo typical_headlines_title_font; echo '; font-size:'; echo typical_headlines_title_font_size; echo '; font-weight:'; echo typical_headlines_title_font_weight; echo ';">'; echo $row0['title']; echo '</a> <table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td height="5"></td></tr></table> '; if (typical_headlines_tmb == 'yes') { if ($dir = @opendir ('upload/thumbnails/')) { while (($file = readdir ($dir)) !== false) { if (strstr ($file, $row0['tim'])) { echo '<a href="index.php?id='; echo $row0['id']; echo '"><IMG SRC="upload/thumbnails/'; echo $file; echo '" vspace="5" align="'; echo typical_headlines_tmb_align; echo '" '; if (typical_headlines_tmb_width) { echo 'width="'; echo typical_headlines_tmb_width; echo '"'; } echo ' '; if (typical_headlines_tmb_height) { echo 'height="'; echo typical_headlines_tmb_height; echo '"'; } echo '></a>'; continue; } } closedir ($dir); } } echo ' <font STYLE="color:'; echo typical_headlines_description_color; echo '; font-family:'; echo typical_headlines_description_font; echo '; font-size:'; echo typical_headlines_description_font_size; echo '; font-weight:'; echo typical_headlines_description_font_weight; echo ';">• '; echo $row0['description']; echo '</font><br> '; } echo ' </td></tr></table> '; } echo ' <table border="0"> '; while ($row = mysql_fetch_array ($result)) { echo ' <tr><td valign="top"> <a href="index.php?id='; echo $row['id']; echo '" STYLE="color:'; echo typical_title_color; echo '; font-family:'; echo typical_title_font; echo '; font-size:'; echo typical_title_font_size; echo '; font-weight:'; echo typical_title_font_weight; echo ';">'; echo $row['title']; echo '</a> </td></tr> <tr><td valign="top" height=1></td></tr> <tr><td valign="top"> '; if ($dir = @opendir ('upload/thumbnails/')) { while (($file = readdir ($dir)) !== false) { if (strstr ($file, $row['tim'])) { echo '<a href="index.php?id='; echo $row['id']; echo '"><IMG SRC="upload/thumbnails/'; echo $file; echo '" align="'; echo typical_tmb_align; echo '" '; if (typical_tmb_width) { echo 'width="'; echo typical_tmb_width; echo '"'; } echo ' '; if (typical_tmb_height) { echo 'height="'; echo typical_tmb_height; echo '"'; } echo ' style="border: 1px solid Black;"></a>'; continue; } } closedir ($dir); } echo ' <font STYLE="color:'; echo typical_description_color; echo '; font-family:'; echo typical_description_font; echo '; font-size:'; echo typical_description_font_size; echo '; font-weight:'; echo typical_description_font_weight; echo ';">'; echo $row['description']; echo '</font> </td></tr> <tr><td valign="top" height=7></td></tr> '; } echo ' </table>'; }[/code][attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
Muhammad Mustafa Posted September 18, 2006 Author Share Posted September 18, 2006 heeeeyany body here!! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.