| Autor | Zpráva | ||
|---|---|---|---|
| protom1 Profil |
#1 · Zasláno: 4. 12. 2013, 14:54:28
čau lidi prosím vás pomozte mi už si nevím rady jak to mám řešit. Dělám live search a za prvý nevím jak mám udělat, aby to vždy při vymazání textu z inputu zmizlo. A za druhý mi to hlasí tuhle hlášku .. Parse error: syntax error, unexpected '>' in D:\wamp\www\zk\in-search.php on line 10
Díky za rady .. index.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html><head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>MGL-FREE</title> <link rel="stylesheet" type="text/css" href="style.css"> <script language="javascript" src="ajax_framework.js"></script> </head> <body> <center> <h2>Ajax Search Engine</h2> <form id="searchForm" name="searchForm" method="post" action="javascript:insertTask();"> <div class="searchInput"> <input name="searchq" type="text" id="searchq" size="30" onkeyup="javascript:searchNameq()"/> <input type="button" name="submitSearch" id="submitSearch" value="Search" onclick="javascript:searchNameq()"/> </div> </form> <h3>Search Results</h3> <div id="msg">Type something into the input field</div> <div id="search-result"></div> </center> </div> </body> </html> ajax_framework.js /* ---------------------------- */
/* XMLHTTPRequest Enable */
/* ---------------------------- */
function createObject() {
var request_type;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer"){
request_type = new ActiveXObject("Microsoft.XMLHTTP");
} else {
request_type = new XMLHttpRequest();
}
return request_type;
}
var http = createObject();
/* -------------------------- */
/* SEARCH */
/* -------------------------- */
function searchNameq() {
searchq = encodeURI(document.getElementById('searchq').value);
document.getElementById('msg').style.display = "block";
document.getElementById('msg').innerHTML = "Searching for <strong>" + searchq+"";
// Set te random number to add to URL request
nocache = Math.random();
http.open('get', 'in-search.php?name='+searchq+'&nocache = '+nocache);
http.onreadystatechange = searchNameqReply;
http.send(null);
}
function searchNameqReply() {
if(http.readyState == 4){
var response = http.responseText;
document.getElementById('search-result').innerHTML = response;
}
}in-search.php <?php
include('dbcon.php');
$searchq = $_GET['searchq'];
$getName_sql = 'SELECT * FROM song
WHERE name LIKE "%' . $searchq .'%"
$getName = mysql_query($getTask_sql);
$total = mysql_num_rows(getTask);
while ($row = mysql_fetch_array($getName)) {
echo $row.name . '<br/>';
}
?>dbcon.php <?php $hostname_conn = "localhost"; $database_conn = "test"; $username_conn = "root"; $password_conn = ""; $conn = mysql_pconnect($hostname_conn, $username_conn, $password_conn) or trigger_error(mysql_error(),E_USER_ERROR); mysql_select_db($database_conn,$conn); ?> |
||
| juriad Profil |
#2 · Zasláno: 4. 12. 2013, 14:59:31
Na řádce:
WHERE name LIKE "%' . $searchq .'%" WHERE name LIKE "%' . $searchq .'%"'; |
||
| protom1 Profil |
#3 · Zasláno: 4. 12. 2013, 15:10:09
juriad
dobrý no dík to byla ta chyba, ale teď jich tam je 3x tolik :)) ) Notice: Undefined index: searchq in D:\wamp\www\zk\in-search.php on line 3
Call Stack
# Time Memory Function Location
1 0.0012 248688 {main}( ) ..\in-search.php:0Notice: Undefined variable: getTask_sql in D:\wamp\www\zk\in-search.php on line 6
Call Stack
# Time Memory Function Location
1 0.0012 248688 {main}( ) ..\in-search.php:0) Notice: Use of undefined constant getTask - assumed 'getTask' in D:\wamp\www\zk\in-search.php on line 7
Call Stack
# Time Memory Function Location
1 0.0012 248688 {main}( ) ..\in-search.php:0Warning: mysql_num_rows() expects parameter 1 to be resource, string given in D:\wamp\www\zk\in-search.php on line 7
Call Stack
# Time Memory Function Location
1 0.0012 248688 {main}( ) ..\in-search.php:0
2 0.0040 251360 mysql_num_rows ( ) ..\in-search.php:7 Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in D:\wamp\www\zk\in-search.php on line 9
Call Stack
# Time Memory Function Location
1 0.0012 248688 {main}( ) ..\in-search.php:0
2 0.0047 251432 mysql_fetch_array ( ) ..\in-search.php:9 |
||
| Tabetha Profil |
#4 · Zasláno: 4. 12. 2013, 15:42:56
Chyba 1 - mal by si asi radšej dať
$searchq = isset($_GET['searchq']) ? $_GET['searchq'] : null; Chyba 2 - nikde nemáš zadefinovanú premenná $getTask_sql Chyba 3 - Zmeň (predpokladám, ale nevidel som tam taktiež túto premennú) $total = mysql_num_rows(getTask); na $total = mysql_num_rows($getTask);
Chyba 4 - súvisí s chybou 3 Chyba 5 - nemôžeš odovzdávať hodnotu boolean, ale resource |
||
| protom1 Profil |
#5 · Zasláno: 4. 12. 2013, 16:07:59
takze to mam prepsat na co ? nejsem si ted jistej jako - chyba 5
|
||
| jenikkozak Profil |
#6 · Zasláno: 4. 12. 2013, 16:51:46
(Zastaralá) funkce mysql_query vrací
false, protože je chybně sestaven SQL dotaz. Zřejmě proto, že jsi zaměnil proměnnou $getTask_sql za $getName_sql.
|
||
| protom1 Profil |
#7 · Zasláno: 4. 12. 2013, 16:56:11
jenikkozak řešil sem to takto ...
<?php
include('dbcon.php');
$searchq = isset($_GET['searchq']) ? $_GET['searchq'] : null;
$getName_sql = 'SELECT * FROM song
WHERE name LIKE "%' . $searchq .'%"';
$getName = mysql_query($getName_sql);
$total = mysql_num_rows($getName);
while ($row = mysql_fetch_array($getName)) {
print_r($row);
echo " name:" . $row[0];
}
?>zadna chyba tam neni, ale mám tam Array ( [0] => tears in heaven [name] => tears in heaven ) name:tears in heaven a co teď ? :) |
||
| Tabetha Profil |
:) čo je teraz ta problém konkrétne
|
||
| protom1 Profil |
Tabetha:
Teď už mám i tohle .., ale teď to druhý mohli by ste se prosím podívat někdo na ten js ... protoze kdyz napisu do vyhledavani treba t najdemi to tears in havean z databaze .. , potom to vymazu to t a misto toho aby to teats in ahvean zmozlo tak tam zustava .. |
||
| Tabetha Profil |
#10 · Zasláno: 4. 12. 2013, 18:39:34
Skus dat podmienku na searchq v JS, aby ked je prazdna hodnota toho inputu tak nastavis prazdny obsah toho html.
|
||
| protom1 Profil |
#11 · Zasláno: 4. 12. 2013, 18:47:53
Dík, hele dost si mi poradil, ale přišel sem na to, že tenhle den byl celej zbytečnýho psaní, protože to je celý v get a to je v pici, už pracuji na jiném, takže pokud budeš chtít, tak ti potom pošlu zdroják, aby ses podíval, protože si mi v tomhle poradil nejvíc :)) a řekneš mi k tomu svý :))
|
||
| Tabetha Profil |
#12 · Zasláno: 4. 12. 2013, 19:51:04
vôbec nemáš začo :) podľa môjho, tie chyby boli len z nepozornosti, takže som ti možno ušetril len chvíľku :) ale môžeš mi to potom poslať :) rád sa pozriem a prípadne vyjadrím ;)
|
||
| protom1 Profil |
#13 · Zasláno: 5. 12. 2013, 12:50:59
Tabetha:
<?php
include("connection.php");
$html = '';
$html .= '<li class="result">';
$html .= '<a target="_blank" href="urlString">';
$html .= '<h3>nameString</h3>';
$html .= '</a>';
$html .= '</li>';
// Get Search
$search_string = preg_replace("/[^A-Za-z0-9]/", " ", $_POST['query']);
$search_string = mysql_real_escape_string($search_string);
// Check Length More Than One Character
if (strlen($search_string) >= 1 && $search_string !== ' ') {
// Build Query
$query = 'SELECT * FROM song WHERE name LIKE "%'.$search_string.'%"';
// Do Search
$result = mysql_query($query);
//exit;
while($results = mysql_fetch_array($result)) {
$result_array[] = $results;
}
//exit;
// Check If We Have Results
if (isset($result_array)) {
foreach ($result_array as $result) {
// Format Output Strings And Hightlight Matches
//
$display_name = preg_replace("/".$search_string."/i", "<b class='highlight'>".$search_string."</b>", $result['name']);
$display_url = ').'&lang=en]http://php.net/manual-lookup.php?pattern='.urlencode($result['name']).'&lang=en';
// Insert Name
$output = str_replace('nameString', $display_name, $html);
// Insert URL
$output = str_replace('urlString', $display_url, $output);
// Output
echo($output);
}
}else{
// Format No Results Output
$output = str_replace('urlString', 'javascript:void(0);', $html);
$output = str_replace('nameString', '<b>No Results Found.</b>', $output);
$output = str_replace('funcStr', 'Sorry :(', $output);
// Output
echo($output);
}
}
?>/ /* JS File */
// Start Ready
$(document).ready(function() {
// Icon Click Focus
$('div.icon').click(function(){
$('input#search').focus();
});
// Live Search
// On Search Submit and Get Results
function search() {
var query_value = $('input#search').val();
$('b#search-string').html(query_value);
if(query_value !== ''){
$.ajax({
type: "POST",
url: "search.php",
data: { query: query_value },
cache: false,
success: function(html){
$("ul#results").html(html);
}
});
}return false;
}
$("input#search").live("keyup", function(e) {
// Set Timeout
clearTimeout($.data(this, 'timer'));
// Set Search String
var search_string = $(this).val();
// Do Search
if (search_string == '') {
$("ul#results").fadeOut();
$('h4#results-text').fadeOut();
}else{
$("ul#results").fadeIn();
$('h4#results-text').fadeIn();
$(this).data('timer', setTimeout(search, 100));
};
});
}) |
||
| Tabetha Profil |
#14 · Zasláno: 5. 12. 2013, 14:15:31
vyzerá to pekne :)
otázka strlen($search_string) >= 1 && $search_string !== ' ' !empty($search_string) |
||
| protom1 Profil |
#15 · Zasláno: 5. 12. 2013, 14:35:09
Tabetha
jo možná jo :)) dík zkusím to jeste nejak vylepsit, ale jak to tahkle je tak to taha presne co chci :)) |
||
| Tabetha Profil |
#16 · Zasláno: 5. 12. 2013, 14:48:36
:) a ešte akú verziu PHP tam máš, že či by ti nevyšlo najlepšie využívať už mysqli
|
||
|
Časová prodleva: 12 let
|
|||
0