Jump to content


Photo

Select From LIMIT .. help in editing is needed :(


  • Please log in to reply
4 replies to this topic

#1 Muhammad Mustafa

Muhammad Mustafa
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 08 September 2006 - 07:43 PM

hello all
plz every body help me to edit this query


$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';


i use the limit with this query in numbers but i want it to show me the articles from last 7 days
i mean i use limit 10;
this will show me last 10 articles if i change it to
limit 20;
will show me last 20 insert in this table
i want to show all inserts in the last 7 days
i don't know how to write it
i think it will be something like
limit 7days;
or in any another way i don't how
plz help me fast
thx :)

#2 jefkin

jefkin
  • Members
  • PipPipPip
  • Advanced Member
  • 55 posts

Posted 08 September 2006 - 10:54 PM

hello all
plz every body help me to edit this query


$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';

*snip*


Assuming $_GET['tim'] and database tim is in mysql database date form.

$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';

Jeff

#3 radalin

radalin
  • Members
  • PipPipPip
  • Advanced Member
  • 179 posts

Posted 09 September 2006 - 12:56 AM

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)

Roy Simkes
Yet Another Parkyeri Developer

#4 Muhammad Mustafa

Muhammad Mustafa
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 17 September 2006 - 03:25 PM

sorry guys
but both edits didn't work good with me
down is the whole function, in attach is the whole file that contains this fun.
thanks alot for your efforts
and hope to find a solution sooooon :)


    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 ';">&#8226;&nbsp;';
          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>
';
    }

[attachment deleted by admin]

#5 Muhammad Mustafa

Muhammad Mustafa
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 18 September 2006 - 08:55 PM

heeeey
any body here!!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users