Re: Selecting Rows Based on Row Values Being in Array

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Jim,

Thanks for all you help.  Tell me where to mail you the check "seriously". 
If we get this right I'll owe you.

OK, the query string now looks like you said it would.  However Query isn't 
returning a match.
//DETAILS=========================================================

My $list array looks like this one echo'd:

$list[0] =7orange50lbs
$list[1] =8purple60lbs


Now when I do this:

$query_One= "SELECT * FROM shoe WHERE CONCAT(size,color,weight) 
IN({$in_list})";

$result = mysql_query($query_One,$connection) or die("Query failed: ". 
mysql_error($connection));
$row = mysql_fetch_assoc($result);

  while($row = mysql_fetch_assoc($result))
  {extract($row);
  echo "<table width='2400' cellpadding='5' cellspacing='5' 
class='tborder'><tr>
      <td width='46' border = '1' bordercolor ='#3E5C92' height='20' 
align='left' class='tcat'>$count</td>
      <td width='200' align='left' class='row2'>$size</td>
      <td width='200' align='left' class='row2'>$color</td>
      <td width='200' align='left' class='row2'>$weight</td>
      </tr>
      </table>";
  }
No rows are returned to the screen.  I know I should at least have 2 rows 
return because my TABLE has 2 rows in it and both rows are in $in_list[0] 
and[1].

                          size  color       weight
Row1 looks like: 7     orange     50lbs    //This is from phpMyAdmin table 
export
Row2 looks like: 8     purple     60lbs    //This is from phpMyAdmin table 
export


I get no MySQL errors either.  So I'm wondering why aren't rows returning?
//END DETAILS==============================================================


"Jim Lucas" <lists@xxxxxxxxx> wrote in message 
news:468A64F8.7030100@xxxxxxxxxxxx
> kvigor wrote:
>> Ok Jim,
>>
>> This is what I have so far and I'm still working it out.
>>
>> $in_list = "".join('',$someArrayList);  // do I really need to 
>> concatenate
> it needs to be
>
> $in_list = "'".join("','",$someArrayList)."'"; // you need the quotes!!
>
>> or separate anything here since my array values will be '7orange50lbs'? 
>> // this is the format I want.
> You are going wrong right here.  First off you took out all the quoting
>
> Your search items must be quoted and separated by commas.  Remember, we 
> want it to check a list/array() of items
>
> $in_list must look like this when done 'item1','item2','item3'....
>
> in SQL, this is a list.
>
>>
>> $query_One = "SELECT * FROM shoe WHERE CONCAT(size,color,weight) 
>> IN({$in_list})";    // size, color, weight are my column names
>
> if you echo $query_One , what do you get?
>
>> $result = mysql_query($query_One ,$connection) or die("Query failed: ". 
>> mysql_error($connection));
> before you run the fetch, you need to double check that you got something 
> back, otherwise you will get an error from php.
>
> if ( mysql_num_rows($results) > 0 ) {
> while ( $row = mysql_fetch_array(
> } else {
> echo "No results";
> }
>
>> $row = mysql_fetch_array($result);
>
> and I would recommend that you use either *_assoc() or *_row() instead of 
> *_array().
> Doesn't use as much memory, and your resulting $row variable doesn't have 
> two of what you are looking for.
>
>>
>> This is the error I get back from the query:
>> Query failed: Unknown column '6blue40lbs' in 'where clause'
>
> This is because you took out the quotes from above.  Put them back and it 
> might just work.
>
> SQL will see the un-quoted 6blue40lbs and think that it is a string.
> If it was quoted, it would not.
>
> // where am I
>> going wrong?
>
> -- 
> Jim Lucas
>
>    "Some men are born to greatness, some achieve greatness,
>        and some have greatness thrust upon them."
>
> Twelfth Night, Act II, Scene V
>     by William Shakespeare 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux