Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/141691-solved-extract-error/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/141691-solved-extract-error/#findComment-741736
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/141691-solved-extract-error/#findComment-741740
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/141691-solved-extract-error/#findComment-741746
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.