Jump to content

select


Jaynesh

Recommended Posts

Hello. How can I add a column without effects the query?

 

For example, when I add another column in SELECT, it produces each output as double.

I want to add another column because I want to create an if statement with it in the while output.

 

SELECT Users.id, Posts.post, Users.username, Posts.post_id, Posts.karma_up, Posts.karma_down

FROM Posts, Users, Friends

Link to comment
https://forums.phpfreaks.com/topic/241512-select/
Share on other sites

$friendfeed2 = 
"SELECT dbUsers.id, dbPosts.post, dbUsers.username, dbPosts.post_id, dbPosts.karma_up, dbPosts.karma_down 
FROM dbPosts, dbUsers, dbFriends, dbKarma
WHERE (dbPosts.post_id NOT IN (SELECT post_id FROM dbDownvote WHERE user_id = $user)
AND dbPosts.username_id = dbUsers.id
AND dbFriends.user_id = $user 
AND dbFriends.friend_id = dbPosts.username_id
AND dbFriends.status = 1) 

OR 

(dbPosts.post_id NOT IN (SELECT post_id FROM dbDownvote WHERE user_id = $user)
AND dbPosts.username_id = dbUsers.id
AND dbFriends.friend_id = $user 
AND dbFriends.user_id = dbPosts.username_id
AND dbFriends.status = 1) 

UNION SELECT dbUsers.id, dbPosts.post, dbUsers.username, dbPosts.post_id, dbPosts.karma_up, dbPosts.karma_down 
FROM dbPosts, dbUsers, dbPosts_share, dbFriends
WHERE (dbPosts.post_id NOT IN (SELECT post_id FROM dbDownvote WHERE user_id = $user)
AND dbPosts.username_id = dbUsers.id 
AND dbPosts_share.user_id = dbFriends.friend_id 
AND dbFriends.user_id = $user 
AND dbPosts_share.post_id = dbPosts.post_id
AND dbFriends.status = 1)

OR

(dbPosts.post_id NOT IN (SELECT post_id FROM dbDownvote WHERE user_id = $user)
AND dbPosts.username_id = dbUsers.id 
AND dbPosts_share.user_id = dbFriends.user_id 
AND dbFriends.friend_id = $user 
AND dbPosts_share.post_id = dbPosts.post_id
AND dbFriends.status = 1)

UNION SELECT dbUsers.id, dbPosts.post, dbUsers.username, dbPosts.post_id, dbPosts.karma_up, dbPosts.karma_down 
FROM dbPosts, dbUsers
WHERE dbPosts.username_id = dbUsers.id 
AND username_id = $user";

 

while( $i < $row = mysql_fetch_array($friendfeed_query2))
  {
  if ($row['id'] == $user)
  {
  echo $div_mypostbox;
  }
  else
  {
  echo $div_postbox;
  }
  $karma_up = $row['karma_up'];
  $karma_down = $row ['karma_down'];
  $karma_total = $karma_up - $karma_down;
  echo "<a href=vote.php?up=" . $row['post_id'] . "><</a>";
  echo $karma_total;
  echo "<a href=vote.php?down=" . $row['post_id'] . ">></a>";
  echo $break;
  
  $post = $row['post'];
  $post_wrap = wordwrap($post, 50, "\n", true);
  echo "$post_wrap";
  echo $div_end;
  echo $div_postfooter;
  echo "Submitted by " . $row['username'] . "<br>";

  
  if ($row['id'] == $user) {
  echo "<a href=delete.php?id=" . $row['post_id'] . ">delete</a><br>";
  }
  echo  $div_end, $div_end, $div_end, $break;
  }

 

I want to add a column in, to add an if command within the loop. I want to add something similar to what I've done with " if ($row['id'] == $user)" in the 2nd quote.

 

 

Link to comment
https://forums.phpfreaks.com/topic/241512-select/#findComment-1240628
Share on other sites

In simpler terms it always gives me multiple results of each row when I have a table that is not in SELECT.

 

for e.g

 

"SELECT dbPosts.post, dbPosts.username_id

FROM dbPosts, dbUsers

WHERE dbPosts.username_id = 10";

 

The dbUsers table isnt in the SELECT section, so it gives me multiple results of each row. How do I stop this from happening.

Link to comment
https://forums.phpfreaks.com/topic/241512-select/#findComment-1240642
Share on other sites

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.