ThomasBalaban Posted June 11, 2013 Share Posted June 11, 2013 Hello, I am somewhat new to php and I am trying to figure something out. Here is my relevant code.... function run_my_query3($query){ //$serverHandle = mysql_connect('localhost', 'root'); $serverHandle = mysql_connect('localhost:8888', 'root', 'root', 'user_table'); //$serverHandle = mysql_connect('localhost', 'afterlyf','ev730l500c','user_table'); if($serverHandle == false){ die("bad server connection".mysql_error()); } $myDb = mysql_select_db('user_table') or die ('DB Problem - '.mysql_error()); $result4 = mysql_query($query) or die ('Query Problem - '.$query.mysql_error()); mysql_close($serverHandle); return $result4; } $result1 = run_my_query3("SELECT decklists.userName, decklists.userPicture, decklists.decklistName, decklists.decklistSideExtra, decklists.decklistDate FROM decklists, watchers WHERE '$_SESSION[userName]' = watchers.watcherName AND '$_SESSION[userName]' <> watchers.userName ORDER BY decklistDate DESC"); <?php while($row = mysql_fetch_array($result1)){ $userName = $row['userName']; $userPictureDeck = $row['userPicture']; $decklistsId = $row['decklistsId']; $decklistName = $row['decklistName']; $decklistMain = $row['decklistMain']; $decklistSideExtra = $row['decklistSideExtra']; $decklistDate = $row['decklistDate']; ?> <p>Deck Uploaded by <?php echo $userName; ?>: <?php echo $decklistName; ?><span> <?php echo $decklistDate; ?> </span></p> <?php } ?> Table watchId userName watcherName watcherPicture 110 CrunchTheWicked Cloud adamVajoka.jpg112 Afterlyfe Cloud adamVajoka.jpg108 chewieAFG Cloud adamVajoka.jpg I understand why it is repeating three times, which is because Cloud is the current user and his name is used three times within the table. What is the best way to get past this? Quote Link to comment Share on other sites More sharing options...
DaveyK Posted June 11, 2013 Share Posted June 11, 2013 - Please show your code in code blocks, identified by the "<>" icon on the top. - Also, you dont have to open and close your connection on every query. MySQL will use the last opened connection so you can just set it at the beginning of the file, and close it at the end of the file. (or in init/footer files respectively). - what happens if cloud changes his username? Huge loss of data. - You dont have to set new variables if your stuff is already available in a variable. Ask yourself: what do I want from this code anyway? You say it displays 3 times, which is correct according to the table. What do you want it to display then? 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.