flying_monkey Posted June 6, 2013 Share Posted June 6, 2013 how can i change the way my search results look? so i have this search engine that when you search for something you get the results in the blank page that just list the info for you but what i want is to change the way that info looks i want to change the way the search results look on the page ... but i dont know what to do to affect the way it looks if the search results page is being generated when you get the results idk if that made sense but i can post my code and a screen shot if that would help Quote Link to comment https://forums.phpfreaks.com/topic/278831-how-can-i-change-the-way-my-search-results-look/ Share on other sites More sharing options...
ricmetal Posted June 6, 2013 Share Posted June 6, 2013 yeah, hard to time following youre train of thought bascilly, the search engine gets results as data. the only thing that makes the page look how it does is the design + the data. if you want to receive the same data, just change the design. but post youre code to me to have a look, and a couple of screenshots Quote Link to comment https://forums.phpfreaks.com/topic/278831-how-can-i-change-the-way-my-search-results-look/#findComment-1434387 Share on other sites More sharing options...
cpd Posted June 6, 2013 Share Posted June 6, 2013 idk if that made sense but i can post my code and a screen shot if that would help Don't worry about any of that, I've been training in the art of telepathy. Quote Link to comment https://forums.phpfreaks.com/topic/278831-how-can-i-change-the-way-my-search-results-look/#findComment-1434398 Share on other sites More sharing options...
flying_monkey Posted June 6, 2013 Author Share Posted June 6, 2013 (edited) Don't worry about any of that, I've been training in the art of telepathy. lol yea and im a psychic ... heres the screenshot this is the search result ...it just searchs for info thats in the database ... i have another page im trying to set up so that users can submit info from a form, on the website, into the database i want to make it look like this website http://code.ohloh.net/search?s=Search%20open%20source%20code&browser=Default i want to have like a block where all the search results will fill the blanks title description code tags this screenshot is what it looks like right now and that html at the bottom is being generated when you search... at least i think it is cause i dont recognize it heres the html but its saved as .php ... idk if thats normal but it works ... im still a noob at php <html> <head> <title>Title of your search engine</title> </head> <body> <form action='search.php' method='GET'> <center> <h1>My Search Engine</h1> <input type='text' size='90' name='search'></br></br> <input type='submit' name='submit' value='Search source code' ></br></br></br> </center> </form> </body> </html> heres the php (i didnt actually write it i got it from a video on youtube) i had to comment out line 41 cause i got an error from it. idk if i actually need it <?php $button = isset($_GET['submit']) ? $_GET['submit'] : ''; $search = $_GET ['search']; if(strlen($search)<=1) echo "Search term too short"; else{ echo "You searched for <b>$search</b> <hr size='1'></br>"; mysql_connect("localhost","root",""); mysql_select_db("searchengine"); $search_exploded = explode (" ", $search); $x = 0; $construct = ''; foreach($search_exploded as $search_each) { $x++; if($x==1) $construct .="title LIKE '%$search_each%'"; else $construct .="AND title LIKE '%$search_each%'"; } $constructs ="SELECT * FROM searchengine WHERE $construct"; $run = mysql_query($constructs); $foundnum = mysql_num_rows($run); if ($foundnum==0) echo "Sorry, there are no matching result for <b>$search</b>.</br></br>1. Try more general words. for example: If you want to search 'how to create a website' then use general keyword like 'create' 'website'</br>2. Try different words with similar meaning</br>3. Please check your spelling"; else { echo "$foundnum results found !<p>"; $per_page = 1; //results per page //$start = $_GET['start']; $max_pages = ceil($foundnum / $per_page); $start = isset($start) ? $start : 0; $getquery = mysql_query("SELECT * FROM searchengine WHERE $construct LIMIT $start, $per_page"); while($runrows = mysql_fetch_assoc($getquery)) { $title = $runrows ['title']; $desc = $runrows ['description']; $url = $runrows ['url']; echo " <a href='$url'><b>$title</b></a><br> $desc<br> <a href='$url'>$url</a><p> "; } //Pagination Starts echo "<center>"; $prev = $start - $per_page; $next = $start + $per_page; $adjacents = 3; $last = $max_pages - 1; if($max_pages > 1) { //previous button if (!($start<=0)) echo " <a href='search.php?search=$search&submit=Search+source+code&start=$prev'>Prev</a> "; //pages if ($max_pages < 7 + ($adjacents * 2)) //not enough pages to bother breaking it up { $i = 0; for ($counter = 1; $counter <= $max_pages; $counter++) { if ($i == $start){ echo " <a href='search.php?search=$search&submit=Search+source+code&start=$i'><b>$counter</b></a> "; } else { echo " <a href='search.php?search=$search&submit=Search+source+code&start=$i'>$counter</a> "; } $i = $i + $per_page; } } elseif($max_pages > 5 + ($adjacents * 2)) //enough pages to hide some { //close to beginning; only hide later pages if(($start/$per_page) < 1 + ($adjacents * 2)) { $i = 0; for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++) { if ($i == $start){ echo " <a href='search.php?search=$search&submit=Search+source+code&start=$i'><b>$counter</b></a> "; } else { echo " <a href='search.php?search=$search&submit=Search+source+code&start=$i'>$counter</a> "; } $i = $i + $per_page; } } //in middle; hide some front and some back elseif($max_pages - ($adjacents * 2) > ($start / $per_page) && ($start / $per_page) > ($adjacents * 2)) { echo " <a href='search.php?search=$search&submit=Search+source+code&start=0'>1</a> "; echo " <a href='search.php?search=$search&submit=Search+source+code&start=$per_page'>2</a> .... "; $i = $start; for ($counter = ($start/$per_page)+1; $counter < ($start / $per_page) + $adjacents + 2; $counter++) { if ($i == $start){ echo " <a href='search.php?search=$search&submit=Search+source+code&start=$i'><b>$counter</b></a> "; } else { echo " <a href='search.php?search=$search&submit=Search+source+code&start=$i'>$counter</a> "; } $i = $i + $per_page; } } //close to end; only hide early pages else { echo " <a href='search.php?search=$search&submit=Search+source+code&start=0'>1</a> "; echo " <a href='search.php?search=$search&submit=Search+source+code&start=$per_page'>2</a> .... "; $i = $start; for ($counter = ($start / $per_page) + 1; $counter <= $max_pages; $counter++) { if ($i == $start){ echo " <a href='search.php?search=$search&submit=Search+source+code&start=$i'><b>$counter</b></a> "; } else { echo " <a href='search.php?search=$search&submit=Search+source+code&start=$i'>$counter</a> "; } $i = $i + $per_page; } } } //next button if (!($start >=$foundnum-$per_page)) echo " <a href='search.php?search=$search&submit=Search+source+code&start=$next'>Next</a> "; } echo "</center>"; } } ?> Edited June 6, 2013 by flying_monkey Quote Link to comment https://forums.phpfreaks.com/topic/278831-how-can-i-change-the-way-my-search-results-look/#findComment-1434512 Share on other sites More sharing options...
joea Posted June 6, 2013 Share Posted June 6, 2013 You will have your database hacked with this piece of code. Sanitize your variables and use mysql_real_escape_string. BTW, there is nothing on line 41 that could cause PHP error. Quote Link to comment https://forums.phpfreaks.com/topic/278831-how-can-i-change-the-way-my-search-results-look/#findComment-1434517 Share on other sites More sharing options...
flying_monkey Posted June 6, 2013 Author Share Posted June 6, 2013 i know the code is super insecure but its more like a proof of concept right now i just need to get it working and looking semi decent then if i get the green light to finish it, i'll start tweaking all the security stuff ... dont get me wrong, i'll still take notes on what i should work on later, as far as security goes ... whats the mysql_real_escape_string for? heres what i get when line 41 isn't commented out ( ! ) SCREAM: Error suppression ignored for ( ! ) Notice: Undefined index: start in C:\wamp\www\test search\search.php on line 41 Call Stack # Time Memory Function Location 1 0.0015 276504 {main}( ) ..\search.php:0 Quote Link to comment https://forums.phpfreaks.com/topic/278831-how-can-i-change-the-way-my-search-results-look/#findComment-1434528 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.