Jump to content

php mysql search engine


Reaper0167

Recommended Posts

php mysql search engine displays the blob image like this....what is going on?

‡ÿêB™\€„Àt‘8K€@zŽB¦@F€˜&S `ËcbãP-`'æÓ€ø™{[”! ‘ eˆDh;¬ÏVŠEX0fKÄ9Ø-0IWfH°·ÀÎ ² 0Qˆ…){`È##x„™FòW<ñ+®ç*x™²<¹$9E[-qWW.(ÎI+6aaš@.Ây™24àóÌ ‘àƒóýxήÎÎ6Ž¶_-ê¿ÿ"bbãþåÏ«p@át~Ñþ,/³€;€mþ¢%îh^  u÷‹f²@µ éÚWópø~<ß5°j>{‘-¨]cöK'XtÀâ÷ò»oÁÔ(€hƒáÏwÿï?ýG %€fI’q^D$.Tʳ?ÇD *°AôÁ,ÀÁÜÁ ü`6„B$ÄÂBB d€r`)¬‚B(†Í°*`/Ô@4ÀQh†“p.ÂU¸=púažÁ(¼ AÈa!ÚˆbŠX#Ž™…ø!ÁH‹$ ɈQ"K‘5H1RŠT UHò=r9‡\Fº‘;È2‚ü†¼G1”²Q=Ô µC¹¨7„F¢ Ðdt1š ›Ðr´=Œ6¡çЫhÚ>CÇ0Àè3Äl0.ÆÃB±8, “c˱"¬ «Æ°V¬»‰õcϱwEÀ 6wB aAHXLXNØH¨ $4Ú 7 „QÂ'"“¨K´&ºùÄb21‡XH,#Ö/{ˆCÄ7$‰C2'¹I±¤TÒÒFÒnR#é,©›4H#“ÉÚdk²9”, +È…ääÃä3ää!ò[ b@q¤øSâ(RÊjJåå4åe˜2AU£šRݨ¡T5ZB­¡¶R¯Q‡

Link to comment
Share on other sites

by the way, this is not my script, i was just wondering how good it worked so I could get an idea of search engines. I tried the header code at the top of the page and all it shows is a little box with an x in the middle. And all the other content on the page was missing.

<?php
header('Content-type:image/x-png');
include "upload_db_info.php";

  // Get the search variable from URL
  $var = @$_GET['q'] ;
  $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 "<p>Please enter a search...</p>";
  exit;
  }

// check for a search parameter
if (!isset($var))
  {
  echo "<p>We dont seem to have a search parameter!</p>";
  exit;
  }

//connect to your database ** EDIT REQUIRED HERE **
mysql_connect("----","-----","-------"); //(host, username, password)

//specify database ** EDIT REQUIRED HERE **
mysql_select_db("-------") or die("Unable to select database"); //select which database we're using

// Build SQL Query  
$query = "select * from $table_name where name like \"%$trimmed%\"  
  order by name"; // EDIT HERE and specify your table and field names for the SQL query

$numresults=mysql_query($query);
$numrows=mysql_num_rows($numresults);

// If we have no results, offer a google search as an alternative

if ($numrows == 0)
  {
  echo "<h4>Results</h4>";
  echo "<p>Sorry, your search: "" . $trimmed . "" returned zero results</p>";

// google
echo "<p><a href=\"http://www.google.com/search?q=" 
  . $trimmed . "\" target=\"_blank\" title=\"Look up 
  " . $trimmed . " on Google\">Click here</a> to try the 
  search on google</p>";
  }

// next determine if s has been passed to script, if not use 0
  if (empty($s)) {
  $s=0;
  }

// get results
  $query .= " limit $s,$limit";
  $result = mysql_query($query) or die("Couldn't execute query");

// display what the person searched for
echo "<p>You searched for: "" . $var . ""</p>";

// begin to show results set
echo "Results";
$count = 1 + $s ;

// now you can display the results returned
  while ($row= mysql_fetch_array($result)) {
  $title = $row["content"];

  echo "$count.) $title" ;
  $count++ ;
  }

$currPage = (($s/$limit) + 1);

//break before paging
  echo "<br />";

  // next we need to do the links to other results
  if ($s>=1) { // bypass PREV link if s is 0
  $prevs=($s-$limit);
  print " <a href=\"$PHP_SELF?s=$prevs&q=$var\"><< 
  Prev 10</a>&nbsp ";
  }

// 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 " <a href=\"$PHP_SELF?s=$news&q=$var\">Next 10 >></a>";
  }

$a = $s + ($limit) ;
  if ($a > $numrows) { $a = $numrows ; }
  $b = $s + 1 ;
  echo "<p>Showing results $b to $a of $numrows</p>";
  
?>

Link to comment
Share on other sites

i found this little bit of code

<?php
<html> 
2 <head> 
3   <title>My page title</title> 
4 </head> 
5 <body> 
6 
7  <img height="125" width="125" alt="Flower" src="flower01.jpg" /> 
8 
9 </body> 
10</html>
?>

Each picture will need a page like this, and then echo out the php page on my search results page????? How can this be done with all the images in the database?

Link to comment
Share on other sites

I don't think you understand what you've been told.  A browser understands http protocol.  In reference to html, the browser supports the rendering of html documents.  Documents can have embedded elements like images, but the base html for those images is the img tag.  The img tag needs to reference a source for the image --- namely a seperate url that indicates where the image can be located in web space.  The client is responsible for integrating all the elements referenced in the html page and rendering them.

 

So -- no you can't just read a blob out the database and display that.  What you *can* do, is have a script that reads the image blob data from the database and returns that with the appropriate Mime header, as genericnumber1 suggested.  You can then use the call to that script in a page. 

 

So--- you need to write a script that returns ONE image.  The simplest manner would be using the get param as he illustrated.  Let's say that the script is called:

 

image.php.

 

It would accept an image id, or something that can be used to find the data in the mysql database.

 

You'd call it with :  http://yoursite.com/image.php?id=5

 

Working properly, this should render the image in your browser.

 

 

Once this is working, it's easy enough to have a page with as many images as you need:

 

Image one!

image.php?id=5

 

Image two!

image.php?id=6

 

etc.

 

 

Link to comment
Share on other sites

  • 2 months later...

So are you saying that every time someone uploads a picture, i need to edit that php file? I hope not.

 

No. The script example I provided assumed a generic script.  We don't have any information from you about your database structure, so the best we can do is hypothesize.  Often people use AUTO_INCREMENT to provide a numeric primary key on the table.  My example assumed such a mechanism.  I could easily write a script that would query the image table, and provide a list of the file names and the images.  This would be "generic" in that the next time someone uploaded an image it would be reflected in the list.

 

We don't know what the application is or what you are trying to do.  You haven't provided any code to look at.  We're just guessing at this point. 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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