What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » MySQL and PHP - using 2 tables in one query?

Pages: (3): « First « 1 [ 2 ] 3 » Last »
MySQL and PHP - using 2 tables in one query?
Author: Message:
Jimbo
Veteran Member
*****

Avatar

Posts: 1650
Reputation: 18
32 / Male / Flag
Joined: Jul 2006
O.P. RE: MySQL and PHP - using 2 tables in one query?
[slightly offtopic]
<? and ?> tags are short_open_tags, and I always use these, so they are enabled. Since I rent my own server box, and host everything from there, I can change anything I like in my PHP.ini.
[/slightly offtopic]
01-17-2010 07:57 PM
Profile E-Mail PM Find Quote Report
Chrissy
Senior Member
****

Avatar

Posts: 850
Reputation: 5
29 / Male / Flag
Joined: Nov 2009
RE: MySQL and PHP - using 2 tables in one query?
Ok - I see!
01-17-2010 08:04 PM
Profile E-Mail PM Web Find Quote Report
Adeptus
Senior Member
****


Posts: 732
Reputation: 40
Joined: Oct 2005
RE: MySQL and PHP - using 2 tables in one query?
First of all, your questions are welcome.  I just think you would benefit from knowing what kind of functionality is out there when querying a typical SQL engine.

Secondly, I recommend testing queries in an interactive tool before you put them in code, so that when things don't work you don't have to guess whether it's a problem with the query or the PHP code.  With mysql, you can do this on the command line, using a web based tool or one of several Windows GUI tools.

If you are getting no results, a good test might be to drop your WHERE clause and see what happens without it.  Sure, you will probably then get results you don't want, but if that works it's a good clue where to look for the issue.

This post was edited on 01-17-2010 at 08:14 PM by Adeptus.
01-17-2010 08:13 PM
Profile E-Mail PM Find Quote Report
MeEtc
Patchou's look-alike
*****

Avatar
In the Shadow Gallery once again

Posts: 2200
Reputation: 60
38 / Male / Flag
Joined: Nov 2004
Status: Away
RE: MySQL and PHP - using 2 tables in one query?
Try running the query as-is in phpmyadmin, to see what it results in. You might be able to drop the "INNER" from the inner join part, to see if this has any impact.
[Image: signature/]     [Image: sharing.png]
I cannot hear you. There is a banana in my ear.
01-17-2010 08:15 PM
Profile PM Web Find Quote Report
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
32 / Male / Flag
Joined: Apr 2004
RE: MySQL and PHP - using 2 tables in one query?
I don't know which version of MySQL you're running and I'm not a MySQL expert myself, but perhaps adding "AS" between the table names and its alias may help? Or maybe it's the new line characters? Have you tried checking for errors from MySQL first?
php code:
<?php
$result = mysql_query("SELECT a.*, b.playername "
    . "FROM upgrades AS a INNER JOIN zm_timetracker AS b ON a.steamid = b.steamid "
    . "WHERE b.playername LIKE '%$search2%'") or die("MySQL error: " . mysql_error());
?>
If that doesn't resolve the issue, try running the query in something like phpMyAdmin and see if the query works as expected. At least that'll tell us whether it's the query or the PHP that's faulty.
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
01-17-2010 08:19 PM
Profile E-Mail PM Web Find Quote Report
Jimbo
Veteran Member
*****

Avatar

Posts: 1650
Reputation: 18
32 / Male / Flag
Joined: Jul 2006
O.P. RE: MySQL and PHP - using 2 tables in one query?
When running that query using PHP, I now get all results from table A returned, no matter what I type into the search.

When running the following query in navicat:
sql code:
SELECT a.*, b.name FROM upgrades AS a INNER JOIN zm_timetracker AS b ON a.steamid = b.steamid WHERE b.name LIKE '%cherry%'
I get 4 results returned, with all their corresponding fields in TableA, and all of which have "cherry" in their name in tableB.

EDIT: Forget that, I found what I did wrong. Thank you so much everyone for your help :)

This post was edited on 01-17-2010 at 08:48 PM by Jimbo.
01-17-2010 08:39 PM
Profile E-Mail PM Find Quote Report
Adeptus
Senior Member
****


Posts: 732
Reputation: 40
Joined: Oct 2005
RE: MySQL and PHP - using 2 tables in one query?
quote:
Originally posted by Jimbo
When running the following query in navicat:

    SQL code:
    SELECT a.*, b.name FROM upgrades AS a INNER JOIN zm_timetracker AS b ON a.steamid = b.steamid WHERE b.name LIKE '%cherry%'

I get 4 results returned, with all their corresponding fields in TableA, and all of which have "cherry" in their name in tableB.
That is what I would expect -- is that not what you wanted?
01-17-2010 08:55 PM
Profile E-Mail PM Find Quote Report
Jimbo
Veteran Member
*****

Avatar

Posts: 1650
Reputation: 18
32 / Male / Flag
Joined: Jul 2006
O.P. RE: MySQL and PHP - using 2 tables in one query?
Yeah, it is. Thanks. (Check my recent post edit :P)
01-17-2010 09:16 PM
Profile E-Mail PM Find Quote Report
Adeptus
Senior Member
****


Posts: 732
Reputation: 40
Joined: Oct 2005
RE: MySQL and PHP - using 2 tables in one query?
Great.  You should come on IRC (#banana) sometime.  :)
01-17-2010 09:22 PM
Profile E-Mail PM Find Quote Report
NanaFreak
Scripting Contest Winner
*****


Posts: 1476
Reputation: 53
32 / Male / Flag
Joined: Jul 2006
RE: MySQL and PHP - using 2 tables in one query?
Jimbo, a site that one of my teachers got me (and my class) to use to learn and try SQL is http://sqlzoo.net/

though that is mainly to get you to learn and remember some stuff... i would try and learn the basics from another site first and then use that once you 'get the hang' of it
01-18-2010 01:49 AM
Profile PM Find Quote Report
Pages: (3): « First « 1 [ 2 ] 3 » Last »
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On