...

View Full Version : Problem printing info with a join



hightechredneck
12-21-2006, 10:35 PM
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.



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.



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

Fumigator
12-22-2006, 06:57 AM
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.

hightechredneck
12-22-2006, 04:50 PM
When I echoed


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?

Fumigator
12-23-2006, 10:01 AM
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).



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum