Jump to content
Sign in to follow this  
techboy999

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

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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • 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.