Jump to content

[SOLVED] php select query help


nezbo

Recommended Posts

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...

Link to comment
https://forums.phpfreaks.com/topic/81657-solved-php-select-query-help/
Share on other sites

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...

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());

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.