Jump to content

[SOLVED] select statement that does the same as this


scarhand

Recommended Posts

looking for a select statement that can replace this:

 

<?php

$sql = mysql_query("SELECT * FROM topics");

while ($row = mysql_fetch_array($sql))
{
  $id = $row['id'];
  
  $readcount = mysql_num_rows(mysql_query("SELECT * FROM readtopics where topicid='$id'"));

  if ($readcount != 0)
  {
    echo "this topic has been read";
  {
}

?>

 

any help would be greatly appreciated

Link to comment
Share on other sites

SELECT count(topicid) FROM readtopics where topicid in (SELECT id FROM topics) group by topicid

 

im trying to select stories that have not been read...

 

i have a table called "stories" and a table called "stories_read"

 

i tried this, but it does not work. i am not sure what the syntax for "NOT IN" is, i tried "!IN" but that does not work

 

heres what ive got:

 

the $myid variable is already declared as an integer

 

"SELECT * FROM stories WHERE id !IN (SELECT storyid FROM stories_read) AND readerid='$myid'"

 

might give you a better idea of what im trying to do here.

 

"readerid" is in the stories_read table.

Link to comment
Share on other sites

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.