SitePoint Sponsor

User Tag List

Page 6 of 7 FirstFirst ... 234567 LastLast
Results 126 to 150 of 151
  1. #126
    SitePoint Guru hisham777's Avatar
    Join Date
    Dec 2005
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok i tried making the edit process in one function
    its working but not fully do to my limited understanding of
    sessions i guess.
    when i keep one field empty it will givem this warning
    Warning: Cannot modify header information - headers already sent by (output started at E:\Practise\test4\config.php:9) in E:\Practise\test4\edit2.php on line 21


    this is the edit function.

    PHP Code:
      function article_update($article_id $article)
      {
      if(
    $article_id){
           
    $sql "SELECT article_name, summary, author, article_content, notes, date_added, status
          FROM articles WHERE articleID = '"
    .$article_id."'";
      
          
    $res my_query($sql);
          if(
    mysql_num_rows($res) != 0)
          {
              
    $num mysql_fetch_assoc($res);
              return 
    $num;
          }
          else
              return 
    false;
      }
      
      elseif(
    $article){
      
      if(empty(
    $article["article_name"]))
          {
              
    $_SESSION["error"] = "Please enter The Article Name";
              return 
    false;
          }
          else if(empty(
    $article["summary"]))
          {
              
    $_SESSION["error"] = "Please enter a summary";
              return 
    false;
          }
          else if(empty(
    $article["article_content"]))
          {
              
    $_SESSION["error"] = "Please enter a content";
              return 
    false;
          }
          
    $sql "UPDATE articles SET";
          
    $sql .=" article_name = '".$article["article_name"]."'";
          
    $sql .=", summary = '".$article["summary"]."'";
          
    $sql .=", author = '".$article["author"]."'";
          
    $sql .=", article_content = '".$article["article_content"]."'";
          
    $sql .=", notes = '".$article["notes"]."'";
          
    $sql .=", status = '".$article["status"]."' WHERE articleID = '".$article["articleID"]."'"
          
    my_query($sql);
          return 
    true;
          }
          return 
    true;
      } 

    and this is the edit1.php form
    PHP Code:
      <?php
      
    include_once "common.php";
      
    $article_id $_GET['article_ID'];
      
    $article article_update($article_id NULL);
      if(!
    $article)
      {
        echo 
    "article doesn't exist";
      }
      else
      {
      echo 
    '<html><body>
      
      <form action="edit2.php" method="post">
        <p>
          <input name="articleID" type="hidden" id="articleID" value="'
    ;
          echo 
    $article_id;
          echo 
    ' "/>
          <br />
          Article Name <br />
          <input name="articlename" type="text" id="articlename" value="'
    ;
          echo 
    $article["article_name"];
          echo 
    ' " size="80" maxlength="80" />
          <br />
          Summary <br />
          <input name="summary" type="text" id="summary" value="'
    ;
          echo 
    $article["summary"];
          echo 
    ' "size="80" />
          <br />
          Author <br />
          <input name="author" type="text" id="author" value="'
    ;
          echo 
    $article["author"];
          echo 
    '" size="80" maxlength="30" />
          <br />
        Article Content </p>
        <p>
          <textarea name="articlecontent" cols="80" rows="7" id="articlecontent">'
    ;
          echo 
    $article["article_content"];
          echo 
    '</textarea>
          <br />
          <br />
          Notes <br />
          <input name="notes" type="text" id="notes" value="'
    ;
          echo 
    $article["notes"];
          echo 
    '" size="80" maxlength="300" />
          <br />
          Date Posted <br />
          <input name="date" type="text" id="date" value="'
    ;
          echo 
    $article["date_added"];
          echo 
    '" size="80" maxlength="30" />
          <br />
          Status <br />
          <input name="status" type="text" id="status" value="'
    ;
          echo 
    $article["status"];
          echo 
    '" size="7" maxlength="80" />
          <br />
          <input name="" type="submit" value="Submit" />
        </p>
      </form>
      </body>
      </html>'
    ;
      }
      
      
    ?>
    and the edit2.php
    PHP Code:
      <?php 
      
    include_once "common.php";
      
          
    $article["articleID"]   = $_POST['articleID'];
          
    $article["article_name"]   = $_POST['articlename'];
          
    $article["summary"] = $_POST['summary'];
          
    $article["author"]   = $_POST['author'];
          
    $article["article_content"] = $_POST['articlecontent'];
          
    $article["notes"] = $_POST['notes'];
          
    $article["status"] = $_POST['status'];
          if(
    article_update(NULL $article))
          {
              echo 
    "Ok";
              
    //success
              //do whatever you want to do on succes
          
    }
          else
          {
          
    //error
          
    $_SESSION["article"] = $article;
              
    header("Location: edit1.php");
          }
          
          
    ?>
    i hope its a right way to impliment ?
    there is also another way (i think ) is to call function article_read($article_id, $frontend = false)

    from function
    article_update($article_id , $article)
    well i guess its possible, but i wasnt lucky.
    Last edited by hisham777; Mar 31, 2006 at 20:23.

  2. #127
    SitePoint Evangelist
    Join Date
    Jun 2003
    Location
    Melbourne, Australia
    Posts
    440
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by jelena
    I agree with you, but the only problem you don't see here is that he is struggling with building basic functions, and besides what will he have to expend in 6 months if he doesn't build simple system now? (this is a theoretical question)
    When I started with PHP, I made the mistake of focussing way too much on the minutiae of php functions rather than on the task I was trying to achieve. Of course, it's easy to say that now, but I really think I spent a lot of time chasing my tail.
    Best aproach for learing I've experienced so far is STEP BY STEP one.
    But I think we'd probably disagree on what those steps would be. I'd say learn php's native functions and how to use them as you need to. There's one caveat to that: if you don't understand really basic stuff like types (arrays, string, integers, objects, etc.) and language constructs, flow control, etc. then you really do have to start from first principles.
    Quote Originally Posted by jelena
    Anyway, I don't want this beautiful thread to go offtopic. Please, if you'd like to disccuss OO, take a look at PHP Application Design forum.
    I hang out on that forum much more than here, but thanks for the recommendation... for anyone else who might be intrigued by the possibilities. Besides OOP is taken for granted there; the forum is not really aboout learning OOP per se, and more about ways of using objects and making them interact. You'll see the term 'design patterns' a lot.

    I don't think that describing the way that a function (or a class method) might be used is off-topic. It seems to me that so many of the posts in this thread are concerned with minutiae that the bigger picture -- that is, the purpose of the script -- is being obscured.

    Just as an example, I think what hisham777 wants to do is something like this:

    Core operations:
    List articles
    Read a single article
    Create a new article -> add the new article
    Edit an article -> update the article
    Delete an article

    There's seven functions right there:
    PHP Code:
    article_list()
    article_read($article_id)
    article_new()
    article_add()
    article_edit($article_id)
    article_update($article_id)
    article_delete($article_id
    Now start to flesh out those functions, again using pseudo-code. For example, we've already decided that we want to use a database as a repository for the articles, so we're going to have to connect to it:
    PHP Code:
    function article_list() {
        
    connect_to_db($connection_parameters);
        
    $results db_query('SELECT * FROM articles');
        foreach(
    $results as $result) {
            
    //display fields from entry
        
    }

    Then you might concentrate on the functions for connecting to the DB and making a query.

    it does mean that you won't be doing the userful stuff like DB interactions immediately but you can always place echo() statements inside incomplete functions to see that they're being called and that your logic is OK. Each iteration of code adds a little more detail, but the larger picture is maintained. (And I haven't even used classes this time!)
    Last edited by auricle; Apr 1, 2006 at 02:15. Reason: Clarity
    Zealotry is contingent upon 100 posts and addiction 200?

  3. #128
    SitePoint Guru hisham777's Avatar
    Join Date
    Dec 2005
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    clerify the Objectives

    let me start my saying thanks for showing a considirations for this thread.


    Quote Originally Posted by auricle
    When I started with PHP, I made the mistake of focussing way too much on the minutiae of php functions rather than on the task I was trying to achieve. Of course, it's easy to say that now,
    i made a mistake not learning the functions.

    I'd say learn php's native functions and how to use them as you need to.
    am coming to that when i get agood grip of how functions really behave.

    for anyone else who might be intrigued by the possibilities. Besides OOP is taken for granted there; the forum is not really aboout learning OOP per se, and more about ways of using objects and making them interact. You'll see the term 'design patterns' a lot.
    i agree it will be seen a lot.
    but not anyone will understand OOP on the fly.
    and i dont think anybody take OOP for granted its the futere in programming specially for large systems

    It seems to me that so many of the posts in this thread are concerned with minutiae
    thats what i wanted long time ago, and i think alot of biggeners also.
    that the bigger picture -- that is, the purpose of the script -- is being obscured.
    the purpose of me starting this thread at the first place, is to learn the
    basics of constrecting a simple system

    Core operations:
    List articles
    Read a single article
    Create a new article -> add the new article
    Edit an article -> update the article
    Delete an article

    There's seven functions right there:
    PHP Code:
    article_list()
     
    article_read($article_id)
     
    article_new()
     
    article_add()
     
    article_edit($article_id)
     
    article_update($article_id)
     
    article_delete($article_id
    never thought of it this way,
    thanks for the way, it helps diside what functions based on the features
    thanks am learning from you something new as i said am just abiggener who want to enter to the web develpment world.



    and againe i dont know how to thank jelena for making me understand
    a bit about functions (from 0 to a hero in functions ).
    and for her paitiens which alot of developers dont have for begginers (sorry to say that) everybody has his/her reasons.

    one thing to mansion auricle myself and alot of begginers who are reading this thread would love to see the same system features in OO style.

    me i can use both to compaire how OOP is diffrent from Structorer.

  4. #129
    SitePoint Wizard silver trophy Jelena's Avatar
    Join Date
    Feb 2005
    Location
    Universum, 3rd Corner
    Posts
    3,000
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Hey there hisham777:
    Here is an updated version of your article_update function
    PHP Code:
    <?php
    /**
    *
    *    Function updates signle article
    *    It expects an array $article with following elements
    *    article[article_id]
    *           [article_name]
    *           [article_summary]
    *           [article_author]
    *           [article_content]
    *           [article_notes]
    *           [status]
    *    If will perform all checks needed. On error it will set
    *    a session element error and return false.
    *    On success, it will update article and return true.
    *
    *    @param array article - holds article details
    *    @return boolean - returns true or false
    *
    */
    function article_update($article)
    {
      
          if(empty(
    $article["articleID"]))
          {
            
    $_SESSION["error"] = "Article ID isn't defined.";
         return 
    false;
          }
          if(empty(
    $article["article_name"]))
          {
              
    $_SESSION["error"] = "Please enter The Article Name";
              return 
    false;
          }
          if(empty(
    $article["summary"]))
          {
              
    $_SESSION["error"] = "Please enter a summary";
              return 
    false;
          }
          else if(empty(
    $article["article_content"]))
          {
              
    $_SESSION["error"] = "Please enter a content";
              return 
    false;
          }
          
    $sql "UPDATE articles SET";
          
    $sql .=" article_name = '".$article["article_name"]."'";
          
    $sql .=", summary = '".$article["summary"]."'";
          
    $sql .=", author = '".$article["author"]."'";
          
    $sql .=", article_content = '".$article["article_content"]."'";
          
    $sql .=", notes = '".$article["notes"]."'";
          
    $sql .=", status = '".$article["status"]."' WHERE articleID = '".$article["articleID"]."'";
          
    my_query($sql);
          return 
    true;


    ?>
    Now, as for edit2.php I would make it sligtly different. For example, I wouldnt use session here, but something like:
    PHP Code:
    <?php
      
    include_once "common.php";
      
          
    $article["articleID"]   = $_POST['articleID'];
          
    $article["article_name"]   = $_POST['articlename'];
          
    $article["summary"] = $_POST['summary'];
          
    $article["author"]   = $_POST['author'];
          
    $article["article_content"] = $_POST['articlecontent'];
          
    $article["notes"] = $_POST['notes'];
          
    $article["status"] = $_POST['status'];
          if(
    article_update($article))
          {
              echo 
    "Ok";
              
    //success
              //do whatever you want to do on succes
          
    }
          else
          {
          
    //error
              
    header("Location: edit1.php?article_ID=".$article["articleID"]);
          }
          
          
    ?>
    The reason is, what if admin accidantely delete all summary or content of the article. That way, it's better to populate form with original details, then with updated ones.

    As for the warning you are getting, check the config.php and make sure to remove all white spaces in that file, because it's likely that it causes error you are getting.
    -- Jelena --

  5. #130
    SitePoint Guru hisham777's Avatar
    Join Date
    Dec 2005
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi jelena, thanks for replay.

    so using this function
    function article_update($article_id , $article)
    its not advisable ?

    and to get the article all just use this ?
    function article_read($article_id, $frontend = false)

  6. #131
    SitePoint Wizard silver trophy Jelena's Avatar
    Join Date
    Feb 2005
    Location
    Universum, 3rd Corner
    Posts
    3,000
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by hisham777
    hi jelena, thanks for replay.

    so using this function
    function article_update($article_id , $article)
    its not advisable ?
    Well, first part of the function, where you check if article with provided id exists, doesn't make sense. Care to elaborate what you have tried to accomplish?
    Quote Originally Posted by hisham777
    and to get the article all just use this ?
    function article_read($article_id, $frontend = false)
    yes, correct, calling it:
    $article = article_read($article_id);
    No need for providing second parametar for admin usage, as it's optional, and it will be false as we need it.
    -- Jelena --

  7. #132
    SitePoint Guru hisham777's Avatar
    Join Date
    Dec 2005
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you made it clear.

    now i think the next step for me, make the display page (list all articles),
    and the main admin page (simple page with simple statistics).??

    thanks again.

  8. #133
    SitePoint Wizard silver trophy Jelena's Avatar
    Join Date
    Feb 2005
    Location
    Universum, 3rd Corner
    Posts
    3,000
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by hisham777
    you made it clear.

    now i think the next step for me, make the display page (list all articles),
    and the main admin page (simple page with simple statistics).??

    thanks again.
    If you have created delete page in admin, you can now create function that lists all articles in the front end (aproved ones).
    How many articles do you expect? It would be wise to think about per page option.
    -- Jelena --

  9. #134
    SitePoint Guru hisham777's Avatar
    Join Date
    Dec 2005
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok i have never considered the amont of articles.
    but all take something like 50 as an example,
    and list it in pages 10 each.

    i have read an article on phpfreaks about pagination long time ago.
    all i remmember it was good.

  10. #135
    SitePoint Wizard silver trophy Jelena's Avatar
    Join Date
    Feb 2005
    Location
    Universum, 3rd Corner
    Posts
    3,000
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by hisham777
    ok i have never considered the amont of articles.
    but all take something like 50 as an example,
    and list it in pages 10 each.

    i have read an article on phpfreaks about pagination long time ago.
    all i remmember it was good.
    I'll introduce you my way of implementing per page, which doesn't mean it's the best one, but works with me
    -- Jelena --

  11. #136
    SitePoint Guru hisham777's Avatar
    Join Date
    Dec 2005
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i dont get it !!
    am tring to do a loop in a function (is this possible ?)
    i thought of constructing it as simble one first, then all add more
    functions into it.

    the thing is that it fatches one row and display it !!!

    OK, it look like something wrong
    -there must be a loop.
    -but ist in the listrecord.php
    -or in the functions.php ???

    [PHP]
    function list_records($status)
    {
    $sql = "SELECT * FROM articles";
    //$sql .= " ORDER BY articleID DESC LIMIT 10";
    //if($status != ""){
    // $sql .= " WHERE Status = '".$status."'";
    $res = my_query($sql);
    if(mysql_num_rows($res) != 0)
    {
    //$num = mysql_fetch_assoc($res);
    while($num = mysql_fetch_assoc($res))
    {
    return $num;
    }
    }
    else
    {
    return false;
    }
    }
    [PHP]

  12. #137
    SitePoint Wizard silver trophy Jelena's Avatar
    Join Date
    Feb 2005
    Location
    Universum, 3rd Corner
    Posts
    3,000
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Revised version of your function
    PHP Code:
    function list_records($status)
    {
        
    $sql "SELECT * FROM articles";
        
    $sql .= " WHERE status = '".$status."'";

        
    $res my_query($sql);
        if(
    mysql_num_rows($res) != 0)
        {
            while(
    $num mysql_fetch_assoc($res))
            {
                
    $data[] = $num;
            }
            return 
    $data;
        }
        else
        {
            return 
    false;
        }

    -- Jelena --

  13. #138
    SitePoint Guru hisham777's Avatar
    Join Date
    Dec 2005
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    now am getting this notes

    Notice: Undefined index: article_name in E:\Practise\test4\listrecords.php on line 18

  14. #139
    SitePoint Guru hisham777's Avatar
    Join Date
    Dec 2005
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok i did something almost crashed my system

  15. #140
    SitePoint Wizard silver trophy Jelena's Avatar
    Join Date
    Feb 2005
    Location
    Universum, 3rd Corner
    Posts
    3,000
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by hisham777
    now am getting this notes

    Notice: Undefined index: article_name in E:\Practise\test4\listrecords.php on line 18
    Could you post listrecord.php please?
    -- Jelena --

  16. #141
    SitePoint Guru hisham777's Avatar
    Join Date
    Dec 2005
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    can i use a statement like this ???
    while($data = list_records($status))

  17. #142
    SitePoint Guru hisham777's Avatar
    Join Date
    Dec 2005
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the new code
    PHP Code:
    <?php
    include_once "common.php";
    $status $_POST["status"];
    $data list_records($status);


    echo 
    '
    <table width="720" border="1" cellpadding="0" cellspacing="0">
    <tr>
        <td>Title</td>
        <td>Date</td>
        <td>Author</td>
        <td>Action</td>
    </tr>'
    ;
        
       while(
    $data list_records($status))
    {

        
    ?>
        <tr>
            <td><?php echo $array["article_name"];?></td>
            <td><?php echo $array["date_added"];?></td>
            <td><?php echo $array["author"];?></td>
            <td><a href="userread.php?article_ID=<?php echo $array["articleID"] ;?>">View</a> |
            <a href="edit1.php?article_ID=<?php echo $array["articleID"] ;?>">Edit</a> |
            <a href="delete.php?article_ID=<?php echo $array["articleID"] ;?>">Delete</a>
            </td>
        </tr>
    <?php    
    }?>
    </table>

  18. #143
    SitePoint Wizard silver trophy Jelena's Avatar
    Join Date
    Feb 2005
    Location
    Universum, 3rd Corner
    Posts
    3,000
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:


    <?php
    include_once "common.php";
    $status $_POST["status"];
    $data list_records($status);


    echo 
    '
    <table width="720" border="1" cellpadding="0" cellspacing="0">
    <tr>
        <td>Title</td>
        <td>Date</td>
        <td>Author</td>
        <td>Action</td>
    </tr>'
    ;
    for(
    $i=0$i<count($data);$i++)
    {
        
    ?>
        <tr>
            <td><?php echo $data[$i]["article_name"];?></td>
            <td><?php echo $data[$i]["date_added"];?></td>
            <td><?php echo $data[$i]["author"];?></td>
            <td>links</td>
        </tr>
    <?php
    }
    ?>
    </table>
    -- Jelena --

  19. #144
    SitePoint Guru hisham777's Avatar
    Join Date
    Dec 2005
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
      for($i=0$i<count($data);$i++) 
    at my self
    how i never thought of it.
    may be Coz my head stock with the functions

  20. #145
    SitePoint Guru hisham777's Avatar
    Join Date
    Dec 2005
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    now its fully functional(major features).
    all the credit go to you jelena.
    thanks

  21. #146
    SitePoint Guru hisham777's Avatar
    Join Date
    Dec 2005
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    now i need to think of the last few thing should be added.
    1-pagination.
    2-simple statistics.
    3-figure out a method to secure the admin side.
    any comments on the above.?

    then the user side should be prety simple i guess.

  22. #147
    SitePoint Guru hisham777's Avatar
    Join Date
    Dec 2005
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i call it a night for my self.
    its my sleeping time i have to wake up early.
    thanks jelena,
    and thanks for all the members who are viewing the thread

  23. #148
    SitePoint Wizard silver trophy Jelena's Avatar
    Join Date
    Feb 2005
    Location
    Universum, 3rd Corner
    Posts
    3,000
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Here is the my way of handling per page option. I will demonstrate it:
    This is an updated version of list_records function:
    PHP Code:
    function list_records($status, &$ctrl)
    {
        
    $sql "SELECT COUNT(*) FROM articles";
        
    $sql .= " WHERE status = '".$status."'";

        
    $result my_query($sql);
        if(
    mysql_num_rows($result) == 0)
            return 
    false;

        list(
    $total) = mysql_fetch_row($result);

        if(
    $total == 0)
            return 
    false;

        
    //check if we already have Page and PerPage elements
        
    if(!isset($ctrl["PerPage"]))
            
    $ctrl["PerPage"] = "10";
        if(!isset(
    $ctrl["Page"]))
            
    $ctrl["Page"] = 1;

        
    //create couple new vars so it is easier to read
        
    $page $ctrl["Page"];
        
    $perpage $ctrl["PerPage"];


        
    //create new control array
        
    $tmp_ctrl = array(
            
    "Total"        => $total,
            
    "PerPage"    => $perpage,
            
    "Start"        => (($page-1)*$perpage),
            
    "HasNext"       => ($page $perpage $total true false),
            
    "HasPrev"       => ($page true false),
            
    "NextPage"      => ($page+1),
            
    "PrevPage"      => ($page-1),
            
    "Page"          => ($page),
            
    "TotalPages"    => (ceil($total/$perpage))
            );

        
    //save created control array
        
    $ctrl $tmp_ctrl;
        
        
    $sql "SELECT article_id, article_name, summary, article_content, date_added FROM articles";
        
    $sql .= " WHERE status = '".$status."'";
        
    $sql .= " LIMIT ".(($ctrl["Page"]-1)*$ctrl["PerPage"]).", ".$ctrl["PerPage"];
        
        
    $result my_query($sql);
        
        while(
    $tmp mysql_fetch_assoc($result))
        {
            
    $data[] = $tmp;
        }
        
        return 
    $data;

    and an updated version of page which displays records:
    PHP Code:
    <?php
    include_once "common.php";
    $status $_GET["status"];
    $page $_GET["page"];


    if(isset(
    $page) && $page != "")
        
    $ctrl["Page"] = $page;

    $data list_records($status$ctrl);

    $ctrl["DisplayPages"] = array();
    if(isset(
    $ctrl["TotalPages"]))
    {
        for(
    $i=0$i<$ctrl["TotalPages"]; $i++)
            
    $ctrl["DisplayPages"][] = $i;
    }    

    echo 
    '
    <table width="720" border="1" cellpadding="0" cellspacing="0">
    <tr>
        <td>Title</td>
        <td>Date</td>
        <td>Author</td>
        <td>Action</td>
    </tr>'
    ;
    for(
    $i=0$i<count($data);$i++)
    {
        
    ?>
        <tr>
            <td><?php echo $data[$i]["article_name"];?></td>
            <td><?php echo $data[$i]["date_added"];?></td>
            <td><?php echo $data[$i]["author"];?></td>
            <td>links</td>
        </tr>
    <?php
    }
    ?>
    </table>
    <br />
    <?php

    if ($ctrl["HasPrev"])
    {
        
    ?>
        <a href="you_page_name.php?status=<?php echo $status;?>&page=<?php echo $ctrl["PrevPage"];?>">&laquo; prev</a>
        <?php
    }
    else
    {
        
    ?>
        <span style="color:#afafaf;">&laquo; prev</span>
        <?php
    }
    for(
    $i=0$i count($ctrl["DisplayPages"]); $i++)
    {
        if((
    $i 1) == $ctrl["Page"])
        {
            echo 
    $i 1;
        }
        else
        {
            
    ?>
            <a href="you_page_name.php?status=<?php echo $status;?>&page=<?php echo $i+1;?>"><?php echo $i+1;?>
            <?php
        
    }
    }
    //for
    if($ctr["HasNext"])
    {
        
    ?>
        <a href="your_page_name.php?status=<?php echo $status;?>&&page=<?php echo $ctrl["NextPage"];?>">next &raquo;</a>
        <?php
    }
    else
    {
        
    ?>
        <span style="color:#afafaf;">next &raquo;</span>
        <?php
    }
    ?>
    As you can see, the major change has to do with introducing new array $ctrl which contains all per page elements. Read code carefully, and let me know which part is confusing.

    I haven't fully tested this code. I wrote it with no checks, so it might come with some errors, but it will show the basic concept.

    Also, I call other members to comment on this method.

    As for the statistics, what kind of statistics you'd like?
    Last edited by jelena; Apr 6, 2006 at 07:36.
    -- Jelena --

  24. #149
    SitePoint Guru hisham777's Avatar
    Join Date
    Dec 2005
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi there
    its nice to learn from a developer like you.
    the code its working.
    i just did inetial test to it.
    i think when this is done it will be good having it on line.
    for bigenners to learn from it.

    as for the statistics i thought of something just to dominstrate
    how statistics page constrected, i dont know.
    may be something simple about,
    how many records in the DB
    how many records approved
    how many records pendding aprovale
    or may be click counter....etc

    anybody has a suggestion please
    post some.


    thanks

  25. #150
    SitePoint Wizard silver trophy Jelena's Avatar
    Join Date
    Feb 2005
    Location
    Universum, 3rd Corner
    Posts
    3,000
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    As for the click counter, the simplest way would be to add one more additional field 'Cliks' in db table , which will be updated each time an article gets view. Not exactly each time, but each time someone loads it for the first time.

    In other words, you could set a session with id of the article visitor has viewed, and check if session isn't set, it means visitor is loading article for the first time, and you should update the Clicks field. If session has article id, no updated required.

    Those this make sense?

    As for the showing how many articles (active, pending) you have, simple count will do the trick.
    -- Jelena --


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •