Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

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?

share|improve this question
up vote 2 down vote accepted

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

$domain_boxes_results = mysql_fetch_array($domain_boxes_query, MYSQL_ASSOC); 
share|improve this answer
    
that worked, i comented it out. thansk for the help, both of you nailed it on the head! another reason i love SO! – John Stapleton Sep 6 '12 at 1:35

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

share|improve this answer
    
this has been plaguing me forever. I appreciate you explaining it in plain English. – Stephan Hovnanian Mar 29 '13 at 14:15

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.