Jump to content

telabrun

New Members
  • Posts

    3
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

telabrun's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Okay, so I\'ve been playing with this a little bit, and now I\'m looking at something of a simpler query. It no longer involves JOIN; I believe I\'ve tracked the problem to something in the manner in which PHP interacts with SELECT in a FOR loop. I understand that it\'s probably bad style to perform the JOIN-type operation in two steps, and I know for certain that it\'s slower than a JOIN operation. However, I\'m trying to get this to work in any way that I can. for($k = 1; $k <= $nrows; $k++) { $query = "select id, time, title, user from article where id=\'$k\'"; $return = mysql_query($query); $row = mysql_fetch_array($return); extract($row); $query = "select fname, lname from user where user=\'$user\'"; echo $query; echo "<p></p>"; } produces: select fname, lname from user where user=\'joe\' select fname, lname from user where user=\'kim select fname, lname from user where user=\'dale select fname, lname from user where user=\'joe\' Notice that the second single quote is missing for all user except joe (who happens to be the user that occupies the first row). What gives? Thanks again. telabrun daggoth
  2. The article.user value is, essentially an \"author\" field, and it is generated immediately when a new row is added to the article table. This is ensured by a login. Perhaps a clearer statement of my question is: What query can I use in order to obtain a result that returns the names of all the users, not just the first one, without adding any other columns to either table? Quite simply, I would like to obtain this result: id / user / title / body / name 1 / joe / monkeys / I like them / Joseph Ape 2 / kim / crows / they eat monkeys / Kimberly Primate 3 / joe / squirrels / can fly / Joseph Ape The only difference here is that Kimberly Primate\'s name appears (i.e., is JOINed); with all of the queries I\'ve tried so far, that cell is NULL. It seems to me that a JOIN should exist to perform this, without too much difficulty. The mySQL manual suggests as much, but the subtleties of the JOIN syntax, apparently, elude me. Thanks again. telabrun daggoth
  3. I\'m attempting to use JOIN--any type that I can get to work--but receiving somewhat strange results. I have a table \"article\" (columns \"id\", \"user\", \"title\", and \"body\") and a table \"user\" (columns \"user\" and \"name\"). In those tables, let\'s say, are: article: id / user / title / body 1 / joe / monkeys / I like them 2 / kim / crows / they eat monkeys user: user / name joe / Joseph Ape kim / Kimberly Primate I would like to have a result that looks like id / user / title / body / name 1 / joe / monkeys / I like them / Joseph Ape 2 / kim / crows / they eat monkeys / Kimberly Primate so I use the query SELECT id, user, title, body, name FROM article LEFT JOIN user ON article.user = user.user and I get 1 / joe / monkeys / I like them / Joseph Ape 2 / kim / crows / they eat monkeys / NULL If I use an inner join, I get only the first line. Oddly enough, if I add another article by user joe, it displays perfectly. For example, if I add values 3 / joe / squirrels / can fly to the article table, and run the above query, I get 1 / joe / monkeys / I like them / Joseph Ape 2 / kim / crows / they eat monkeys / NULL 3 / joe / squirrels / can fly / Joseph Ape It seems to me that the join condition article.user = user.user is operating somewhat differently than advertised; instead of setting the columns equal to each other, it appears to take the value of that column in the first row of the user table, and use that as a join condition: i.e., if the user is joe, then display his name; if it is anyone else, do not. This is as bizarre, I think, as it is frustrating; if anybody has any ideas, I would be profoundly grateful. cheers telabrun daggoth
×
×
  • 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.