Jump to content

[SOLVED] php / mysql select db where issue.


des1017

Recommended Posts

$query  = "SELECT * FROM $tablecategories";
$result = mysql_query($query);
while($rowx = mysql_fetch_array($result, MYSQL_BOTH))
{

echo "
<div id='textheading'>" . $rowx['categoryname'] . "</div>
<div id='naddition'>
";

$queryz  = "SELECT * FROM $tableunits WHERE unitcategory = " . $rowx['categoryname'] . ";
$resultz = mysql_query($queryz);
while($rowz = mysql_fetch_array($resultz, MYSQL_BOTH))
{

echo "
<div id='nitem'>
<a href='jewelry.php?item=".$rowz["unitid"]."'><img src='jewelry/".$rowz["unitimage"]."' alt='".$rowz["unitname"]."' width='100' height='100'><br />-> Click Here</a>
</div>
";

}

echo "
</div>
";

}

 

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource

 

 

I'm having an issue with two while loops. I'm thinking either the query/result inside the first loop is an issue, or the select db where unitcategory = $categoryname

Link to comment
https://forums.phpfreaks.com/topic/116667-solved-php-mysql-select-db-where-issue/
Share on other sites

Do:

 

 

$queryz  = "SELECT * FROM $tableunits WHERE unitcategory = '{$rowx['categoryname']}'";

$resultz = mysql_query($queryz) or die(mysql_error());

 

 

What I just did:

  • Added quotation marks around the string in the where clause
  • Used proper array parsing technique in strings.  It's much cleaner.
  • Added a mysql_error() clause

 

Please try that code.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.