desjardins2016 Posted March 24, 2016 Share Posted March 24, 2016 This is frustrating me and I could use some help if you wouldn't mind - Below the While Loop I'm trying to add the //Get Images Tied To Vent block - and it breaks the whole script. I'm trying to have the script fetch each image that is located in the uploads WHERE the confessId matches ( hence why I placed it in the loop aswell ) other wise I don't have access to the confessId. Each image is stored in the uploads tied to the confessId so I'm simply trying to fetch each image that matches the Id and display them above the <i class="fa fa-quote-left"></i> <div class="confessbox"> <?php while ($row = mysqli_fetch_assoc($res)) { //Get Imgaes Tied To Vent $getImg = "SELECT * FROM uploads WHERE confessId = ".$row['confessId'].""; $imgSql = mysqli_query($mysqli, $getImg) or die(mysqli_error()); $imgFetch = mysqli_fetch_array($imgSql) or die(mysqli_error()); // Get Total Comments $comssql = "SELECT 'X' FROM comments WHERE confessId = ".$row['confessId']." AND isActive = 1"; $commentstotal = mysqli_query($mysqli, $comssql) or die('-4'.mysqli_error()); $totComments = mysqli_num_rows($commentstotal); if ($totComments == '1') { $comText = 'Comment'; } else { $comText = 'Comments'; } if ($row['totalViews'] == '1') { $viewText = 'View'; } else { $viewText = 'Views'; } $shareURL = $set['installUrl'].'page.php?page=view&confession='.$row['confessId']; ?> <div class="confession confHide"> <p> <img src="/uploads/<? echo $imgSrc; ?>"> <i class="fa fa-quote-left"></i> <?php if ($filterProfanity == '1') { echo nl2br(htmlspecialchars(filterwords($row['confessText']))); } else { echo nl2br(htmlspecialchars($row['confessText'])); } ?> <i class="fa fa-quote-right"></i> </p> <input type="hidden" id="confessId" name="confessId_<?php echo $count; ?>" value="<?php echo $row['confessId']; ?>" /> <div class="confession-footer"> <div class="likes"> <span class="label label-confess first liked"> <a href="" id="likeIt<?php echo $row['confessId']; ?>" class="likeIt_<?php echo $count; ?> text-success"> <i class="fa fa-smile-o"></i> <span id="likesVal_<?php echo $count; ?>"><?php echo $row['totalLikes']; ?></span> </a> </span> </div> <div class="dislikes"> <span class="label label-confess disliked"> <a href="" id="dislikeIt<?php echo $row['confessId']; ?>" class="dislike_<?php echo $count; ?> text-danger"> <span id="dislikesVal_<?php echo $count; ?>"><?php echo $row['totalDislikes']; ?></span> <i class="fa fa-frown-o"></i> </a> </span> </div> <span class="label label-confess"><?php echo timeago($row['postDate']); ?></span> <?php if ($row['hasImage'] != '0') { ?> <span class="label label-confess"><i class="fa fa-picture-o img"></i></span> <?php } ?> <span class="label label-confess last"><?php echo $row['totalViews'].' '.$viewText; ?></span> <span class="label label-confess last hasVoted text-danger"><strong><?php echo $onlyVoteOnceText; ?></strong></span> <div class="comments"> <a href="https://twitter.com/intent/tweet?text=<?php echo $set['siteName']; ?>%20Confession:%20<?php echo ellipsis($row['confessText'],65); ?>%20&url=<?php echo $shareURL; ?>" class="btn btn-tw btn-sm" target="_blank" data-toggle="tooltip" data-placement="top" title="<?php echo $twitterShareTooltip; ?>"> <i class="fa fa-twitter"></i> </a> <a href="https://plus.google.com/share?url=<?php echo $pageURL; ?>" class="btn btn-gp btn-sm" target="_blank" data-toggle="tooltip" data-placement="top" title="<?php echo $googleShareTooltip; ?>"> <i class="fa fa-google-plus"></i> </a> <a href="page.php?page=view&confession=<?php echo $row['confessId']; ?>" class="btn btn-comment btn-sm btn-icon"> <i class="fa fa-comments"></i> <?php echo $totComments.' '.$comText; ?> </a> </div> </div> <div class="clearfix"></div> </div> <?php $count++; } ?> </div> index.php Quote Link to comment https://forums.phpfreaks.com/topic/301078-confused-need-help-please/ Share on other sites More sharing options...
Solution ginerjm Posted March 24, 2016 Solution Share Posted March 24, 2016 Not a good solution to do a query inside a loop, let alone two of them! Why aren't you writing an all-inclusive query to avoid all that? That said - please define 'broke'. Programmers need precise information to help solve problems. Quote Link to comment https://forums.phpfreaks.com/topic/301078-confused-need-help-please/#findComment-1532426 Share on other sites More sharing options...
desjardins2016 Posted March 24, 2016 Author Share Posted March 24, 2016 TBH - it's not my script I'm simply trying to add a feature to it. Broke meaning it utilizing the or die() but not shooting out any errors... the site it's on is h3ll.xyz if that helps - the reason I was putting it in the loop is I needed the Id that is only available AFTER I called the loop and that whole block is a loop... can anyone suggest to me another way to accomplish this... Quote Link to comment https://forums.phpfreaks.com/topic/301078-confused-need-help-please/#findComment-1532427 Share on other sites More sharing options...
ginerjm Posted March 24, 2016 Share Posted March 24, 2016 Do you have error checking turned on? (my signature) If you can't tell us what is or isn't happening how do you think we can help you - besides telling you that the current process is just plain bad practice? Quote Link to comment https://forums.phpfreaks.com/topic/301078-confused-need-help-please/#findComment-1532428 Share on other sites More sharing options...
desjardins2016 Posted March 24, 2016 Author Share Posted March 24, 2016 Got it - thanks... Quote Link to comment https://forums.phpfreaks.com/topic/301078-confused-need-help-please/#findComment-1532431 Share on other sites More sharing options...
ginerjm Posted March 24, 2016 Share Posted March 24, 2016 Sounds like you've given up, because I know I wasn't able to give you anything other than some advice. ok - here is one problem: ['confessId']."" You end your string with two double quotes. Plus if confessed is not numeric you need single quotes around it. Turning on php error checking would have told you that. Again you do this: SELECT 'X' FROM comments... Why do you want to collect a set of rows with nothing but an X in them? Quote Link to comment https://forums.phpfreaks.com/topic/301078-confused-need-help-please/#findComment-1532435 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.