How to SELECT WHERE column = string?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Serengeti
Forum Newbie
Posts: 19
Joined: Sat Jan 22, 2005 1:58 am

How to SELECT WHERE column = string?

Post 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;
User avatar
neophyte
DevNet Resident
Posts: 1537
Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota

Post by neophyte »

It should be just 'Y' .....

But if that wasn't working I'd double check to make sure my connection was good.
Serengeti
Forum Newbie
Posts: 19
Joined: Sat Jan 22, 2005 1:58 am

Post 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.
User avatar
neophyte
DevNet Resident
Posts: 1537
Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota

Just a suggestion...

Post 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....
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
Serengeti
Forum Newbie
Posts: 19
Joined: Sat Jan 22, 2005 1:58 am

Post 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 :)
Post Reply