Page 1 of 1

How to SELECT WHERE column = string?

Posted: Sat Jan 22, 2005 1:51 pm
by Serengeti

Code: Select all

Warning:  mysql_fetch_row(): supplied argument is not a valid MySQL result resource in *****featured.php on line 61
Its not pulling any data...
WHERE t3.Featured = Y
returns nothing, prolly the wrong syntax, but I've used
=QUOTE(Y)
='Y'
=('Y')

I've searched about 4 different tutorial sites and forums and I can't find a solution to this simple problem! lol

Code: Select all

function getFeatured(){
    Global $connection;
    $today = date("Ymd");
	
    hookUpDb();
    $query = "SELECT t1.PhotoURL, t3.MemberNum, t3.ExtColor, t3.Descr1, t3.NumOfColor
                   FROM photos t1, xrefphotomember t2, memberinfo t3
                   WHERE t3.Featured = Y
				   AND t2.PID = t1.PID
				   AND t3.MID = t2.MID";
				   
    $result = mysql_query($query,$connection);
    openFeaturedTable();
    
    while ($row = mysql_fetch_row($result)){
           $PhotoURL      = unFormatData($rowї0]);
		   $MemberNum     = unFormatData($rowї1]);
		   $ExtColor      = unFormatData($rowї2]);
		   $Descr1        = unFormatData($rowї3]);
		   $NumOfColor    = unFormatData($rowї4]);
print("$PhotoURL");
print("$MemberNum");
print("$ExtColor");
print("$Descr1");
print("$NumOfColor");
           $PhotoLarge    = $MemberNum. "-". $PhotoURL. ".jpg";
           $PhotoThumb    = "images/cars/". $MemberNum. "-". $PhotoURL. "-thumb.jpg";
		   $String1       = "Member #". $MemberNum;
		   $String2       = $NumOfColor. $ExtColor. "99 VR-4s";
		  
		   $Build1 = "','600','451','* * Click screen to close * *','#000000','hug image','0');return document.MM_returnValue"><img src="$PhotoThumb" alt="" width="169" height="127" border="0"></a><br /><span class="featuredtext">$String1<br />$String2<br />$Descr1</span></div></td>
                </tr>
              </table>   ";

		   $Output   = $PhotoLarge. $Build1;
		   
           print("$Output");
	 	   
     &#125;
     mysql_free_result($result);
     mysql_close($connection);
&#125;

Posted: Sat Jan 22, 2005 2:30 pm
by neophyte
It should be just 'Y' .....

But if that wasn't working I'd double check to make sure my connection was good.

Posted: Sat Jan 22, 2005 3:00 pm
by Serengeti
The connection is good. I copied hookUpDb() straight from another PHP page in the same folder that is working correctly.

I changed some of the code to this:

Code: Select all

$Featured = 'Y';
	
    hookUpDb();
    $query = "SELECT t1.PhotoURL, t3.MemberNum, t3.ExtColor, t3.Descr1, t3.NumOfColor
                   FROM photos t1, xrefphotomember t2, memberinfo t3
                   WHERE t3.Featured = $Featured
				   AND t2.PID = t1.PID
				   AND t3.MID = t2.MID";
and it still gives the same error.

Just a suggestion...

Posted: Sat Jan 22, 2005 3:15 pm
by neophyte
Hmmm If I were in this situation I'd copy that sql out of my script and try running in against my db with phpMyAdmin or something else similar until I got the errors worked out. That way you'll be able to see mysql errors. Or insert or die(mysql_error()); Some place where I might be able to see where the error was....

Posted: Sat Jan 22, 2005 3:28 pm
by feyd
switching this:

Code: Select all

$result = mysql_query($query,$connection);
to

Code: Select all

$result = mysql_query($query,$connection) or die(mysql_error());
like neophyte suggested is probably the best way to figure it out.. I would bet the problem has to do with precedence.

Posted: Sat Jan 22, 2005 4:01 pm
by Serengeti

Code: Select all

$query = "SELECT t1.PhotoURL, t3.MemberNum, t3.ExtColor, t3.Descr1, t3.NumOfColor
                   FROM photos t1, xrefphotomember t2, memberinfo t3
                   WHERE t3.Featured = 'Y'
				   AND t2.PID = t1.PID
				   AND t3.MID = t2.MID
				   AND t1.PhotoURL = 1";
I had to add the last bit of code to select only the first photo. 'Featured' has one record, but that record has multiple photos associated with it. Duh...I told you I was a little rusty. ;)

And thanks for that 'die' code. Works nice ;) It told me there was no column named Y...so I changed the quotes and voila! 3X the output I wanted, lol....added that last AND...now it works like a charm :)