- This topic is empty.
-
AuthorPosts
-
November 19, 2010 at 5:59 am #30743mbarandaoMember
hello:
I’m working on this code that receives a variable via url and performs a mysql search for records using the value of the variable as the key word. I’m using the following code –which I’m currently using successfully on another section of my project, but experiencing problems in a different section.
The code is the same with a few minor changes (database and table connection etc), for some odd reason, the page comes out blank without any errors. I tried changing the connection information with intentional false access info to see if an error would be produced, still nothing. I’m a bit puzzled. Here is the code:
Content of Search Results
Customer's Job Cost History
error_reporting(E_ERROR | E_WARNING | E_PARSE);
// Get the search variable from URL
$var = @$_GET["clientID"] ;
$trimmed = trim($var); //trim whitespace from the stored variable
// rows to return
$limit=10;
// check for an empty string and display a message.
if ($trimmed == "")
{
//echo "Please enter a search...
";
exit;
}
// check for a search parameter
if (!isset($var))
{
echo "We dont seem to have a search parameter!
";
exit;
}
//connect to your database
mysql_connect("xxxxxxxxx", "xxxxxxxxx","xxxxxxxxxxxx"); //(host, username, password)
//specify database
mysql_select_db("shop") or die("Unable to select database"); //select which database we're using
// Build SQL Query
//$query = "select * from billofservice where clientID like '%$trimmed%' order by vehicleid "; // EDIT HERE and specify your table and field names for the SQL query
//echo "
" . $query . "
"; //die(); //$query = "select hashed_name = "%$trimmed%" from music"; //echo "
" . $query . "
";
$query = "select * from billofservice where vehicleid like '%$trimmed%' order by vehicleid ";
$results=mysql_query($query);
$numrows=mysql_num_rows($results);
if ($numrows == 0)
{
//echo "Results
";
echo "Sorry, your search by sound for "" . $trimmed . "" in the music category returned zero results
";
echo "This may simply be that our records has not been updated with detailed information of this search. Please click on the link above,
this will prompt our system to initiate the process for detailed information concerning "" . $trimmed . "" sound.It may also be possible that you have selected the wrong category for your search. A review of your search category selection may resolve the issue.
Thank you!
";
echo "
";
// google
//echo "Click here! to try the //search on google
";
}
// next determine if s has been passed to script, if not use 0
if (empty($s)) {
$s=0;
}
// get results
//else{
$query .= " limit $s,$limit";
$result = mysql_query($query) or die("Couldn't execute query");
// display what the person searched for
//echo "
";
echo "Additional Details information the search on: "" . $var . ""
";
echo "
";
// begin to show results set
//echo "Results";
$count = 1 + $s ;
// now you can display the results returned
while ($row= mysql_fetch_array($result)) {
$title1 = $row["invoicenum"];
$title2 = $row["servicedesc"];
$title3 = $row["vehicleid"];
$title4 = $row["servicearea"];
$title5 = $row["total"];
$title6 = $row["paid"];
$title7 = $row["Balancedue"];
$title8 = $row["date "];
echo "Invoice Number: $title1
" ;
$count++ ;
echo "Service Description: $title2
";
$count++ ;
echo "Client ID: $title3
";
$count++ ;
echo "Service Area: $title4
" ;
$count++ ;
echo "Job Total Cost: $title5
" ;
$count++ ;
echo "Payment: $title6
" ;
$count++ ;
echo "Balance Due: $title7
" ;
$count++ ;
echo "Date of The Invoice $title8
" ;
$count++ ;
}
$currPage = (($s/$limit) + 1);
//break before paging
echo "
";
// next we need to do the links to other results
if ($s>=1) { // bypass PREV link if s is 0
$prevs=($s-$limit);
print " << Prev 10  ";
}
// calculate number of pages needing links
$pages=intval($numrows/$limit);
// $pages now contains int of pages needed unless there is a remainder from division
if ($numrows%$limit) {
// has remainder so add one page
$pages++;
}
// check to see if last page
if (!((($s+$limit)/$limit)==$pages) && $pages!=1) {
// not last page so give NEXT link
$news=$s+$limit;
echo " Next 10 >>";
}
$a = $s + ($limit) ;
if ($a > $numrows) { $a = $numrows ; }
$b = $s + 1 ;
echo "
Showing results $b to $a of $numrows
";
?>
for the referring url variable I have something like this:
onclick="window.location= 'invoicehistory.php?var=$clientID'Can someone take a look at it to see if they catch something I’m not seeing.
Thanks,
MossaNovember 19, 2010 at 6:17 am #74350sylenixMembernot very sure with this, but as far as i know % sign in mysql statement is usually used as a format symbol like after using sprintf() function or am i wrong?
here:
$query = "select * from billofservice where vehicleid like '%$trimmed%' order by vehicleid ";
November 19, 2010 at 6:29 am #74351Rob MacKayParticipantwell %$trimmed% would define a wildcard where it would find anything with $trimmed in it.
So like if you were looking for dig – you could just say like ‘dig’ and it would just look for those letters in that order… or you could wildcard it dig% – then it would match digger digging digamma etc. With the wildcard defined at the front and the end you are looking for the appearance of those 3 letters in any word. bigdigger for example – made up of course – but you would match that as dig is inside it.
November 19, 2010 at 6:33 am #74353sylenixMemberthanks for the info sir! i didn’t know that one ΓΌ
November 19, 2010 at 6:37 am #74354mbarandaoMemberPersicely my intent with %$trimmed% -as Robskiwarrior writes . As I noted, I’m currently using this code in a different section of my project. It is working fine. So I therefore do not believe my issue in this instance is with the %$trimmed%. It is something else!
November 19, 2010 at 6:45 am #74355sylenixMemberi noticed these closing tags
are positioned outside your body
November 19, 2010 at 6:49 am #74356mbarandaoMemberYes! I have removed them during debugging with no success.
November 19, 2010 at 6:55 am #74357mbarandaoMemberWhat seems a bit incomprehensible to me is that everything is being ignored. Even if I intentionally change my db access with false info, normally an error is produced noting that db is inaccessible…not in this instance. The return is a blank page.
November 19, 2010 at 7:02 am #74358sylenixMemberhmmm strange!
how about this assignment operator that you used in this line?
$query .= " limit $s,$limit";
November 19, 2010 at 7:15 am #74359sylenixMemberfrom what i know, “.=” operator is used to multiply the left variable against the right variable/value given.
November 19, 2010 at 7:16 am #74360mbarandaoMemberThis assignment operator was specific to a search option with google in case my initial internal search was not successful. This should have been commented out as it pertained to another process–which it is now. …still not the cause.
November 19, 2010 at 9:24 am #74361Rob MacKayParticipant$query .= “string”; will concatenate $query with more string. Example:
$query = "bob";
$query .= "cat";
echo $query; //displays "bobcat"November 19, 2010 at 11:05 am #74362mbarandaoMemberIssue resolved!
It was pointed to me by another forumer that I had two instances of “exit;” on line 29 and 36. These instances were causing the failure. After commenting out these instance; “voila”, the script works.
Thank you to all who have posted in attempt to help resolve the problem.
The very best,
Mossa -
AuthorPosts
- The forum ‘Back End’ is closed to new topics and replies.