Jump to content

jedispyder

New Members
  • Posts

    6
  • Joined

  • Last visited

    Never

Everything posted by jedispyder

  1. Thanks, it works perfectly now!
  2. Ken2k7 > Sorry for putting it in the wrong forum, I saw other posts on problems with "If" here and thought this would be the right place. Sorry! Maq > I tried using that and it didn't work =o/ And I did look up mysql_query and tried several of those combos but none worked.
  3. I have a message I'm trying to return when I get a null result after doing a query, but can't seem to get it to work. I think the problem is finding out which variable to use to test when something is null or if I'm just testing it wrong. My code: //$result is the result of the query if ($result != "") { while($row = mysql_fetch_array($result)) { echo "Results returned."; } } else { echo "Sorry, but no results were returned."; } It properly returns results when something is returned, but if nothing is returned then it doesn't return the "Sorry, but not results were returned." Another code I tried that still didn't work was: if (!$result) { echo "Sorry, but no results were returned."; } I've tried including it within the While and using $row but still haven't had any luck. Any help?
  4. Awesome! Thank you very much, works perfectly. I don't know I didn't try out "Where", guess it was because I kept seeing the "Join" and thought it would be that.
  5. Thanks, I forgot about that possibility. So when I looked up many-to-many, from what I understood I need a 3rd table to reference the two. So I created: Creator_Books [i relabeled "Comics" to "Books" for short naming purposes] bid (int) which links to the Books.id cid (int) which links to the Creators.id And I'm guessing I now need to remove the Writer01,...,Illustrator01,..., from the Books database, since that info is being fed from the intermediary Creator_Books table, correct? I'm still having trouble with it, so I think I may have the wrong relationship set up. In phpMyAdmin, I set up the relationship while in the Creator_Books table, linking them to the correct value. Should it be the other way around, linking from the Books and Creators table into the Creator_Books table? The Query I tried: SELECT Books.name, Books.num, Creators.name FROM Books, Creators LEFT JOIN Creator_Books ON Creator_Books.cid = Creators.id And while it did return results, it didn't return the right results. For example, I was trying for it to say: Creator X worked on Book X and Book Y Creator Y worked on Book X, and Book Z It returned that Creator X worked on Book X, Y, Z and Creator Y worked on Book X,Y,Z as well as listing them multiple times for each Book. I'm guessing I have the Join wrong, but I tried it several ways and every time I tried doing "Creator_Books.bid = Books.id" it gave me an error...
  6. Hello all, I'm very new to PHP and MySQL. I'm working on a comic book database and for my question I'll describe 2 of the tables: Table: Creators id [int, primary key] (just the typical id) name [varchar, foreign key] (this contains the names of comic book creators) Table: Comics id [int, primary key] (just the typical id) num (contains issue number for the comic) writer01 [int, links to Creator.id] writer02 [int, links to Creator.id, null] writer03 [int, links to Creator.id, null] illustrator01 [int, links to Creator.id] illustrator02 [int, links to Creator.id, null] illustrator03 [int, links to Creator.id, null] Occasionally there are multiple writers/illustrator on a comic book, so I'd like to be able to display all of that information if available (some issues may have just a 1 writer/1 illustrator). When I tried a WHERE to display just Comics.writer01, it worked fine. When I tried to create a WHERE to display Comics.writer01 and Comics.writer02 I got a "0 results returned". MySQL Query for only Comics.writer01 SELECT Comics.num, Creators.name FROM Comics, Creators WHERE Comics.writer01 = Creators.id MySQL Query for both Comics.writer01 and Comics.writer02 SELECT Comics.num, Creators.name FROM Comics, Creators WHERE Comics.writer01 = Creators.id AND Comics.writer02 = Creators.id As I stated earlier, I'm very new to MySQL (and really databases in general). I have looked through a couple books trying to fully understand JOINS but just don't fully get it yet. Sorry if its something simple that most people understand, its just evidently taking me longer than I thought...
×
×
  • 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.