laPistola Posted November 23, 2008 Share Posted November 23, 2008 mysql_select_db($database_bedroomBlogsDB, $bedroomBlogsDB); $query_FLfriends_A_B_RS = "SELECT fid FROM friends_list WHERE `uid` = '$FLgetUID' AND status = '1'"; $FLfriends_A_B_RS = mysql_query($query_FLfriends_A_B_RS, $bedroomBlogsDB) or die(mysql_error()); $row_FLfriends_A_B_RS = mysql_fetch_assoc($FLfriends_A_B_RS); $totalRows_FLfriends_A_B_RS = mysql_num_rows($FLfriends_A_B_RS); mysql_select_db($database_bedroomBlogsDB, $bedroomBlogsDB); $query_FLfriends_B_A_RS = "SELECT `uid` FROM friends_list WHERE fid = '$FLgetUID' AND status = '1'"; $FLfriends_B_A_RS = mysql_query($query_FLfriends_B_A_RS, $bedroomBlogsDB) or die(mysql_error()); $row_FLfriends_B_A_RS = mysql_fetch_assoc($FLfriends_B_A_RS); $totalRows_FLfriends_B_A_RS = mysql_num_rows($FLfriends_B_A_RS); function doAB($ab) { while($ab) { $ab['fid']","; } } $FLab = doAB($row_FLfriends_A_B_RS); $FLba = ""; $FLabba = $FLab.$FLba; Above is about as far as i got before i tested and errors came up with unexpected T_CONSTANT_ENCAPSED_STRING line 63 Basicly what im trying to do is create a string or it could be an array that contants id's numbers only so it can be run through another mySQL query. The two query's above return only numbers on one colume but i need both query results to end up in the same string/array the string needs to look like 1,4,26,45,2,8 etc any ideas please Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted November 23, 2008 Share Posted November 23, 2008 Were you wanting something like this? <?php $sql = "SELECT fid,uid FROM friends_list WHERE (`uid` = '$FLgetUID' OR `fid`='$FLgetUID') AND status = '1'"; $result = mysql_query($sql) or trigger_error(mysql_error(),E_USER_ERROR); $array = array(); while($row = mysql_fetch_assoc($result)){ $array[] = $row['fid']; $array[] = $row['uid']; } echo '<pre>'.print_r($array,1).'</pre>'; ?> If not, you're going to need to explain your problem a bit more carefully. Oh, and there's no need to select the database before each query. Once is sufficient (unless it changes). Quote Link to comment Share on other sites More sharing options...
waynew Posted November 23, 2008 Share Posted November 23, 2008 <?php $sql = "SELECT fid,uid FROM friends_list WHERE (`uid` = '$FLgetUID' OR `fid`='$FLgetUID') AND status = '1'"; $result = mysql_query($sql) or trigger_error(mysql_error(),E_USER_ERROR); $friend_uid = array(); while($row = mysql_fetch_assoc($result)){ array_push($friend_uid,$row['fid']); array_push($friend_uid,$row['uid']); } echo '<pre>'.print_r($friend_uid,1).'</pre>'; ?> ??? Quote Link to comment Share on other sites More sharing options...
laPistola Posted November 23, 2008 Author Share Posted November 23, 2008 close enough i think, i didn't use one query with an OR as i thought that some of the results would contain the same value as $FLgetUID which would bring new problems when i run the array in the next sql query. this array will be ran in the next SQL with an implode in the WHERE id IN to return all the members approved friends so having the same value as $FLgetUID which is the logged in users ID in the array would also return themselves as one of there own friends. Im sure with what you have wrote i can adopt to what i need, the only thing im unsure of now is combining two arrays to make one? Thank you Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted November 23, 2008 Share Posted November 23, 2008 Im sure with what you have wrote i can adopt to what i need, the only thing im unsure of now is combining two arrays to make one? array_merge Quote Link to comment Share on other sites More sharing options...
laPistola Posted November 23, 2008 Author Share Posted November 23, 2008 Im sure with what you have wrote i can adopt to what i need, the only thing im unsure of now is combining two arrays to make one? array_merge should of checked php.net for that one sorry, thanks for the help Quote Link to comment Share on other sites More sharing options...
laPistola Posted November 23, 2008 Author Share Posted November 23, 2008 right something isn't right?? i have cheched the DB and it should return 6 into colume uid and 8 into colume fid all the extra code (like db calls on every query) is dreamweaver which its easier for me to keep in until im finshed then ill remove whats not needed. <?php $FLgetUID = 1; mysql_select_db($database_bedroomBlogsDB, $bedroomBlogsDB); $query_FLfriends_A_B_RS = "SELECT fid FROM friends_list WHERE `uid` = '$FLgetUID' AND status = '1'"; $FLfriends_A_B_RS = mysql_query($query_FLfriends_A_B_RS, $bedroomBlogsDB) or die(mysql_error()); $row_FLfriends_A_B_RS = mysql_fetch_assoc($FLfriends_A_B_RS); $totalRows_FLfriends_A_B_RS = mysql_num_rows($FLfriends_A_B_RS); mysql_select_db($database_bedroomBlogsDB, $bedroomBlogsDB); $query_FLfriends_B_A_RS = "SELECT `uid` FROM friends_list WHERE fid = '$FLgetUID' AND status = '1'"; $FLfriends_B_A_RS = mysql_query($query_FLfriends_B_A_RS, $bedroomBlogsDB) or die(mysql_error()); $row_FLfriends_B_A_RS = mysql_fetch_assoc($FLfriends_B_A_RS); $totalRows_FLfriends_B_A_RS = mysql_num_rows($FLfriends_B_A_RS); $FLab = array(); while($ab = mysql_fetch_assoc($FLfriends_A_B_RS)) { array_push($FLab,$ab['fid']); } $FLba = array(); while($ba = mysql_fetch_assoc($FLfriends_B_A_RS)) { array_push($FLba,$ba['uid']); } $FLabba = array_merge($FLab,$FLba); mysql_select_db($database_bedroomBlogsDB, $bedroomBlogsDB); $query_FLmembersGetRS = "SELECT username, photo, imgtype FROM members WHERE id IN ('" . implode(",",$FLabba) . "')"; $FLmembersGetRS = mysql_query($query_FLmembersGetRS, $bedroomBlogsDB) or die(mysql_error()); $row_FLmembersGetRS = mysql_fetch_assoc($FLmembersGetRS); $totalRows_FLmembersGetRS = mysql_num_rows($FLmembersGetRS); // these two echos are just just to see if its working echo "Username: ".$row_FLmembersGetRS['username']."<br />"; echo "logged in user id: ".$FLgetUID; mysql_free_result($FLFLgetMemberIdRS); mysql_free_result($FLfriends_A_B_RS); mysql_free_result($FLfriends_B_A_RS); mysql_free_result($FLmembersGetRS); ?> the pages shows as Username: logged in user id: 1 Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted November 23, 2008 Share Posted November 23, 2008 You should be using single quotes around your imploded list of IDs: $query_FLmembersGetRS = "SELECT username, photo, imgtype FROM members WHERE id IN ('" . implode(',',$FLabba) . "')"; Quote Link to comment Share on other sites More sharing options...
laPistola Posted November 23, 2008 Author Share Posted November 23, 2008 thank you for the reply, this still returns nothing? Quote Link to comment Share on other sites More sharing options...
laPistola Posted November 23, 2008 Author Share Posted November 23, 2008 just tested a few things //$FLabba = array_merge($FLab,$FLba); $FLabba = array("6","8"); worked, it echoed testing which is user id 6 tried $query_FLmembersGetRS = "SELECT username, photo, imgtype FROM members WHERE id IN ('" . implode(',',$FLab) . "')"; and $query_FLmembersGetRS = "SELECT username, photo, imgtype FROM members WHERE id IN ('" . implode(',',$FLba) . "')"; which both failed to show any user also i echoed $row_FLfriends_A_B_RS['fid'] and $row_FLfriends_B_A_RS['uid'] which shown Username: logged in user id: 1 ab query: 8 ba query: 6 Quote Link to comment Share on other sites More sharing options...
laPistola Posted November 24, 2008 Author Share Posted November 24, 2008 fixed it accured to me that the mysql_fetch_assoc($FLfriends_A_B_RS) and other was called before so couldn't be called again, removed them in the earlier code and it works now Thank you all your help Quote Link to comment Share on other sites More sharing options...
laPistola Posted November 28, 2008 Author Share Posted November 28, 2008 Right i have hit a problem today with this Everything works until i get to the implode which don't seem to be doing its thing the code is <?php $FLab = array(); while($ab = mysql_fetch_assoc($FLfriends_A_B_RS)) { array_push($FLab,$ab['fid']); } $FLba = array(); while($ba = mysql_fetch_assoc($FLfriends_B_A_RS)) { array_push($FLba,$ba['uid']); } $FLabba = array_merge($FLab,$FLba); $query_FLmembersGetRS = "SELECT `id`, username, photo, imgtype FROM members WHERE `id` IN ('" . implode(',',$FLabba) . "') ORDER BY username ASC"; $FLmembersGetRS = mysql_query($query_FLmembersGetRS, $bedroomBlogsDB) or die(mysql_error()); $totalRows_FLmembersGetRS = mysql_num_rows($FLmembersGetRS); ?> i have echo'ed $FLabba and it has the correct values 6 and 8 but when it goes through the query with the implode ist only seeing the first value in the array $FLabba which is 6, i confirmed this by echoing $totalRows_FLmembersGetRS whcih returned as 1, should be 2 Any ideas?? Thanks Quote Link to comment 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.