Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Mar 2005
    Posts
    56
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Problem printing info with a join

    I'm working on a script that first calls all of the states in the nation, then displays info for each state when the state is selected from the pull down.

    The first segment of code I'm enclosing prints all of the info, except that it returns the state id as a numerical figure rather than the state.

    Code:
    		if ($st) { // Print info for selected state(s)
                $query2 = "SELECT debtors.entry_date, debtors.business_name, debtors.responsible_party, debtors.city, debtors.state, debtors.zip, debtors.address, debtors.dollar_amount, debtors.details, debtors.date_of_default, debtors.resolved, debtors.date_resolved, debtors.creditor, debtors.creditor_name, debtors.creditor_city, debtors.creditor_state, debtors.creditor_zip, debtors.creditor_address, debtors.paid, state.id, state.state FROM debtors, state WHERE debtors.paid = 'Yes' AND state.id = debtors.state ORDER BY city, business_name, responsible_party";
                $result2 = mysql_query ($query2);
                if ($result2) {
                 
    			 
    			   
    				
    				echo '
                    <fieldset><legend><font face="Arial, Helvetica, sans-serif" size="2">Select the business name or person\'s name for details:</font></legend>
                    <table border="2" width="90%" cellspacing="3" cellpadding="3" align="center">
                      <tr>
                      <td><b>City</b></td>
                      <td><b>State</b></td>
    		  <td><b>Business Name</b></td>
                      <td><b>Responsible Party</b></td>
    				  </tr>';
        
                    // Display all the debtors.
                    while ($row = mysql_fetch_array($result2, MYSQL_NUM)) {
                        // Display each record.
                        echo "
                        <tr>
                        <td><font face=\"arial\" size=\"2\"><b>$row[3]</b></font></td>
                        <td><font face=\"arial\" size=\"2\"><b>$row[4]</b></font></td>
    		<td><font face=\"arial\" size=\"2\"><b>$row[1]</b></font></td>
                        <td><font face=\"arial\" size=\"2\"><b>$row[2]</b></font></td>
                        </tr>";
                    } // end while
    			} // end-if($result2)
            } // end-if($st)
            $i++;
        } // end-while
    When I use this it returns a blank page except for the header and footer.

    Code:
    if ($st) { // Print info for selected state(s)
                $query2 = "SELECT debtors.entry_date, debtors.business_name, debtors.responsible_party, debtors.city, debtors.state, debtors.zip, debtors.address, debtors.dollar_amount, debtors.details, debtors.date_of_default, debtors.resolved, debtors.date_resolved, debtors.creditor, debtors.creditor_name, debtors.creditor_city, debtors.creditor_state, debtors.creditor_zip, debtors.creditor_address, debtors.paid, state.id, state.state FROM debtors, state WHERE debtors.paid = 'Yes' AND state.id = debtors.state ORDER BY city, business_name, responsible_party";
                $sth = mysql_query($query2) or die(mysql_error());
    			while ($rec = mysql_fetch_assoc($sth)) {
        		$arr['key'];
                if ($result2) {
                 
    			 
    			   
    				
    				echo '
                    <fieldset><legend><font face="Arial, Helvetica, sans-serif" size="2">Select the business name or person\'s name for details:</font></legend>
                    <table border="2" width="90%" cellspacing="3" cellpadding="3" align="center">
                      <tr>
                      <td><b>City</b></td>
                      <td><b>State</b></td>
    		  <td><b>Business Name</b></td>
                      <td><b>Responsible Party</b></td>
    				  </tr>';
        
                    // Display all the debtors.
                    while ($row = mysql_fetch_array($result2, MYSQL_NUM)) {
                        // Display each record.
                        echo "
                        <tr>
                        <td><font face=\"arial\" size=\"2\"><b>$rec[city]</b></font></td>
                        <td><font face=\"arial\" size=\"2\">$rec[state]</b></font></td>
    		    <td><font face=\"arial\" size=\"2\"><b>$rec[business_name]</b></font></td>
                        <td><font face=\"arial\" size=\"2\"><b>$rec[responsible_party]</b></font></td>
                        </tr>";
                    } // end while ($sth)
    				} // end while
    			} // end-if($result2)
            } // end-if($st)
            $i++;
        } // end-while
    What am I doing wrong?

    Thanks

    T

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Try echoing mysql_error() in the event your query doesn't work. Right now you are bypassing the building of your html if the query fails, but then you don't display anything to give you an idea of what went wrong with the query.

  • #3
    New Coder
    Join Date
    Mar 2005
    Posts
    56
    Thanks
    0
    Thanked 0 Times in 0 Posts
    When I echoed
    Code:
    echo '$sth = mysql_query($query2) or die(mysql_error())';
    I got
    Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource
    I've never got that warning before. What could cause that?

  • #4
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Yeah that won't work, putting a variable assignment from a function's return value inside an echo statement. I'm not sure why you tried that.

    Doing the "or die(mysql_error())" thing is good enough, you just didn't have it in your code (the first block you posted).


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •