rbragg Posted July 19, 2007 Share Posted July 19, 2007 I am bringing in a value via POST: <?php $bird= mysql_real_escape_string($_POST['searchBird']); ?> If this value is not empty, I would like to look the bird up in its table and get the primary key (s_num) to use in a later select query. <?php if ( !empty($bird) ) { $queryBirdSearch = " SELECT s_num FROM bird WHERE bird = '$bird' "; $birdSearchResults = mysql_query($queryBirdSearch) or die( "Bird search query failed: " . mysql_error() ); $sNum = mysql_fetch_assoc($birdSearchResults); $querySearch.= " AND call.s_num = '$sNum' "; } ?> However, I am not finding a match although I KNOW there is one because I'm sitting here looking at it. I echo my two variables, <?php echo "bird: " . $bird; echo "<br>s_num: " . $sNum; ?> and get: bird: 845712365 s_num: Array The bird: is right ... but, why is my s_num being set as an array when there is only one result? Have I been staring at this for too long? Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted July 19, 2007 Share Posted July 19, 2007 To display the s_num, you would have to do this: <?php echo "bird: " . $bird; echo "<br>s_num: " . $sNum['s_num']; ?> You also might want to change this line $querySearch.= " AND call.s_num = '$sNum' "; To: $querySearch.= " AND call.s_num = '{$sNum['s_num']}' "; And if you wanted to display ALL the matches instead of just the first one, you would have to use a while loop. Quote Link to comment Share on other sites More sharing options...
trq Posted July 19, 2007 Share Posted July 19, 2007 <?php if ( !empty($bird) ) { $queryBirdSearch = " SELECT s_num FROM bird WHERE bird = '$bird' "; $birdSearchResults = mysql_query($queryBirdSearch) or die( "Bird search query failed: " . mysql_error() ); if (mysql_num_rows($birdSearchResults)) { $row = mysql_fetch_assoc($birdSearchResults); $sNum = $row['s_num']; $querySearch.= " AND call.s_num = '$sNum' "; } } ?> Quote Link to comment Share on other sites More sharing options...
rbragg Posted July 19, 2007 Author Share Posted July 19, 2007 OH DUH!!! I told you guys I've been staring at it for TOO long!! Thanks for your replies. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.