-1

thanks in advance for the help with this.

My problem is this, i have the following code (minus the database connect info and the table names are changed for security). i am stuck here so this is not the finished product. i am building an admin script for my mail server that does virtual domains, users, and aliases drawn froma database. this server works flawlessly. i call this function on my domain detail page to list first the number of mail boxes and then the number of aliases which then lets you go in and edit, add and deleted them. i get all the way to listing the mail box names and it seems to skip the first record. my function is as follows:

function listdomaindetails() {
    $domain = $_GET['domain'];
    $domaindetails_query = mysql_query("SELECT id FROM virtual_domains WHERE name='$domain'"); //get domain id
    $domaindetails_results = mysql_fetch_array($domaindetails_query, MYSQL_ASSOC); //Set domain id
    $domain_boxes_query = mysql_query("SELECT email FROM virtual_users WHERE domain_id='$domaindetails_results[id]'"); //Get virtual users
    $domain_boxes_results = mysql_fetch_array($domain_boxes_query, MYSQL_ASSOC); //Set virtual users
    $domain_boxes_count = mysql_num_rows($domain_boxes_results); //Count Boxes
    $domain_aliases_query = mysql_query("SELECT 'source', 'destination' FROM virtual_aliases WHERE domain_id='$domaindetails_results[id]'"); //Get aliases
    $domain_aliases_results = mysql_fetch_array($domain_aliases_query, MYSQL_ASSOC); //Set aliases
    $domain_aliases_count = mysql_num_rows($domain_aliases_results); //Count Aliases
    if ($domain_boxes_count = 0) {
        echo "This domain has no Email boxes, please add some by clicking <a href='email_add.php?domain=$domain'>HERE</a>";
    } else {
        while ($domain_boxes_row = mysql_fetch_array($domain_boxes_query, MYSQL_ASSOC)) {
        echo "<a href='email_detail.php?box=".$domain_boxes_row['email']."&domain=".$domain."'>".$domain_boxes_row['email']."</a><br>";
        }
    }
}

the page shows the following:

[email protected]
[email protected]

when it is supposed to say this:

[email protected]
[email protected]
[email protected]

any idea what i am doing wrong?

2 Answers 2

3

Because you call mysql_fetch_array once after you run the query, thus pulling off one row before you run the while loop.

1
  • this has been plaguing me forever. I appreciate you explaining it in plain English. Commented Mar 29, 2013 at 14:15
2

You're doing the first fetch immediately after defining the query

$domain_boxes_results = mysql_fetch_array($domain_boxes_query, MYSQL_ASSOC); 
1
  • that worked, i comented it out. thansk for the help, both of you nailed it on the head! another reason i love SO! Commented Sep 6, 2012 at 1:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.