SitePoint Sponsor

User Tag List

Page 4 of 7 FirstFirst 1234567 LastLast
Results 76 to 100 of 151
  1. #76
    SitePoint Guru hisham777's Avatar
    Join Date
    Dec 2005
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    about the code i need time to digest.

  2. #77
    SitePoint Guru hisham777's Avatar
    Join Date
    Dec 2005
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I used the code to add record using the first form you did.
    am geting error.
    Parse error: parse error, unexpected T_GLOBAL, expecting '{' in E:\Practise\test3\common.php on line 16


    PHP Code:
    function my_query($sql)
    /*error*/    GLOBAL $_SERVER["PHP_SELF"];
                    GLOBAL 
    $db

  3. #78
    SitePoint Wizard silver trophy Jelena's Avatar
    Join Date
    Feb 2005
    Location
    Universum, 3rd Corner
    Posts
    3,001
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    function my_query($sql)
    {
    //note this ;)
                    
    GLOBAL $_SERVER["PHP_SELF"];
                    GLOBAL 
    $db
    -- Jelena --

  4. #79
    SitePoint Wizard silver trophy Jelena's Avatar
    Join Date
    Feb 2005
    Location
    Universum, 3rd Corner
    Posts
    3,001
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by hisham777
    clean Code, it make me realise am at level 7 of 100 in PHP
    but thats will not stop me.
    Trust me, code can be even more cleaner
    Quote Originally Posted by hisham777
    my idea to have one persone that admin the articles, and what
    i understand from htacces its for apache servers, what about
    IIS, if can do in ISS as well please point me to a tutorial.
    i dare not ask you more about article system after i saw your code
    you done alot .
    As far as I know, you can do it through control panel on your server. I don't use Windows server so, I'm not good enough to advise you on that, but it should be fairly simple.

    Btw, why windows hosting?
    -- Jelena --

  5. #80
    SitePoint Guru hisham777's Avatar
    Join Date
    Dec 2005
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    its not windows hosting
    am using my computer to learn (localhost) I know its better to use linux
    soon all migrate am geting sick with Micros**k .

    i dont have hosting at the moment planning to buy one soon.
    and about ,htacces IIS does not support it i just got this info
    from a site.

  6. #81
    SitePoint Guru hisham777's Avatar
    Join Date
    Dec 2005
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sorry, what do you mean by
    PHP Code:
    {//note this ;) 

  7. #82
    SitePoint Wizard silver trophy Jelena's Avatar
    Join Date
    Feb 2005
    Location
    Universum, 3rd Corner
    Posts
    3,001
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by hisham777
    sorry, what do you mean by
    PHP Code:
    {//note this ;) 
    You have to add { where I have placed it.
    -- Jelena --

  8. #83
    SitePoint Wizard silver trophy Jelena's Avatar
    Join Date
    Feb 2005
    Location
    Universum, 3rd Corner
    Posts
    3,001
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by hisham777
    its not windows hosting
    am using my computer to learn (localhost) I know its better to use linux
    soon all migrate am geting sick with Micros**k .

    i dont have hosting at the moment planning to buy one soon.
    and about ,htacces IIS does not support it i just got this info
    from a site.
    Then no need to worry, you will setup htaccess as soon as you find a proper hosting. I'm developing under Windows, too
    -- Jelena --

  9. #84
    SitePoint Guru hisham777's Avatar
    Join Date
    Dec 2005
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    may i ask what editer do you use ?

  10. #85
    SitePoint Guru hisham777's Avatar
    Join Date
    Dec 2005
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    now am geting this error
    Parse error: parse error, unexpected '[', expecting ',' or ';' in E:\Practise\test3\common.php on line 15

  11. #86
    SitePoint Wizard silver trophy Jelena's Avatar
    Join Date
    Feb 2005
    Location
    Universum, 3rd Corner
    Posts
    3,001
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Revised version of common.php
    PHP Code:
    <?php
    include_once "config.php";
    include_once 
    "functions.php";
    session_start();

    //connect to the base
    if(!($db = @mysql_pconnect(BASESERVERBASEUSERBASEPASS)))    //connect to base host
        
    die("Cannot connect to the base server.");
    if(!@
    mysql_select_db(BASENAME,$db))    //select base
        
    die("Database doesn't exist!!!");
        
        
    //common functions
    function my_query($sql)
    {
        GLOBAL 
    $PHP_SELF;
        GLOBAL 
    $db;

        if((
    $result = @mysql_query($sql,$db)) == 0)      //Execute SQL query
        
    {
            echo 
    "\n<hr>Database error: <strong>".mysql_error()."</strong><br /><br />\n";
            die(
    "Query was (<strong>$sql</strong>) in file <strong>".$PHP_SELF."</strong>");
        }
        else
            return 
    $result;
    }
    ?>
    Sorry, I haven't checked for syntax errors.
    -- Jelena --

  12. #87
    SitePoint Wizard silver trophy Jelena's Avatar
    Join Date
    Feb 2005
    Location
    Universum, 3rd Corner
    Posts
    3,001
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by hisham777
    may i ask what editer do you use ?
    I use Zend mostly, but code I have wrote here I did in UltraEdit, that is the main reason I haven't checked for syntax errors. Zend marka parts of code that have syntax errors, so it's much easier to fix them.
    -- Jelena --

  13. #88
    SitePoint Guru hisham777's Avatar
    Join Date
    Dec 2005
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok i changed the the code.

    i got error session cant start

    so i repliced session_start at the top, worked
    but i got massage
    Cannot connect to the base server.

    so i changed the config.php from

    PHP Code:
    define("DBHOST","localhost");
    define("DBUSER","roots");
    define("DBPASS""555456");
    define("DBNAME","site"); 
    To
    PHP Code:
    define("BASESERVER","localhost");
    define("BASEUSER","roots");
    define("BASEPASS""555456");
    define("BASENAME","site"); 

    Its Working Cool

  14. #89
    SitePoint Wizard silver trophy Jelena's Avatar
    Join Date
    Feb 2005
    Location
    Universum, 3rd Corner
    Posts
    3,001
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Well spotted! You are getting into it pretty fast
    -- Jelena --

  15. #90
    SitePoint Guru hisham777's Avatar
    Join Date
    Dec 2005
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do you mean Zend Studio ?
    you have to pay for that !?

  16. #91
    SitePoint Wizard silver trophy Jelena's Avatar
    Join Date
    Feb 2005
    Location
    Universum, 3rd Corner
    Posts
    3,001
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by hisham777
    Do you mean Zend Studio ?
    you have to pay for that !?
    Yes, that is exactly what I mean . And yes again, you have to pay for it

    Check out this thread: http://www.sitepoint.com/forums/showthread.php?t=346481, maybe you'll find something that suit you.

    Also, search PHP forum for PHP editors. We have disccussed them so many times before.
    -- Jelena --

  17. #92
    SitePoint Guru hisham777's Avatar
    Join Date
    Dec 2005
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks to you.
    now i have to face the bigger problem is
    to use the code with the othere parts like editing and deleting.

    and this will make me ask a Q. you have seen my level in coding
    there are so many things i just dont get it in PHP.

    so my Q is whats your advaces on this (practise(true)), shall
    i just continue starting with projects, or i go back to the basics,
    like how to build functions, make use of arrays....etc. ?

    by the way have you ever considered to open a site for tutorials
    (i noticed your blog) am a first member .

  18. #93
    SitePoint Wizard silver trophy Jelena's Avatar
    Join Date
    Feb 2005
    Location
    Universum, 3rd Corner
    Posts
    3,001
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by hisham777
    thanks to you.
    now i have to face the bigger problem is
    to use the code with the othere parts like editing and deleting.

    and this will make me ask a Q. you have seen my level in coding
    there are so many things i just dont get it in PHP.

    so my Q is whats your advaces on this (practise(true)), shall
    i just continue starting with projects, or i go back to the basics,
    like how to build functions, make use of arrays....etc. ?
    As I've already noticed, you are progressing very well, but reading about basics would be great. Most thing you can find in
    PHP Manual. But learning while you are making this system would be the fastest solution.
    Quote Originally Posted by hisham777
    by the way have you ever considered to open a site for tutorials
    (i noticed your blog) am a first member .
    Actually, I have. That is on my 2DO list for so long as it has low priority. I just can't find the time to do it .
    -- Jelena --

  19. #94
    SitePoint Guru hisham777's Avatar
    Join Date
    Dec 2005
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi there, its a rainy day.

    jelena i tryed to follow your style of coding. am not lucky
    i just cant it the moment, building a new functions for editing, viewing
    and deleting.
    do you recommend making function for each feature. ?


    am bad with functions so am reading about it in
    http://www.developertutorials.com/tu...620/page1.html

    and her

    http://www.webmasterworld.com/forum88/6411.htm

    Last edited by hisham777; Mar 30, 2006 at 23:46.

  20. #95
    SitePoint Wizard silver trophy Jelena's Avatar
    Join Date
    Feb 2005
    Location
    Universum, 3rd Corner
    Posts
    3,001
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Yes, I do recommend making functions, especially if one can be used on more then one place.
    Paste your code and let's see where's the problem
    -- Jelena --

  21. #96
    SitePoint Evangelist
    Join Date
    Jun 2003
    Location
    Melbourne, Australia
    Posts
    440
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by jelena
    Yes, I do recommend making functions, especially if one can be used on more then one place.
    Better still, learn object-oriented programming and make classes.

    As with functions you can give your classes names which describe their purpose. But you can also associated a number of related functions. This is referred to as encapsulation.

    For example, you have functions related to connecting to the database, running a query and then retrieving the results of that query. I'm not going to reveal the sort of code you'd find in the classes, but here's an example of how you might use them:
    PHP Code:
    require_once('path/to/class.MysqlConnection.php');

    $db =& new MysqlConnection($host$username$password);   //create connection object
    $db->connect($dbname);  //connect and select database 
    The class definition is in the file loaded by require_once(). It has several "methods" (that's the name we give to a class's functions) which are concerned with making a connection to a database and selecting a table.

    The variable $db represents the object you just created and the nomenclature '->' allows you to call its methods. In the example above, the method is 'connect', so I call the object's method with $db->connect($dbname);

    When you come to use the class, you create an "object" from it. The first line initializes the object with the parameters you pass to the creation function. The second line connects and selects the database. In two lines you've done what previously took you many lines. All that other stuff still happens in the background (that is, in the class's own methods), but once you've got your class working you don't have to wade through all that code to see what's it's doing. The script which creates and uses such an object has code, like that I wrote above, which expresses what is happening much more succinctly.

    Want to find articles? Define an article "model' class which makes use of a db connection object and runs specific queries on it. Code to do that might look like:
    PHP Code:
    $articleModel =& new ArticleModel($db);
    $articleModel->findAll(); 
    or
    PHP Code:
    $articleModel->findById($article_id); 
    or
    PHP Code:
    $articleModel->add($article_data); 
    or
    PHP Code:
    $articleModel->delete($article_id); 
    Want to tie that all together with displaying a list of articles?
    PHP Code:
    /* Connect to database */
    $db =& new MysqlConnection($host$username$password);
    $db->connect($dbname);

    /* Fetch all articles */
    $articleModel =& new ArticleModel($db);
    $articles $articleModel->findAll();

    /* Give article data to the view to display */
    $view =& new ArticleView('/path/to/html/template/for/displaying/articles');
    $view->setData($articles);
    $view->display(); 
    Now, learning how to write classes (basic OOP) and then learning how to use them and make sure you write them well is a very steep learning curve, but one worth learning. It allows you to write more expressive code. I've put comments in the last example, but I bet you could tell what was going on even if I hadn't because I gave meaningful and descriptive names to the classes and the variables representing objects based on them.

    And there wasn't any echo()-ing of HTML code. (That's inside the HTML template I gave to the ArticleView class.) It's so much easier to read.

    Beautiful, isn't it?
    Zealotry is contingent upon 100 posts and addiction 200?

  22. #97
    SitePoint Wizard silver trophy Jelena's Avatar
    Join Date
    Feb 2005
    Location
    Universum, 3rd Corner
    Posts
    3,001
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    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.
    -- Jelena --

  23. #98
    SitePoint Guru hisham777's Avatar
    Join Date
    Dec 2005
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    auricle thanks for the info
    i did learn OOP using C++ (theoritical)
    Classes
    Private
    Public
    encapsulation ...etc. and its benifites.
    however OO is in my mind but i need to get a good grip of the
    structorer programming specially the build in Functions,
    and how to make my own which am really bad at it.
    just starting to pick it up.
    thats why jelena functions.php was an exellent example to
    follow (am still trying to understand it still).

    who know may when this done all may be do one more then move to OO

  24. #99
    SitePoint Wizard silver trophy Jelena's Avatar
    Join Date
    Feb 2005
    Location
    Universum, 3rd Corner
    Posts
    3,001
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by hisham777
    thats why jelena functions.php was an exellent example to
    follow (am still trying to understand it still).
    Just tell me what confuses you, and I'll try to explain
    -- Jelena --

  25. #100
    SitePoint Evangelist
    Join Date
    Jun 2003
    Location
    Melbourne, Australia
    Posts
    440
    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.
    I know, but one can aspire to greater things!
    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.
    While I'm inclined to agree with you about the methodology, I guess I wouldn't necessarily have made that assumption. (Edit: in the meantime you and hisham777 sent a couple of posts while I couldn't connect to Sitepoint for a few minutes. Turned out I was right!)
    Also, OO approach on very simple systems like the one hi is building is in qustion.
    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.

    That doesn't mean that procedural coding can't do the job; of course it can. But once the scope of your application begins to increase, this sort of code becomes harder to follow. I remember trying to disable user registration in Postnuke -- it took me two days to find the code related to that! (And the scope has increased here -- we started with selecting articles and we're now onto inserting, updating and deleting them.)

    Besides, there are others following this thread and they might see the benefits too.
    Zealotry is contingent upon 100 posts and addiction 200?


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
  •