Joy.

    Date: 06/29/06 (PHP Community)    Keywords: php, programming, database

    I love how whenever I run into a problem and I post it here, it's always something that I know I should already know how to do.

    Seriously, this should be something really easy, right?

    The project that I'm working on, and really haven't had much time to deal with lately due to other stuff, is the same one that I'm always working on when I post here: A document tracking system for my mom's work.

    A whilie ago I ran into problems converting the system to an older version of PHP (it works fine now, in that regard), and now this.

    It works just fine, and does everything I want. I'm now trying to clean it up from slow and clunky code that was only used for the purpose of making sure the hard stuff worked (ironically, i had little to no problems doing the complicated logic stuff).


    So when bringing up the application, the user is given a form to fill out that essentially sends an e-mail, and has a vague e-mail feel to it anyway. The user has 10 drop-down menus for a maximum of 10 users. In the database, there is a table with all the users available. As a quick and dirty way of populating the list of names, I just wrote a small function that queries the database and plugs the names into the drop-down box. Well, right now, since there are 10 boxes, it does that 10 times. And it's SLOOOOOOW. My mom and I both knew that this wasn't how it was going to stay, it was just an easy way of testing the stuff that would.

    So, now that I'm backtracking slightly, I'm running into problems. What I want to do is pop the results of the query into an aray that mimics the structure of the table. Many rows, two columns. I set up a 2-d array, or tried to at least. The book I have isn't exactly clear on that topic, so I used what I thought I knew from regular programming languages and tried to apply that to this. Apparently it didn't work.

    I'm not sure why this doesn't work, so I'm just going to post the code used in here. Unfortunately, when I try and access the array with:

    $users = array(get_users());
    $num_of_users = count($users);
    for ($i=0; $i<$num_of_users; $i++)
    {
    echo " \n";
    }

    It doesn't do anything. So I don't really know what I'm doing wrong. I may be going about this way too hard. I wanted to just use the explode() function, but i couldn't think of how to get it to differentiate between what would go in one column versus another, and figured it would just plug it all into a 1-d array. So yeah, any help you can offer would be greatly appreciated.



    //This function pulls the users from the webusers table for use in choosing a recipient
    function get_users()
    {
    **Database Connect Information Removed**

    if (!$users_connect || !$db_select)
    {
    die("Problem connecting or selecting a database.");
    } //end if

    $query = "SELECT ename, eaddr FROM webusers ORDER BY ename";
    $result = mysql_db_query("test", $query);
    $num_of_users = mysql_num_rows($result);
    $users[$num_of_users][2] = array();
    $i = 0;
    while (list($ename, $eaddr) = mysql_fetch_row($result))
    {
    $users[$i][0] = $eaddr;
    $users[$i][1] = $ename;
    $i++;
    } //end while

    mysql_close();

    return($users);
    } //end get_users()


    Thanks so much!

    Source: http://community.livejournal.com/php/464906.html

« Learning... || phpBB3 »


antivirus | apache | asp | blogging | browser | bugtracking | cms | crm | css | database | ebay | ecommerce | google | hosting | html | java | jsp | linux | microsoft | mysql | offshore | offshoring | oscommerce | php | postgresql | programming | rss | security | seo | shopping | software | spam | spyware | sql | technology | templates | tracker | virus | web | xml | yahoo | home