nezbo Posted December 14, 2007 Share Posted December 14, 2007 Hi all I have this code and i cant get to bring back the results for the $whereCond2 properly, it brings back the info for the or Problem like '%$find%'. the info for or PassedTo='$thenames' is not coming back. i am not to sure what is going on but it might just be something i am doing. I can echo the $whereCond2 and it comes back with or Problem like '%lynne o%' or PassedTo='19' so the while code is working but it is not working in the SELECT * FROM $table $whereCond $whereCond2 ORDER BY $orderBy $asc_desc etc... any help please Neil $table = "job"; $whereCond = "WHERE Completed='Yes' "; //WHERE xxxx = 'xxxx'; $orderBy = "JobID"; $asc_desc = "DESC"; //Search Pages for contents... if (isset($_REQUEST[s])) { $find = $_REQUEST[w]; } else { $find = $_POST[find]; } if ($find) { $getNames = mysql_query("SELECT * FROM person WHERE FullName like '%$find%'"); $num_rows = mysql_num_rows($getNames); $whereCond2 = $whereCond2 . " or Problem like '%$find%'"; if ($num_rows != 0) { while ($getNames5 = mysql_fetch_array($getNames)) { $thenames = $getNames5['CallID']; $getStuff = " or PassedTo='$thenames'"; $whereCond2 = $whereCond2 . $getStuff; } } } else { $whereCond2 = ""; } include("pages.php"); $result = mysql_query("SELECT * FROM $table $whereCond $whereCond2 ORDER BY $orderBy $asc_desc LIMIT $start, $display")or die(mysql_error()); // Sets the heading of the Check jobs page... Quote Link to comment Share on other sites More sharing options...
scottybwoy Posted December 14, 2007 Share Posted December 14, 2007 You need to put quotes the other side of the % like : $getNames = mysql_query("SELECT * FROM person WHERE FullName like '%" . $find . "%'"); You can't use $vars within single 'quotes' Quote Link to comment Share on other sites More sharing options...
marcus Posted December 14, 2007 Share Posted December 14, 2007 When it comes to SQL queries, the exception is made. The query seems find, just put the or die statement like you did for the other one. Quote Link to comment Share on other sites More sharing options...
nezbo Posted December 17, 2007 Author Share Posted December 17, 2007 I have changed the code and i still cant get it to pick up the calls logged by the the user. the user id is a number and i have changed thd code, but i still cant get it to work. //Make extra pages... $table = "job"; $whereCond = "WHERE Completed='Yes' "; //WHERE xxxx = 'xxxx'; $orderBy = "JobID"; $asc_desc = "DESC"; //Search Pages for contents... if (isset($_REQUEST[s])) { $find = $_REQUEST[w]; } else { $find = $_POST[find]; } if ($find) { $getNames = mysql_query("SELECT * FROM person WHERE FullName like '%" . $find . "%'") or die(mysql_error()); $num_rows = mysql_num_rows($getNames); $whereCond2 = $whereCond2 . " || Problem like '%" . $find . "%'"; if ($num_rows != 0) { while ($getNames5 = mysql_fetch_array($getNames)) { $thenames = $getNames5['CallID']; $getStuff = " || PassedTo=" . $thenames; $whereCond2 = $whereCond2 . $getStuff; } } } else { $whereCond2 = ""; } echo $theWhere = $whereCond . $whereCond2; include("pages.php"); $result = mysql_query("SELECT * FROM $table " . $whereCond . $whereCond2 . " ORDER BY $orderBy $asc_desc LIMIT $start, $display")or die(mysql_error()); // Sets the heading of the Check jobs page... Quote Link to comment Share on other sites More sharing options...
nezbo Posted December 17, 2007 Author Share Posted December 17, 2007 I have just restarted teh code and it works fine now, i am not to sure what was wrong but this is the correct code. $table = "job"; $whereCond = "WHERE Completed='Yes'"; //WHERE xxxx = 'xxxx'; $orderBy = "JobID"; $asc_desc = "DESC"; //Search Pages for contents... if (isset($_REQUEST[s])) { $find = $_REQUEST[w]; } else { $find = $_POST[find]; } if ($find) { $theName = mysql_query("SELECT * FROM person WHERE FullName LIKE '%" . $find . "%'"); while ($theNames2 = mysql_fetch_array($theName)) { $theNames2 = " or PassedTo = \"" . $theNames2['CallID'] . "\""; $theNames = $theNames . $theNames2; } $whereCond2 = " and (Problem like \"%" . $find . "%\" " . $theNames . ")"; } else { $whereCond2 = ""; } include("pages.php"); $result = mysql_query("SELECT * FROM $table $whereCond $whereCond2 ORDER BY $orderBy $asc_desc LIMIT $start, $display")or die(mysql_error()); Quote Link to comment 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.