RP Posted February 12, 2007 Share Posted February 12, 2007 Title says it all, im kinda new at this so im really hoping you guys can help me out. Ive been asked to make a SQL driven google maps mashup, the page has a submit form which a passes a varible to the SQL called $code, This varible is then used in the selct statement. My table has has multiple id feilds (id1, id2, id3, id4, id5) and id like to search all of them for the %code variable. I have gotten the code working perfectly searching just one of the id feilds (as below), but when i try to search more than one it returns 'no results'. include("dbinfo.php"); mysql_connect('$main',$username,$password); mysql_select_db($database) or die( "Unable to select database : " . mysql_error()); $result = mysql_query("SELECT * FROM gmaps WHERE id1 = '$code'"); if (!$result) { echo "no results"; } while($row = mysql_fetch_array($result)) { echo "var point = new GPoint(" . $row['long'] . "," . $row['lat'] . ");\n"; echo "var marker = createMarker(point, '<div id=\"infowindow\" style=\"white-space: nowrap;\"><p><strong>" . addslashes($row['station']) . "</strong><br /><a href=\"javascript:ajaxpage(\'ajaxfiles/" . addslashes($row['html']) . ".htm\',\'rightcolumn\')\">Learn More</a></p></div>');\n"; echo "map.addOverlay(marker);\n"; echo "\n"; } mysql_close(); Everything ive read says that to achive this all i need to do is this : $result = mysql_query("SELECT * FROM gmaps WHERE id1, id2, id3, id4, id5 = '$code'"); but that isnt working either, simply returning 'no result'. Ive tried with apostrophes, without apostrophes, with full text strings (idone, idtwo ect.), still no dice. any ideas? id really appreciate the help. Quote Link to comment https://forums.phpfreaks.com/topic/38219-solved-newbie-with-select-issues/ Share on other sites More sharing options...
trq Posted February 12, 2007 Share Posted February 12, 2007 This wreaks of poor design but..... SELECT * FROM gmaps WHERE id1 = '$code' || id2 = '$code' || id3 = '$code' || id4 = '$code' || id5 = '$code'; Quote Link to comment https://forums.phpfreaks.com/topic/38219-solved-newbie-with-select-issues/#findComment-183040 Share on other sites More sharing options...
RP Posted February 12, 2007 Author Share Posted February 12, 2007 Thanks that worked perfectly. Like i said im very new at this so im not suprided my code is designed badly, any tips would be appreicated. Quote Link to comment https://forums.phpfreaks.com/topic/38219-solved-newbie-with-select-issues/#findComment-183144 Share on other sites More sharing options...
fenway Posted February 13, 2007 Share Posted February 13, 2007 Sounds like the DB isn't normalized particularly well... Quote Link to comment https://forums.phpfreaks.com/topic/38219-solved-newbie-with-select-issues/#findComment-183622 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.