seefor Posted April 1, 2009 Share Posted April 1, 2009 I’m new to php so bare with me Here is my problem: I have two tables in the same database – Table1 Ip city 10.0.10 NY 10.0.20 LA 10.0.30 CH Table2 Ip info1 info2 info3 info4 10.0.10.1 123 123 123 123 10.0.10.2 123 123 123 123 10.0.10.3 123 123 123 123 10.0.10.4 123 123 123 123 10.0.20.1 123 123 123 123 10.0.20.2 123 123 123 123 10.0.20.3 123 123 123 123 10.0.20.4 123 123 123 123 10.0.30.1 123 123 123 123 10.0.30.2 123 123 123 123 10.0.30.3 123 123 123 123 10.0.30.4 123 123 123 123 I was trying to query something like this: SELECT * FROM db. Table1, db. Table2 WHERE db.Table1.ip LIKE db. Table2.Ip.% Then the output looks like this: NY 10.0.10.1 123 123 123 123 10.0.10.2 123 123 123 123 10.0.10.3 123 123 123 123 10.0.10.4 123 123 123 123 LA 10.0.20.1 123 123 123 123 10.0.20.2 123 123 123 123 10.0.20.3 123 123 123 123 10.0.20.4 123 123 123 123 CH 10.0.30.1 123 123 123 123 10.0.30.2 123 123 123 123 10.0.30.3 123 123 123 123 10.0.30.4 123 123 123 123 I hope this makes sense Also any help would be greatly appreciated ;D Quote Link to comment https://forums.phpfreaks.com/topic/152001-php-and-two-mysql-statement/ Share on other sites More sharing options...
Maq Posted April 1, 2009 Share Posted April 1, 2009 1 - This isn't a PHP problem, but don't bother moving it, it's on the way. 2 - What exactly is the problem because: Here is my problem: I have two tables in the same database – isn't a problem, it's normal. Quote Link to comment https://forums.phpfreaks.com/topic/152001-php-and-two-mysql-statement/#findComment-798289 Share on other sites More sharing options...
seefor Posted April 1, 2009 Author Share Posted April 1, 2009 Sorry about where I posted this and for my lack of problem description. I'm using PHP with mySQL database. I really don't know how to do it and would like some help trying to figuring it out. Thanks, SeeFor Quote Link to comment https://forums.phpfreaks.com/topic/152001-php-and-two-mysql-statement/#findComment-798295 Share on other sites More sharing options...
fenway Posted April 2, 2009 Share Posted April 2, 2009 Sounds like you need UNION. Quote Link to comment https://forums.phpfreaks.com/topic/152001-php-and-two-mysql-statement/#findComment-799315 Share on other sites More sharing options...
seefor Posted April 2, 2009 Author Share Posted April 2, 2009 First I would like to say sorry about not reading the Sticky about posting, I posted under PHP. Sounds like you need UNION. Union is great but I only can select the same amount of rows. SELECT ipAddress FROM sencore.1066 UNION SELECT IPAddress FROM sencore.66ipAddress WHERE sencore.66ipAddress.IPAddress LIKE "sencore.1066.ipAddress.%" sencore.1066 have about 30 fields sencore.66ipAddress only have 2 Any other suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/152001-php-and-two-mysql-statement/#findComment-799577 Share on other sites More sharing options...
fenway Posted April 2, 2009 Share Posted April 2, 2009 You can "fake" fields with "AS". Quote Link to comment https://forums.phpfreaks.com/topic/152001-php-and-two-mysql-statement/#findComment-799640 Share on other sites More sharing options...
seefor Posted April 3, 2009 Author Share Posted April 3, 2009 Do you mind giving me an example? I tried googling it but couldn't find a good one Thanks again for all your help. Quote Link to comment https://forums.phpfreaks.com/topic/152001-php-and-two-mysql-statement/#findComment-800004 Share on other sites More sharing options...
fenway Posted April 3, 2009 Share Posted April 3, 2009 Which fields do you need from the 30-column table? Quote Link to comment https://forums.phpfreaks.com/topic/152001-php-and-two-mysql-statement/#findComment-800311 Share on other sites More sharing options...
seefor Posted April 3, 2009 Author Share Posted April 3, 2009 CREATE TABLE `sencore`.`1066` ( `id` int(11) NOT NULL auto_increment, `IPAddress` varchar(100) default NULL, `displaymode` varchar(100) default NULL, `analogoutput` varchar(100) default NULL, `formatmode` varchar(100) default NULL, `videoformat` varchar(100) default NULL, `failuremode` varchar(100) default NULL, `line4` varchar(100) default NULL, `line5` varchar(100) default NULL, `line6` varchar(100) default NULL, `line7` varchar(100) default NULL, `line8` varchar(100) default NULL, `line9` varchar(100) default NULL, `line10` varchar(100) default NULL, `line11` varchar(100) default NULL, `line12` varchar(100) default NULL, `line13` varchar(100) default NULL, `line14` varchar(100) default NULL, `line15` varchar(100) default NULL, `pSNMPserver` varchar(100) default NULL, `bSNMPserver` varchar(100) default NULL, `read` varchar(100) default NULL, `write` varchar(100) default NULL, `pid` varchar(100) default NULL, `format1` varchar(100) default NULL, `format2` varchar(100) default NULL, `format3` varchar(100) default NULL, `format4` varchar(100) default NULL, `chromaformat` varchar(100) default NULL, `level1` varchar(100) default NULL, `level2` varchar(100) default NULL, `asitype` varchar(100) default NULL, `mer` varchar(100) default NULL, `channel` varchar(100) default NULL, `lowlevel` varchar(100) default NULL, `lowmer` varchar(100) default NULL, `modulationmode` varchar(100) default NULL, `channelplan` varchar(100) default NULL, `CurrentInput` varchar(100) default NULL, `BackupInput` varchar(100) default NULL, `ServiceSelectionMode` varchar(100) default NULL, `ServiceNumber` varchar(100) default NULL, `Notes` varchar(100) default NULL, `alias` varchar(100) default NULL, `sencore` varchar(100) default NULL, `unitversion` varchar(100) default NULL, `decoderVersion` varchar(100) default NULL, `tssid` varchar(100) default NULL, `stationname` varchar(100) default NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM AUTO_INCREMENT=8503 DEFAULT CHARSET=latin1; CREATE TABLE `sencore`.`66ipAddress` ( `ipAddress` varchar(45) default NULL, `cityCode` varchar(45) default NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1; SELECT ipAddress FROM sencore.1066 UNION SELECT IPAddress FROM sencore.66ipAddress WHERE sencore.66ipAddress.IPAddress LIKE "sencore.1066.ipAddress.%" Trying to do a Union with a LIKE statement to see how that works I'm really a newbie at all of this Thanks again for all your help fenway ;D ;D Quote Link to comment https://forums.phpfreaks.com/topic/152001-php-and-two-mysql-statement/#findComment-800544 Share on other sites More sharing options...
fenway Posted April 3, 2009 Share Posted April 3, 2009 That doesn't answer my question... what do you want the output to look like? Quote Link to comment https://forums.phpfreaks.com/topic/152001-php-and-two-mysql-statement/#findComment-800591 Share on other sites More sharing options...
seefor Posted April 8, 2009 Author Share Posted April 8, 2009 First off, many thanks for reply to my questions fenway What I would like my out to look like: cityCode IPAddress Notes alias sencore unitversion decoderVersion tssid stationname cityCode IPAddress Notes alias sencore unitversion decoderVersion tssid stationname Each with a new cityCode I hope that make sense Quote Link to comment https://forums.phpfreaks.com/topic/152001-php-and-two-mysql-statement/#findComment-804897 Share on other sites More sharing options...
seefor Posted April 13, 2009 Author Share Posted April 13, 2009 anyluck fenway Quote Link to comment https://forums.phpfreaks.com/topic/152001-php-and-two-mysql-statement/#findComment-808700 Share on other sites More sharing options...
fenway Posted April 14, 2009 Share Posted April 14, 2009 Still confused... why 2 statements/ Quote Link to comment https://forums.phpfreaks.com/topic/152001-php-and-two-mysql-statement/#findComment-810124 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.