techboy999 Posted May 24, 2017 Share Posted May 24, 2017 I am sitting here and twisting my head for a mysql query that need select 4 records with a catogory and needs check that 4 records in an other table for an userid to check if a message have been send to a customer already if it have been I need to run the query again : $result=mysqli_query($conn, "Select * from messages where approved='1' AND catogory='".$catogory."' ORDER by rand() LIMIT 4"); while($row=mysqli_fetch_array($result)) $result=mysqli_query($conn, "select * from send_messages where message_id='".$id."' AND username='".$username."'"); while($row=mysqli_fetch_array($result)) $rowcount=mysqli_num_rows($result); if($rowcount > "0"){ header("location: index.php?username=$username"); exit(); } echo "<input type='radio' id='test' name='message' value='$row[id]'><label for='test'>$row[message]</label><br>"; echo "</form>"; The code works good for 1 record but I need to print the 4 records out and then I try this code it shows nothing Quote Link to comment https://forums.phpfreaks.com/topic/304001-find-4-records-in-database-and-check-if-exist-in-other-table/ Share on other sites More sharing options...
taquitosensei Posted May 31, 2017 Share Posted May 31, 2017 somebody else will tell you not to use mysqli for the sql statement you could use a join and only have one statement select * from messages m join send_messages sm on m.id=sm.message_id and m.username=sm.username where m.catogory='".$catogory."' and m.approved=1 order by rand() limit 4 Quote Link to comment https://forums.phpfreaks.com/topic/304001-find-4-records-in-database-and-check-if-exist-in-other-table/#findComment-1546960 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.