Jump to content

extract() expects parameter 1 to be array no information displayed.


Namtip

Recommended Posts

Problem:

"Warning: extract() expects parameter 1 to be array, null given in C:\x\xampp\htdocs\pages\user_personal.php on line 32" - error also found on lines 33 and 38.

and none of the information is displayed.

 

Goal: I'm trying to retrieve profile information and multiple user inserted pictures and display the pictures through a while loop from one query.

 

 

 

<?php$query = 'SELECT        u.name_id, i.bio, i.exhib, p.product_code        FROM        user u LEFT JOIN profile i ON u.name_id = i.name_id	LEFT JOIN ecomm_products p ON u.name_id = p.product_code        WHERE        u.name = "' . mysql_real_escape_string($_SESSION['name'], $db) . '" and p.name = "' . mysql_real_escape_string($_SESSION['name'], $db) . '"';    $result = mysql_query($query, $db) or die(mysql_error());extract($bio);  //line 32extract($exhib); //line 33$odd = true;while ($row = mysql_fetch_array($result)) {    echo ($odd == true) ? '<tr class="odd_row">' : '<tr class="even_row">';    $odd = !$odd;     extract($rows); line 38    echo '<td><a href="' . $dir . '/' . $row['product_code'] . '.jpg">';    echo '<img src="' . $thumbdir . '/' . $row['product_code'] . '.jpg">';    echo '</a></td>';    echo '</tr>';	}	echo "</table>";	echo "<p>";?>  <ul>   <li>Biography: <?php echo $bio; ?></li>   <li>Exhibitions: <?php echo $exhib; ?></li>  </ul>

 

Link to comment
Share on other sites

This works.

 

<?php$query = 'SELECT        u.name_id, i.bio, i.exhib, p.product_code        FROM        user u LEFT JOIN profile i ON u.name_id = i.name_id	LEFT JOIN ecomm_products p ON u.name_id = p.product_code        WHERE        u.name = "' . mysql_real_escape_string($_SESSION['name'], $db) . '" and p.name = "' . mysql_real_escape_string($_SESSION['name'], $db) . '"';    $result = mysql_query($query, $db) or die(mysql_error());$row = mysql_fetch_array($result);extract($row);mysql_free_result($result);mysql_close($db);	?>  <ul>   <li>Biography: <?php echo $bio; ?></li>   <li>Exhibitions: <?php echo $exhib; ?></li>  </ul>

 

 

but i want try to loop out the pictures it says different errors.

This gives out this error "Warning: mysql_fetch_array(): 5 is not a valid MySQL result resource in C:\x\xampp\htdocs\pages\user_personal.php on line 54"

 

<?php$query = 'SELECT        u.name_id, i.bio, i.exhib, p.product_code        FROM        user u LEFT JOIN profile i ON u.name_id = i.name_id	LEFT JOIN ecomm_products p ON u.name_id = p.product_code        WHERE        u.name = "' . mysql_real_escape_string($_SESSION['name'], $db) . '" and p.name = "' . mysql_real_escape_string($_SESSION['name'], $db) . '"';    $result = mysql_query($query, $db) or die(mysql_error());$row = mysql_fetch_array($result);extract($row);mysql_free_result($result);mysql_close($db);	?>  <ul>   <li>Biography: <?php echo $bio; ?></li>   <li>Exhibitions: <?php echo $exhib; ?></li>  </ul>  <p><a href="update_profile.php">Update Profile</a> |<a href="upload_image.php">Upload Work</a> |<a href="update_account.php">Update Account</a> |<a href="delete_account.php">Delete Account</a> |<a href="logout.php">Sign out</a>   </p></body></html><?php$odd = true;while ($row = mysql_fetch_array($result)) {                 // line 54    echo ($odd == true) ? '<tr class="odd_row">' : '<tr class="even_row">';    $odd = !$odd;     extract($rows);    echo '<td><a href="' . $dir . '/' . $row['product_code'] . '.jpg">';    echo '<img src="' . $thumbdir . '/' . $row['product_code'] . '.jpg">';    echo '</a></td>';    echo '</tr>';	}	echo "</table>";	echo "<p>";?>

 

Is it not possible to pull two different results from the array? Do I need to give variables to the mysql WHERE function in the SELECT table?

 

Am I making sense?  :shy:

Link to comment
Share on other sites

<?php
$query = 'SELECT
        u.name_id, i.bio, i.exhib, p.product_code
        FROM
        user u LEFT JOIN profile i ON u.name_id = i.name_id
	LEFT JOIN ecomm_products p ON u.name_id = p.product_code
        WHERE
        u.name = "' . mysql_real_escape_string($_SESSION['name'], $db) . '" and p.name = "' . mysql_real_escape_string($_SESSION['name'], $db) . '"';
    $result = mysql_query($query, $db) or die(mysql_error());

$row = mysql_fetch_array($result);
extract($row);

?>
<html>
<head></head>
<body>
  <ul>
   <li>Biography: <?php echo $bio; ?></li>
   <li>Exhibitions: <?php echo $exhib; ?></li>
  </ul>
  <p><a href="update_profile.php">Update Profile</a> |
<a href="upload_image.php">Upload Work</a> |
<a href="update_account.php">Update Account</a> |
<a href="delete_account.php">Delete Account</a> |
<a href="logout.php">Sign out</a>
   </p>

<?php
$odd = true;
while ($row = mysql_fetch_array($result)) {
    echo ($odd == true) ? '<tr class="odd_row">' : '<tr class="even_row">';
    $odd = !$odd; 
    extract($rows);
    echo '<td><a href="' . $dir . '/' . $row['product_code'] . '.jpg">';
    echo '<img src="' . $thumbdir . '/' . $row['product_code'] . '.jpg">';
    echo '</a></td>';
    echo '</tr>';
	}
	echo "</table>";
	echo "<p>";

?>
</body>
</html>

No error messages display but no photos loop either. Sorry to be a bother. :(

Link to comment
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.