Jump to content

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

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
This thread is more than a year old. Please don't revive it unless you have something important to add.

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.

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