Jump to content

Archived

This topic is now archived and is closed to further replies.

Muhammad Mustafa

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

Recommended Posts

hello all
plz 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 days
i 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 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
[code]limit 7days;[/code]
or in any another way i don't how
plz help me fast
thx :)

Share this post


Link to post
Share on other sites
[quote author=Muhammad Mustafa link=topic=107390.msg430845#msg430845 date=1157744605]
hello all
plz 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

Share this post


Link to post
Share on other sites
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)

Share this post


Link to post
Share on other sites
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 :)


[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 ';">&#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>
';
    }[/code]

[attachment deleted by admin]

Share this post


Link to post
Share on other sites

×

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.