glennn.php Posted November 25, 2006 Share Posted November 25, 2006 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>" 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]$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"]; echo "$mp3";} 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>"; [/code] Quote Link to comment https://forums.phpfreaks.com/topic/28389-need-help-with-simple-query-please/ Share on other sites More sharing options...
fenway Posted November 25, 2006 Share Posted November 25, 2006 if ($mp3 = '518')You mean "==". Quote Link to comment https://forums.phpfreaks.com/topic/28389-need-help-with-simple-query-please/#findComment-129894 Share on other sites More sharing options...
glennn.php Posted November 25, 2006 Author Share Posted November 25, 2006 you mean all that looks right except for THAT??? i'm picking myself up off the floor laughing. i've attempted every reasonable script configuration known to man, woman and dolphin, and ... well. i'm a novice. let's go give this a try. i'll let you know. TIA. Quote Link to comment https://forums.phpfreaks.com/topic/28389-need-help-with-simple-query-please/#findComment-129897 Share on other sites More sharing options...
glennn.php Posted November 25, 2006 Author Share Posted November 25, 2006 nope. still prints the line regardless. man, and i'm a BIG BoSox fan, i was thinking GoBoSox!!!this is such a simple fix, i know. i'm just so new at it... Quote Link to comment https://forums.phpfreaks.com/topic/28389-need-help-with-simple-query-please/#findComment-129899 Share on other sites More sharing options...
glennn.php Posted November 25, 2006 Author Share Posted November 25, 2006 let me clarify - i want to print that particular portion of $line ONLY IF a cat with value 518 exists for $userid. for some reason the query as i have it now prints that line whether the userid possesses a cat of 518 or not (all userid's possess a cat of something else - some ALSO have a 518, or two or several, in which case i'd want the link "Playlist" printed along with the other info...)hope that clarifies my Greek for whomever is inclined to assist this lost soul.TIA Quote Link to comment https://forums.phpfreaks.com/topic/28389-need-help-with-simple-query-please/#findComment-129905 Share on other sites More sharing options...
glennn.php Posted November 25, 2006 Author Share Posted November 25, 2006 Fenway, that worked after i removed "cat = '518' AND ... LIMIT 1". Only condition i needed was userid... got it, thanks to you.[quote author=fenway link=topic=116214.msg473405#msg473405 date=1164422658]if ($mp3 = '518')You mean "==".[/quote] Quote Link to comment https://forums.phpfreaks.com/topic/28389-need-help-with-simple-query-please/#findComment-129924 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.