Jump to content

find 4 records in database and check if exist in other table


techboy999

Recommended Posts

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.