i need some HELP (not THAT kind of help - i'm SEEING a Dr.)

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
glennn.php
Forum Commoner
Posts: 41
Joined: Sat Jul 08, 2006 12:26 pm

i need some HELP (not THAT kind of help - i'm SEEING a Dr.)

Post by glennn.php »

the kind of help i need is with this stupid little query that i can't make behave...

this is an old query i've been remodelling to work with an ever changing script (any suggestions as to its cleanliness and efficiency are most welcome)...

i'm trying to print "$line <a href// Playlist</a>" (down around $resa = ) ONLY IF any number of cats with the value of 518 exist for each userid. doesn't matter how many records with such a cat - that's handled elsewhere. i just don't want to print that line if there are no 518s for $userid.

can anyone show me the error of my ways? (not like my mom tried to show me - that NEVER worked).

thanks, in all seriousness, and regards,
gn


Code: Select all

$res = mysql_query("SELECT id, userid, user, cat, bigimage, description, extra1 FROM pp_photos ORDER BY rating DESC");
while ($row = mysql_fetch_array($res)) {
	$img = $row["bigimage"];
	$bio = $row["description"];	
	$url = $row["extra1"];
	$userid = $row["userid"];
	$name = $row["user"];
	$id = $row["id"];
	$cat = $row["cat"];
	$catArray[] = $cat;
	$mp3Array[] = $mp3;
	$picsArray[] = $img;
	$useridArray [] = $userid;
	$nameArray[] = $name;
	$urlArray[] = $url;
	$idArray[] = $id;
	$bioArray[] = $bio;
}


 $idx = 0;
$pos = 0;
$purl = $picUrl[$pic];	
$i = (count($picsArray) - 1);
                while ($idx <= $i) 
		{				
			$pic  = $picsArray[$idx];
			$url  = $urlArray[$idx];
			$name  = $nameArray[$idx];
			$cat  = $catArray[$idx];
			$userid  = $useridArray[$idx];
			$id  = $idArray[$idx];
			$bio  = $bioArray[$idx];
			$name = str_replace("'", "\'", $name);
			$bio = str_replace("'", "\'", $bio);
			$bio = preg_replace("/"/", "\'", $bio);
			$bio = preg_replace("/'/", "\'", $bio);
			if ($pos == 0) { print "<tr>\n"; }
			
			
$line = "<a href=\"pp/showphoto.php?photo=$id&cat=$cat&ppuser=$userid\" target=\"\" onmouseover=\"return overlib ('<b><a href=$url target=_blank>Website</a></b><br><img src=imgs/spacer.gif width=100 height=3><br>";
			
$resa = mysql_query("SELECT cat FROM pp_photos WHERE cat = '518' AND userid = '$userid' LIMIT 1");
	while ($row = mysql_fetch_array($resa)) {
	$mp3 = $row["cat"];}
	
if ($mp3 = '518') {
	$line .= "<b><a href=mediaPlayer/player.php?userid=$userid target=player>Playlist</a> </b>";
}				

$line .= "<br><img src=imgs/spacer.gif width=100 height=3><br><b>$bio</b><br><img src=imgs/spacer.gif width=100 height=3>', STICKY, CAPTION, '<b>$name</b>', MOUSEOFF);\" onmouseout=\"return nd();\"><img src=\"pp/data/".$cat."/".$pic."\" border=\"0\" height=\"100\" width=\"100\"></a>"; 

User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

Post by kendall »

probably a

Code: Select all

$res = mysql_query("SELECT id, userid, user, cat, bigimage, description, extra1 FROM pp_photos WHERE cat = 518 ORDER BY rating DESC"); 
or a

Code: Select all

$res = mysql_query("SELECT id, userid, user, cat, bigimage, description, extra1 FROM pp_photos WHERE cat LIKE 518 ORDER BY rating DESC"); 
might work
Post Reply