Clinton Posted January 21, 2009 Share Posted January 21, 2009 I'm getting an extract error that generally shows up when there are no rows to be fetched. However, I use this same exact query (cut and paste) elsewhere but it just produces an error here. What am I doing wrong? <?php $query1 = mysql_query("SELECT * FROM head WHERE did = '$id' AND rname = '$rname'"); $row1 = mysql_fetch_assoc($query1); extract($row1); ?> <center> <b><?php echo $fname; ?> <?php echo $mname; ?> <?php echo $lname; ?></b><br /> </center> ///The Above Code Works Fine/// <?php $query1 = mysql_query("SELECT * FROM structure WHERE did = '$id' AND rname = '$rname'"); $row1 = mysql_fetch_assoc($query1); extract($row1); /// I'm Getting My Error Here /// ?> EDIT Error just FYI: Warning: extract() [function.extract]: First argument should be an array Quote Link to comment https://forums.phpfreaks.com/topic/141691-solved-extract-error/ Share on other sites More sharing options...
trq Posted January 21, 2009 Share Posted January 21, 2009 What am I doing wrong? Not checking your query returns results. <?php if ($query1 = mysql_query("SELECT * FROM head WHERE did = '$id' AND rname = '$rname'")) { if (mysql_num_rows($result1)) { $row1 = mysql_fetch_assoc($result1); extract($row1); ?> <center> <b><?php echo $fname; ?> <?php echo $mname; ?> <?php echo $lname; ?></b><br /> </center> <?php } } ?> Edit: Your also passing $query1 instead of $result1 to mysql_fetch_assoc. Quote Link to comment https://forums.phpfreaks.com/topic/141691-solved-extract-error/#findComment-741736 Share on other sites More sharing options...
Clinton Posted January 21, 2009 Author Share Posted January 21, 2009 Ok, yes, I may be doing that wrong but that's not the answer (I will fix that though). :-) If I remove the first query then the second query works just fine. They don't like each other for some reason and I'm not sure why. Even if they're renamed so they're not identical. Quote Link to comment https://forums.phpfreaks.com/topic/141691-solved-extract-error/#findComment-741740 Share on other sites More sharing options...
PFMaBiSmAd Posted January 21, 2009 Share Posted January 21, 2009 As to the interaction, your unconditional use of extract() is probably overwriting variables that the second query is using. extract() should only be used with one of the PREFIX options so that the variables it creates are unique to that query and don't have a chance of overwriting any existing program variables. Quote Link to comment https://forums.phpfreaks.com/topic/141691-solved-extract-error/#findComment-741746 Share on other sites More sharing options...
Clinton Posted January 21, 2009 Author Share Posted January 21, 2009 Ok Ty. Quote Link to comment https://forums.phpfreaks.com/topic/141691-solved-extract-error/#findComment-741748 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.