SELECT query -mysql/php

I need my search/select query to result in the row searched from my input text aka ‘searchby’ but with the added =’$searchby’ it delivers no data but just ea_reg $searchby gains all data.

I only want it to deliver rows that include $searchby. :frowning: please help

[php]
$searchby = $_POST[“searchby”];

	$db_host = "localhost";
	$db_user = "++++";
	$db_pass = "++++";
	$db_base = "+++";

$db_server = mysql_connect($db_host, $db_user, $db_pass);

if (!$db_server) die("unable to connect: " . mysql_error());

mysql_select_db($db_base)
	or die("Unable to select database: " . mysql_error());
	
$query = "SELECT * FROM job_db WHERE ea_reg='$searchby'";
		
$result = mysql_query($query);

if (!$result) die ("Database access failed: " . mysql_error());

$rows = mysql_num_rows($result);

for ($j = 0 ; $j < $rows ; ++$j)
{

	$row = mysql_fetch_row($result);
	
	echo '<table border="1" align="center">';
	echo '<tr>';
	echo '<th>' 	. 	'EA Number '			.	'</th>';
	echo '<th>' 	. 	'Job Notes '			.	'</th>';
	echo '<th>' 	. 	'Job Completed '		.	'</th>';
	echo '<th>' 	. 	'Task Name '			.	'</th>';
	echo '<th>' 	. 	'Order Number '			.	'</th>';
	echo '<th>' 	. 	'Engineer1 '			.	'</th>';
	echo '<th>' 	. 	'Engineer2 '			.	'</th>';
	echo '<th>' 	. 	'Reported Time '		.	'</th>';
	echo '<th>' 	. 	'Reported Date '		.	'</th>';
	echo '<th>' 	. 	'Completed Time '		.	'</th>';
	echo '<th>' 	. 	'Completed Date '		.	'</th>';
	echo '</tr>';
	//table split
	echo '<tr>';
	echo '<td>' . $row[0]  . '</td>';
	echo '<td>' . $row[1]  . '</td>';
	echo '<td>' . $row[2]  . '</td>';
	echo '<td>' . $row[3]  . '</td>';	
	echo '<td>' . $row[4]  . '</td>';
	echo '<td>' . $row[5]  . '</td>';
	echo '<td>' . $row[6]  . '</td>';
	echo '<td>' . $row[7] . ':' . $row[8] .  '</td>';
	echo '<td>' . $row[9]  . ' / ' . $row[10] . ' / ' . $row[11] . '</td>';
	echo '<td>' . $row[12] . ':' . $row[13] .'</td>';
	echo '<td>' . $row[14] . ' / ' . $row[15] . ' / ' . $row[16] . '</td>';
	echo '</tr></table><p></p>';

}
mysql_close($db_server);

echo <<<_END

_END;

?>[/php]

[php]

//“SELECT * FROM job_db WHERE ea_reg=’$searchby’”;

//should be

//“SELECT * FROM job_db WHERE ea_reg LIKE ‘%$searchby%’”;
[/php]

I get mysql errors when i used the LIKE with & &

which confused me.

Do you mean when you have the & symbol in the string $searchby? Or are you creating another condition in the SQL statement with && like you do in PHP? In MySQL you use the word ‘AND’ :

SELECT `name` FROM `users` WHERE `group` > 4 AND `active`=1

ok no errors with ea_reg LIKE ‘%$searchby%’ but once again i get all rows from ea_reg not just the one i searched.

is it my: [php]for ($j = 0 ; $j < $rows ; ++$j)[/php]

i had form method=get rather than form method=post.

all fixed now, but I cannot get that week of my life back because of one moron error!

Sponsor our Newsletter | Privacy Policy | Terms of Service