ecabrera Posted August 5, 2011 Share Posted August 5, 2011 hey i want to make a search bar for my videos page and i want the search bar just to search that page no other page its like if a member types in keywords,title description all that will show up just like youtube how do i do that? how do i get started?where do i get start? Quote Link to comment https://forums.phpfreaks.com/topic/243958-search-bar/ Share on other sites More sharing options...
darkfreaks Posted August 5, 2011 Share Posted August 5, 2011 http://www.tutorialized.com/view/tutorial/PHP-MySQL-database-search/416 Quote Link to comment https://forums.phpfreaks.com/topic/243958-search-bar/#findComment-1252652 Share on other sites More sharing options...
ecabrera Posted August 5, 2011 Author Share Posted August 5, 2011 ok can u help me is it like this it tells me to // Build SQL Query $query = "select videos from the_table where 1st_field like \"%$trimmed%\" order by 1st_field"; // EDIT HERE and specify your table and field names for the SQL query $query = mysql_query("SELECT * FROM videos WHERE id='$getid'"); $numrows = mysql_num_rows($query); if ($numrows == 1){ $row = mysql_fetch_assoc($query); $title = $row['title']; $user_name = $row['user_name']; $keywords = $row['keywords']; $date = $row['date']; $description = $row['description']; $meta_description = "$title by $user_name - $date"; $meta_keywords = "$keywords"; $title = "$title by $user_name Videos"; Quote Link to comment https://forums.phpfreaks.com/topic/243958-search-bar/#findComment-1252665 Share on other sites More sharing options...
darkfreaks Posted August 5, 2011 Share Posted August 5, 2011 $query = "select * from videos where id like \"%$getid%\ order by id"; Quote Link to comment https://forums.phpfreaks.com/topic/243958-search-bar/#findComment-1252669 Share on other sites More sharing options...
ecabrera Posted August 5, 2011 Author Share Posted August 5, 2011 Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/ecabrera/public_html/videos.php on line 94 $numrows=mysql_num_rows($numresults); heres the whole code in the ****** i put in my 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("localhost","******","*******"); //(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 = mysql_query("SELECT * FROM videos WHERE id='$getid'"); $numrows = mysql_num_rows($query); if ($numrows == 1){ $row = mysql_fetch_assoc($query); $id = $row['id']; $user_id = $row['user_id']; $user_name = $row['user_name']; $title = $row['title']; $description = $row['description']; $keywords = $row['keywords']; $category = $row['category']; $videoid = $row['videoid']; $views = $row['views']; $comments = $row['comments']; $date = $row['date']; $description = htmltext($description); // 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["1st_field"]; 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>  "; } // 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>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/243958-search-bar/#findComment-1252688 Share on other sites More sharing options...
darkfreaks Posted August 5, 2011 Share Posted August 5, 2011 $connect= mysql_connect('localhost','user','pass'); $numrows= mysql_num_rows($connect,$variable); Quote Link to comment https://forums.phpfreaks.com/topic/243958-search-bar/#findComment-1252714 Share on other sites More sharing options...
ecabrera Posted August 5, 2011 Author Share Posted August 5, 2011 i cant get it to work Quote Link to comment https://forums.phpfreaks.com/topic/243958-search-bar/#findComment-1252729 Share on other sites More sharing options...
darkfreaks Posted August 5, 2011 Share Posted August 5, 2011 code please? and paste it between [ code ] and [ /code ] tags Quote Link to comment https://forums.phpfreaks.com/topic/243958-search-bar/#findComment-1252731 Share on other sites More sharing options...
ecabrera Posted August 5, 2011 Author Share Posted August 5, 2011 i havent put my info in the msql_connect becuase ill put that later but in my orginal script i did in the // Build SQL Query $query = "select * from the_table where 1st_field like \"%$trimmed%\" order by 1st_field"; // EDIT HERE and specify your table and field names for the SQL query $numresults=mysql_query($query); $numrows=mysql_num_rows($numresults); i tdont know what to put here should i put this $query = mysql_query("SELECT * FROM videos WHERE id='$getid'"); $numrows = mysql_num_rows($query); if ($numrows == 1){ $row = mysql_fetch_assoc($query); $id = $row['id']; $user_id = $row['user_id']; $user_name = $row['user_name']; $title = $row['title']; $description = $row['description']; $keywords = $row['keywords']; $category = $row['category']; $videoid = $row['videoid']; $views = $row['views']; $comments = $row['comments']; $date = $row['date']; or $query = mysql_query("SELECT * FROM video_comments WHERE video_id='$getid' AND user_id='$userid' AND comment='$comment'"); $numerows =mysql_num_rows($query); if ($numrows != 0){ <?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("localhost","username","password"); //(host, username, password) //specify database ** EDIT REQUIRED HERE ** mysql_select_db("database") or die("Unable to select database"); //select which database we're using // Build SQL Query $query = "select * from the_table where 1st_field like \"%$trimmed%\" order by 1st_field"; // 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["1st_field"]; 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>  "; } // 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>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/243958-search-bar/#findComment-1252734 Share on other sites More sharing options...
darkfreaks Posted August 5, 2011 Share Posted August 5, 2011 // 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 ** $connect = mysql_connect("localhost","username","password"); //(host, username, password) // Build SQL Query $query = "select * from the_table where 1st_field like \"%$trimmed%\" order by 1st_field"; // EDIT HERE and specify your table and field names for the SQL query $numresults=mysql_query($query); $numrows=mysql_num_rows($connect,$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["1st_field"]; 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>  "; } // 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>"; ?> Report to moderator Logged Quote Link to comment https://forums.phpfreaks.com/topic/243958-search-bar/#findComment-1252742 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.