Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 3 of 3
  1. #1
    Senior Member
    Join Date
    Oct 2003
    Location
    Essex/Greater London
    Posts
    167
    Member #
    3433
    I've been trying to recode my website so that it works, well, better. On my index page, I am trying to load my various items from a MySQL DB, and after I had finished my code, and checked that it worked, I took a step back and realised I had created a God awful mess. The code is horrible, and extremely bloated. I am doing all of this in PHP, which I am not very good at, and was wondering whether I am overlooking some sort of technique or function that could cut the size of this mess.

    On my site there is an area for the most recently entered articles, the newest feature, and my blog. On an article view page, I am querying, by repeating the same code, with different variables, loading the article text, username of the author etc., all from different tables.

    I have tried making one function that would run all of the queries, which I could then provide all of the necessary variables (what to load, what table etc.) but because various different variations of the code (such as LIMIT, ORDER BY and whatnot) I have been unsuccessful. Isn't there a better way of doing this?! An example of the code I have so far:

    Code:
    $sql = "SELECT username FROM phpbb_users WHERE user_id = $auth_id ";
    $sql_query = mysql_query($sql, $conn) or die(mysql_error());
    
    while ($sql_result = mysql_fetch_array($sql_query)) {
    $auth_name = $sql_result['username'];
    }
    I have seen slightly different methods of doing the same thing in the source of phpBB and a CMS I occassionaly use, but didn't really understand them.

  2.  

  3. #2
    Senior Member jlgosse's Avatar
    Join Date
    Jan 2004
    Location
    Newfoundland, Canada
    Posts
    1,037
    Member #
    4570
    Liked
    7 times
    Do you mean making user defined functions? That would be about the only thing that I could think of that would make that much better.

    Make a function that takes arguments to get something from the database.


  4. #3
    Senior Member
    Join Date
    Oct 2003
    Location
    Essex/Greater London
    Posts
    167
    Member #
    3433
    No, I'm afraid it would only use predefined arguments that I would define according to the situation.

    Maybe the code it meant to look like this, but I can't help but feel that it is a little too bloated.


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 11:15 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com