Sydcomebak Posted July 4, 2008 Share Posted July 4, 2008 Assume the following database structure: HouseTblPeopleTblResidentTbl -HouseID (unique)-NameID (unique)-ResidentID (unique) -HouseNum-NameLast-Name_ID -HouseStreet-NameFirst-House_ID -HouseCombined[/td][td] Bring in a variable from a link that you want to be the first letter of the last name. Call it $var. What I need to do is display the address next to the name that's echoed. <?php $result = mysql_query("SELECT * FROM PeopleTbl INNER JOIN ResidentTbl ON (PeopleTbl.NameID = ResidentTbl.Name_ID) WHERE SUBSTRING(NameLast,1,1) = '$var'"); ?> <?php while ($row = mysql_fetch_array($result) ) { echo "<a href="; echo '"'; echo "results.php?address="; echo $row['House_ID']; echo '"'; echo ">"; echo $row['NameLast'].", ".$row['NameFirst']; echo "</a> - "; $result1 = mysql_query("SELECT * FROM HouseTbl INNER JOIN ResidentTbl ON (HouseTbl.HouseID = ResidentTbl.House_ID) WHERE (HouseID = '$row[House_ID]'"); while ($row1 = mysql_fetch_array($result1) ) { echo $row1['HouseTbl.HouseCombined']; } echo "<br>"; } ?> Right now, I'm getting the error: "Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in..." after each displayed name. Am I not allowed to use "$row1" or "$result1" I don't think the recursive function will work unless I use different vars ? Link to comment https://forums.phpfreaks.com/topic/113180-recursive-functions-illegal-variable/ Share on other sites More sharing options...
DarkWater Posted July 4, 2008 Share Posted July 4, 2008 $result1 = mysql_query("SELECT * FROM HouseTbl INNER JOIN ResidentTbl ON (HouseTbl.HouseID = ResidentTbl.House_ID) WHERE (HouseID = '$row[House_ID]'") OR die(mysql_error()); Try that. That error that you got is due to the query failing. Link to comment https://forums.phpfreaks.com/topic/113180-recursive-functions-illegal-variable/#findComment-581504 Share on other sites More sharing options...
Sydcomebak Posted July 4, 2008 Author Share Posted July 4, 2008 Adams, Homer - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 4 Link to comment https://forums.phpfreaks.com/topic/113180-recursive-functions-illegal-variable/#findComment-581507 Share on other sites More sharing options...
DarkWater Posted July 4, 2008 Share Posted July 4, 2008 You missed a ). $result1 = mysql_query("SELECT * FROM HouseTbl INNER JOIN ResidentTbl ON (HouseTbl.HouseID = ResidentTbl.House_ID) WHERE (HouseID = '$row[House_ID]')") OR die(mysql_error()); That should work properly. =D Link to comment https://forums.phpfreaks.com/topic/113180-recursive-functions-illegal-variable/#findComment-581508 Share on other sites More sharing options...
Sydcomebak Posted July 4, 2008 Author Share Posted July 4, 2008 It made it through the functions and displayed all the names, but no addresses appeared. I'm going to try and add the table names and see if that helps. edit: Changed THIS: echo $row1['HouseTbl.HouseCombined']; To THIS: echo $row1['HouseCombined']; and now it works... sort of. The problem is that In a household where 2 ppl are residents, the address displays twice for each person. Maybe I should remove the While command? Link to comment https://forums.phpfreaks.com/topic/113180-recursive-functions-illegal-variable/#findComment-581511 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.