making a search and counting and returning results
Posted: Thu Feb 27, 2003 9:38 am
Hi
As a newbie i realise my code may be faulty in a few areas. if you have time to look for anything that is obviously wrong to you, then i would be bvery grateful.
i am trying to search my mySQL database and return results.
I am getting this error - parse error, expecting `','' or `';'' -
on the following line
while ($i < $resultRowCount; $i++) {
here the function i have made
<?php
function searchInstallers($search)
{
global $search_keyword,$search;
// form has 2 tick boxes for keyword or postcode search
if($search == "keywords"){
/* i am looking for all mentions of any keyword ($keywords) in any table in the whole databse
as long as the installer_approved field is 'approved' */
$keyword_search = "SELECT * FROM ccMembers WHERE *='$keywords' && installer_approved='approved' ORDER BY user_id DESC";
//not sure if this line underneath is neccasary for count, just testing - hopefully will return a number
$resultRowCount = "SELECT COUNT * FROM ccMembers WHERE *='$keywords' && installer_approved='approved'";
$searchResults = mysql_query($keyword_search, $db) or die('error making query');
// at this point i am expecting the result to be a collection of rows
if ($resultRow)
echo ' Here are your search results:<br><br>';
echo '<table border="2" cellspacing="0" cellpadding="5" bgcolor="#99cccc" align="center" width="50%" bordercolor="#000066">
<tr>
<td height="30"><font class="normal">Installer
Name: </font></td>
<td><font class="normal">Comapny Name:</font>
</td>
<td><font class="normal">Address:</font> </td>
<td><font class="normal">Certificates:</font>
</td>
</tr>'
/* while statement will set up this run to be repeated until finish*/
/*having a problem is counting the row in search */
while ($i < $resultRowCount; $i++) {
// mysql_fetch_array is to take 1 result at a time and send to the follwing statement
$resultRow = mysql_fetch_array($searchResults);
// uses a multidimensional array to display results
echo '<tr bgcolor="#FFFFFF">
<td>'.$resultRow[$i]["firstName"].' '.$resultRow["lastName"].'</td>
<td height="30">'.$resultRow[$i]["company_name"].' </td>
<td height="30">'.$resultRow[$i]["address1"].', '.$resultRow["address3"].', '.$resultRow["postcode"].'</td>
<td height="30">'.$resultRow[$i]["installer_certificates"].'</td>
</tr>';
} //end while
echo '</table>';
elseif($search == "postcodes"){
// haven't started writing any code for this search yet
}
else
echo '<font class="normal">Please use the search form above or the UK Map above to the right. Your search results will appear here.</font>';
}
?>
thank you any help you may be able to give.
As a newbie i realise my code may be faulty in a few areas. if you have time to look for anything that is obviously wrong to you, then i would be bvery grateful.
i am trying to search my mySQL database and return results.
I am getting this error - parse error, expecting `','' or `';'' -
on the following line
while ($i < $resultRowCount; $i++) {
here the function i have made
<?php
function searchInstallers($search)
{
global $search_keyword,$search;
// form has 2 tick boxes for keyword or postcode search
if($search == "keywords"){
/* i am looking for all mentions of any keyword ($keywords) in any table in the whole databse
as long as the installer_approved field is 'approved' */
$keyword_search = "SELECT * FROM ccMembers WHERE *='$keywords' && installer_approved='approved' ORDER BY user_id DESC";
//not sure if this line underneath is neccasary for count, just testing - hopefully will return a number
$resultRowCount = "SELECT COUNT * FROM ccMembers WHERE *='$keywords' && installer_approved='approved'";
$searchResults = mysql_query($keyword_search, $db) or die('error making query');
// at this point i am expecting the result to be a collection of rows
if ($resultRow)
echo ' Here are your search results:<br><br>';
echo '<table border="2" cellspacing="0" cellpadding="5" bgcolor="#99cccc" align="center" width="50%" bordercolor="#000066">
<tr>
<td height="30"><font class="normal">Installer
Name: </font></td>
<td><font class="normal">Comapny Name:</font>
</td>
<td><font class="normal">Address:</font> </td>
<td><font class="normal">Certificates:</font>
</td>
</tr>'
/* while statement will set up this run to be repeated until finish*/
/*having a problem is counting the row in search */
while ($i < $resultRowCount; $i++) {
// mysql_fetch_array is to take 1 result at a time and send to the follwing statement
$resultRow = mysql_fetch_array($searchResults);
// uses a multidimensional array to display results
echo '<tr bgcolor="#FFFFFF">
<td>'.$resultRow[$i]["firstName"].' '.$resultRow["lastName"].'</td>
<td height="30">'.$resultRow[$i]["company_name"].' </td>
<td height="30">'.$resultRow[$i]["address1"].', '.$resultRow["address3"].', '.$resultRow["postcode"].'</td>
<td height="30">'.$resultRow[$i]["installer_certificates"].'</td>
</tr>';
} //end while
echo '</table>';
elseif($search == "postcodes"){
// haven't started writing any code for this search yet
}
else
echo '<font class="normal">Please use the search form above or the UK Map above to the right. Your search results will appear here.</font>';
}
?>
thank you any help you may be able to give.