SitePoint Sponsor

User Tag List

Page 5 of 7 FirstFirst 1234567 LastLast
Results 101 to 125 of 151
  1. #101
    SitePoint Guru hisham777's Avatar
    Join Date
    Dec 2005
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by jelena
    auricle, I haven't suggested OO aproach, because hisham777 is a beginner. He would be confused to jump into OO right from the beginning. From my experience, people have hard time to go straight with classes if they haven't programmed before. I'm not sure if hisham777 programmed before, but from what I've seen, I would say no. He is having hard times to get along with things I have posted, although he is a great student so far and quick learner.

    Also, OO aproach on very simple systems like the one hi is building is in qustion.
    thanks jelena for the consideration, its true i never programmed before
    exept for C++, and it was just introductions if you know what i mean
    (input, output, control statment(if, else, while and for)) and simple understanding of pointers, as will as the basic use of functions,
    then i stoped for almost 1 year and a half,
    i got an internet connection last year, reading online about almost everything, webdevelopment, buissnes, name it exept politics
    so i saw my self really behind in IT industry (am an IT student).

    so a started from then.
    reading about OS (windows, Linux)
    business and IT (ecommers)
    now am into webdevelopment (and i like it).

    in general i support open sorce, i like anything realated to open source.

    so my first chose was PHP and Mysql.
    i almost gave up
    i moved to HTML\xHTML the CSS2 (i love it)

    now am back to PHP and MYSQL (wish me luck)

    then may be a bit of Java Script

    then to OO with PHP
    so i hope i can achive this before i gratuate which is by year end.

  2. #102
    SitePoint Guru hisham777's Avatar
    Join Date
    Dec 2005
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    please i have this silly Q.

    if am passing a variable through url and i want the funnction to get the variable
    and use it then return a instruction
    how to make the function get the variable silly isn't ?

  3. #103
    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 auricle
    Why? I venture to suggest that what I've written is much more illustrative of what he's trying to achieve than any example you've posted, especially where you've mixed in HTML, either by echo()-ing or delimiting PHP code with '<?php' and '?>'. Now, much of what you did post, such as showing the database queries, is probably what I'd put inside class methods, but it doesn't show how it's used. And consider a typical scenario: when you have to change the features of the web site in 6 months' time, how much of your code will you be able to follow and how quickly? Using functions reduces the problem, but OOP does that even more.
    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)

    One cannot learn everything in one week. As I already mentioned in my posts here, there is lot more in php.

    I've had students before. I have my own aproach of teaching. Best aproach for learing I've experienced so far is STEP BY STEP one.

    For example, before jumping into classes, I would rather teach him about code separation.

    Quote Originally Posted by auricle
    Besides, there are others following this thread and they might see the benefits too.
    Once again, I'm not saying your aproach is bad, I'm just saying it's not for the beginner.

    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.
    -- Jelena --

  4. #104
    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
    please i have this silly Q.

    if am passing a variable through url and i want the funnction to get the variable
    and use it then return a instruction
    how to make the function get the variable silly isn't ?
    Let's say you have a simple function which will echo a variable like:
    PHP Code:
    funciton echo_me($variable)
    {
      if(
    $variable != "")
      {
           echo 
    $variable;
    }

    Now, to grab a variable from URL, you will have to access it through $_GET array. If an url looks like: http://www.example.com/index.php?var="something" we will grab it like:
    PHP Code:
    $var $_GET["var"]; 
    Now to use a function to echo it, we will call it this way:
    PHP Code:
    echo_me($var); 
    Or, if I understood you well, you would want something like:
    PHP Code:
    $var $_GET["var"];

    $new return_me($var);

    function 
    return_me($variable)
    {
       return 
    $variable;

    Or lets just post concrete code you are having problems with.
    -- Jelena --

  5. #105
    SitePoint Guru hisham777's Avatar
    Join Date
    Dec 2005
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok after trying i came up with this, am not sure how good it is but its working

    i added a new function in the functions.php
    PHP Code:
    function article_delete($article_id)
    {

    $sql "DELETE FROM articles WHERE articleID = '".$article_id."'";

    my_query($sql);
        return 
    true;


    and the delete.php

    PHP Code:
    include_once "common.php";


    $article_id $_GET['article_ID'];
    if(
    article_delete($article_id))
        {
            echo 
    "Ok";
          }
        else
        {
        
        echo 
    "error ";
        echo 
    "Article,,,ID : ".$article_id;    
        } 

  6. #106
    SitePoint Guru hisham777's Avatar
    Join Date
    Dec 2005
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    am not eve sure if its correct ????

  7. #107
    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
    am not eve sure if its correct ????
    It is

    With one only modification:
    You don't need an if here
    PHP Code:
    $article_id $_GET['article_ID'];
    if(
    article_delete($article_id))
        {
            echo 
    "Ok";
          }
        else
        {
        
        echo 
    "error ";
        echo 
    "Article,,,ID : ".$article_id;    
        } 
    Because article_delete function will always return true. The only situation when it will fail is when my_query failed, but in that situation, it will call die() and stop executing code.
    So, it would be just fine to do:
    PHP Code:
    include_once "common.php";

    $article_id $_GET['article_ID'];
    article_delete($article_id)
    echo 
    "Deleted"
    -- Jelena --

  8. #108
    SitePoint Guru hisham777's Avatar
    Join Date
    Dec 2005
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by jelena
    So, it would be just fine to do:
    PHP Code:
     include_once "common.php";
     
     
    $article_id $_GET['article_ID'];
     
    article_delete($article_id)
     echo 
    "Deleted"
    so based what you posted about functions
    and this post.

    article_delete($article_id)
    her am calling the function in the delete.php
    and the function will take the value of $article_id
    and process it in the function then return ok.
    the compiler will go to the next line and echo "Deleted";?

    if its correct then am starting to pick up functions
    if not correct i have to read a bit about the compiler behaviour.

  9. #109
    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
    so based what you posted about functions
    and this post.

    article_delete($article_id)
    her am calling the function in the delete.php
    and the function will take the value of $article_id
    and process it in the function then return ok.
    the compiler will go to the next line and echo "Deleted";?

    if its correct then am starting to pick up functions
    if not correct i have to read a bit about the compiler behaviour.
    Yes, it will return true on success, but as you are not assigning what the function returns to any variable, then the next line/command gets executed.
    As I explained in previous post, we don't need to assign what function returns to a variable, as it will always return true.
    -- Jelena --

  10. #110
    SitePoint Guru hisham777's Avatar
    Join Date
    Dec 2005
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok thats bring me to another Q.
    now am trying to code afunction to read article.
    with my basic understanding. this is the style of the function

    name the function

    function article_read($article_id)

    the SQL quiry
    $sql = "SELECT FROM articles WHERE articleID = '".$article_id."'";

    now here is the confution, can i still use what i usally use

    $res = mysql_query($sql);
    $num = mysql_fetch_assoc($res);
    my_query($sql);


    but it return the $num like this

    return $num;

  11. #111
    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)
    Yes, basically, that's correct.
    PHP Code:
    function article_read($article_id)
    {
        
    $sql "SELECT article_name, summarty, date_added, article_content FROM articles WHERE articleID = '".$article_id."'";

        
    $res mysql_query($sql);
        if(
    mysql_num_rows($res) != 0)
        {
            
    $num mysql_fetch_assoc($res);
            return 
    $num;
        }
        else
            return 
    false;

    And you'll call function like:
    PHP Code:
    $article article_read($article_id); 
    Now, variable $article is either false, or contains an array with all article details.
    When it's false, that means that article with provided ID doesn't exist.
    So, before displaying it, we would perform a check
    PHP Code:
    if(!$article)
    {
      echo 
    "article doesn't exist";
    }
    else
    {
     
    //dispay article

    -- Jelena --

  12. #112
    SitePoint Guru hisham777's Avatar
    Join Date
    Dec 2005
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    a small change to this
    Quote Originally Posted by jelena
    PHP Code:
     function article_read($article_id)
     {
         
    $sql "SELECT article_name, summarty, date_added, article_content FROM articles WHERE articleID = '".$article_id."'";
     
    //to
    $sql "SELECT article_name, summary, author, article_content, notes, date_added, status
        FROM articles WHERE articleID = '"
    .$article_id."'";

         
    $res mysql_query($sql);
    //to 
        
    $res my_query($sql);
         if(
    mysql_num_rows($res) != 0)
         {
             
    $num mysql_fetch_assoc($res);
             return 
    $num;
         }
         else
             return 
    false;
     } 
    and the display.php
    PHP Code:
    include_once "common.php";

    $article_id $_GET['article_ID'];
    $article article_read($article_id);
    if(!
    $article)
    {
      echo 
    "article doesn't exist";
    }
    else
    {
    echo 
    '<table width="720" border="1" cellpadding="0" cellspacing="0">
      <!--DWLayoutTable-->
      <tr>
        <td width="181" height="30" valign="top">Name </td>
        <td width="539" valign="top">'
    ;
        echo 
    $article["article_name"];
        echo 
    '</td>
      </tr>
      <tr>
        <td height="30" valign="top">Summary</td>
        <td valign="top">'
    ;
        echo 
    $article["summary"];
        echo 
    '</td>
      </tr>
      <tr>
        <td height="30" valign="top">Author</td>
        <td valign="top">'
    ;
        echo 
    $article["author"];
        echo 
    '</td>
      </tr>
      <tr>
        <td height="30" valign="top">Content</td>
        <td rowspan="2" valign="top">'
    ;
        echo 
    $article["article_content"];
        echo 
    '</td>
      </tr>
      <tr>
        <td height="190">&nbsp;</td>
      </tr>
      <tr>
        <td height="42" valign="top">Note</td>
        <td valign="top">'
    ;
        echo 
    $article["notes"];
        echo 
    '</td>
      </tr>
      
      <tr>
        <td height="30" valign="top">Date added </td>
        <td valign="top">'
    ;
        echo 
    $article["date_added"];
        echo 
    '</td>
      </tr>
      <tr>
        <td height="30" valign="top">Status</td>
        <td valign="top">'
    ;
        echo 
    $article["status"];
        echo 
    '</td>
      </tr>
    </table>'
    ;

    //dispay article

    thanks to you jelena

  13. #113
    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)
    Now, let make function flexible for usage in frontend and admin zone:
    PHP Code:
    function article_read($article_id$frontend false)
    {

        
    $sql "SELECT article_name, summary, author, article_content, notes, date_added, status"
        
    $sql .= " FROM articles"
        
    $sql .= " WHERE articleID = '".$article_id."'";
        if(
    $frontend)
            
    $sql .= " AND Status = '1'";

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

    $frontend is an optional parametar for the above function, which means that function could be call with or without it. When it's called without it (in admin zone), it will assign false to $frontend by default.

    Now when calling funtion in frontend, we will call it this way:
    PHP Code:
    $article article_read($article_idtrue
    This way we are sure that visitors don't have access to articles which are not approved.
    This is also a good example for seeing purpose of writting functions.
    Last edited by jelena; Mar 31, 2006 at 06:51. Reason: added more explanations
    -- Jelena --

  14. #114
    SitePoint Guru hisham777's Avatar
    Join Date
    Dec 2005
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    cooooool never thought of the display yat though. am more on the admin side still.

    but the function its Wow, it make me realize what i was missing in programming

    now i have to think how to write a function that edit the articles(am excited).

  15. #115
    SitePoint Guru hisham777's Avatar
    Join Date
    Dec 2005
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wo Wo Wo WO, sorry i did not notice this.
    Quote Originally Posted by jelena
    Now, let make function flexible for usage in frontend and admin zone:

  16. #116
    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 i have to think how to write a function that edit the articles(am excited).
    Well, function for editing articles will be similar to function which adds article, with the difference in query and that it should also have article_id available.
    Let me know if you are stuck somewhere.

    I don't want to write it for you, I'd like to see you try first without help
    -- Jelena --

  17. #117
    SitePoint Guru hisham777's Avatar
    Join Date
    Dec 2005
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok, i made use of the function article_read($article_id) to fatch the article
    and diplay it in the form, and its working.

    ist ok to make use of the same function or you have something in mind ?
    PHP Code:
    <?php
    include_once "common.php";
    $article_id $_GET['article_ID'];
    $article article_read($article_id);
    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["articleID"];
        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>'
    ;
    }

    ?>

  18. #118
    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)
    I would create a separate function for editing articles, but basically you can copy/paste all checks from function for adding articles..
    I would also make Status as a checkbox (but only if you don't have intention to add more statuses, if you do, then I would use select).
    -- Jelena --

  19. #119
    SitePoint Guru hisham777's Avatar
    Join Date
    Dec 2005
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    there is a special way to handle the hidden fields !!??
    can i use the same way i use with text fields ?

  20. #120
    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
    there is a special way to handle the hidden fields !!??
    can i use the same way i use with text fields ?
    No, there is no a special way of handling hidden fields and yes, you may use them the same way as text fields.
    -- Jelena --

  21. #121
    SitePoint Guru hisham777's Avatar
    Join Date
    Dec 2005
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i know its not what you expected
    ok i dont know if its the right way?

    but there is an error. its my best at the moment.
    9hours stright infront of the computer.
    the function .
    PHP Code:
      function article_update($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"]."'";
          
    $sql "WHERE articleID = '".$article["articleID"]."'";
          
    my_query($sql);
          return 
    true;
      } 

    the error

    Database error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'summary = 'mvbm ' author = 'vbmcvbmcv' article_content = ',n,cbn,nbbn,ddaw' note' at line 1

    Query was (UPDATE articles SET article_name = 'bvnvb ' summary = 'mvbm ' author = 'vbmcvbmcv' article_content = ',n,cbn,nbbn,ddaw' notes = 'bcn,cbn,bn,' status = '0') in file

  22. #122
    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:
          $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"]."'";
          
    $sql .= " WHERE articleID = '".$article["articleID"]."'"
    Space before WHERE, no =, and no commas
    -- Jelena --

  23. #123
    SitePoint Guru hisham777's Avatar
    Join Date
    Dec 2005
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i change it to this
    PHP Code:
    $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"]."'"
    and i get this error
    Database error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'summary = 'kjgykjdyk ' author = 'jgykfgtyk' article_content = 'gykgkgkghkbjkkjjk' at line 1

    Query was (UPDATE articles SET article_name = 'l;;;udyjudy ' summary = 'kjgykjdyk ' author = 'jgykfgtyk' article_content = 'gykgkgkghkbjkkjjkn,' notes = 'hkghkkhk' status = '0' WHERE articleID = '32 ') in file

  24. #124
    SitePoint Guru hisham777's Avatar
    Join Date
    Dec 2005
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    better still, am to tired, i think i should go to sleep.

    and 2moro morning i shall construct the function from scratch.

    any advice to consider before i start doing it again?
    as for good night and thanks jelena.

  25. #125
    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)
    Still no commas where you should have them in your query:
    PHP Code:
     $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"]."'"
    -- 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
  •