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

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.

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.