Danny
Danny

Reputation: 1

select and print everything from a table except 1

i have a question. i have a table named news that has rows such as;

news_id ,   timestamp , login_id ,  headline,

i would like to echo all the headlines and timestamps that go with them except for login_id = 1

How can i achieve this?

i would like to do something like

select timestamp, headline, login_id;
echo everything exept login_id = 1;

printed on a table?

thank you for reading.

Upvotes: 0

Views: 469

Answers (4)

Gaurav
Gaurav

Reputation: 28755

$reuslt = mysql_query('SELECT timestamp, headline, login_id FROM news WHERE login_id <> 1');
echo '<table>';
while($row = mysql_fetch_assoc($result))
{
  echo "<tr><td>".$row['timestamp']."</td><td>".$row['headline']."</td></tr>";
}

echo "</table>";

Upvotes: 0

TonyTheJet
TonyTheJet

Reputation: 527

<?php
$query=mysql_query("SELECT timestamp, headline, login_id FROM news WHERE login_id <> 1");
while ($row=mysql_fetch_assoc($query)){
    echo $row['timestamp'].' '.$row['headline'].' '.$row['login_id'];
}
?>

Upvotes: 1

Stefan H
Stefan H

Reputation: 6683

The sql query you would use is

SELECT timestamp
     , headline
     , login_id
  FROM news
 WHERE login_id <> 1

Upvotes: 0

Ted Hopp
Ted Hopp

Reputation: 234795

SELECT timestamp, headline, login_id FROM my_table WHERE login_id != 1;

Upvotes: 0

Related Questions