Please login or register.

Login with username, password and session length
Advanced search  

News:

Latest sNews - sNews 1.7 - with its own forums - for discussion and user mods.

Pages: [1] 2

Author Topic: change search page result in other page  (Read 1922 times)

adminphp

  • Full Member
  • ***
  • Karma: 4
  • Posts: 150
  • you must be a great snewser .
change search page result in other page
« on: November 09, 2011, 12:55:58 AM »

hi every body, i'm going to put my request directley because i'm tired this day,

what i can change in search function in snews.php to change the result page  with an other page like (result_search.php) not (index.php)
so i know that we just have to change and add some codes in (//SEARCH ENGINE ) and ( // CENTER) functions.
 ;) so HOW?
thanks guys for ur help.
Logged
“Fifty years of programming language research, and we end up with C++?”

Rui Mendes

  • Development,Testing, Support
  • Hero Member
  • *****
  • Karma: 195
  • Posts: 1009
  • sNews1.7
    • Comunidade Portuguesa
Re: change search page result in other page
« Reply #1 on: November 09, 2011, 01:11:09 AM »

You mean like this
Quote
// SEARCH FORM
function searchform() { ?>
   <form id="search_engine" method="post" action="<?php echo "result_search.php"; ?>" accept-charset="<?php echo s('charset');?>">
      <p><input class="searchfield" name="search_query" type="text" id="keywords" value="<?php echo l('search_keywords');
?>" onfocus="document.forms['search_engine'].keywords.value='';" onblur="if (document.forms['search_engine'].keywords.value == '') document.forms['search_engine'].keywords.value='<?php echo l('search_keywords'); ?>';" />
      <input class="searchbutton" name="submit" type="submit" value="<?php echo l('search_button')?>" /></p>
   </form>
<?php }
Logged
Need a Job on Europe. Linkdin - Facebook / Group

Rui Mendes

  • Development,Testing, Support
  • Hero Member
  • *****
  • Karma: 195
  • Posts: 1009
  • sNews1.7
    • Comunidade Portuguesa
Re: change search page result in other page
« Reply #2 on: November 09, 2011, 07:15:19 PM »

I think you can make changes to make result_search.php working.
- Connect to database
- create some security to avoid sql injection in queries.
- And show results
Logged
Need a Job on Europe. Linkdin - Facebook / Group

adminphp

  • Full Member
  • ***
  • Karma: 4
  • Posts: 150
  • you must be a great snewser .
Re: change search page result in other page
« Reply #3 on: November 09, 2011, 08:50:00 PM »

I think you can make changes to make result_search.php working.
- Connect to database
- create some security to avoid sql injection in queries.
- And show results

I dont know if you understood my request; what I want is to change some thing in  snews.php to that allow us to display the results of search in other page main not index.php,
for example i have files (index.php & index2.php) normally the results of search shows in index.php but i want to display them in the second page (index2.php);
this last include some special modifiction in template design.

the changes in the code you gave me in the previous comment, is just to search in in a specific page/category ,
I think the way is samply easy to acheive that, (what about in center function ) in the first lines is it possible to change soem thing there,
« Last Edit: November 10, 2011, 01:21:11 AM by adminphp »
Logged
“Fifty years of programming language research, and we end up with C++?”

Rui Mendes

  • Development,Testing, Support
  • Hero Member
  • *****
  • Karma: 195
  • Posts: 1009
  • sNews1.7
    • Comunidade Portuguesa
Re: change search page result in other page
« Reply #4 on: November 11, 2011, 01:07:55 PM »

If you want to jump to another page like index2.php is the way I told you. This means you must create all stuff (connect to database) to catch the data from search form and show the results.
If you want  to use the same index and show other page, you must include file and call function.
Quote
include('index2.php');
In function search call new function inside index2
Quote
// SEARCH ENGINE
function search($limit = 20) {
newsearch();
return;
....
This last one you don't need to connect to database, because was already included.
Logged
Need a Job on Europe. Linkdin - Facebook / Group

adminphp

  • Full Member
  • ***
  • Karma: 4
  • Posts: 150
  • you must be a great snewser .
Re: change search page result in other page
« Reply #5 on: November 12, 2011, 04:29:48 AM »


By default, sNews is a single-template system. Everything generated by every function in snews.php displays in the template (index,php) file.

i know what are you talking about, but, i am confused a little bit about what you said (why i have to connect to database if i've already connected? )
now the problem is where i want to display search results, that is to say, when i click (input radio) = (search) ; normally results shows in index.php, but in my case i want them to show in other page which include of course ( php session_start(); include('snews.php');...) and in the main include ( <?php center(); ?>)  as the index.php,

to explain more to you:
What i describe seems to be that i want my "my search results" form to be displayed in a different template than the one generated by your index.php file.
Logged
“Fifty years of programming language research, and we end up with C++?”

Rui Mendes

  • Development,Testing, Support
  • Hero Member
  • *****
  • Karma: 195
  • Posts: 1009
  • sNews1.7
    • Comunidade Portuguesa
Re: change search page result in other page
« Reply #6 on: November 12, 2011, 02:11:56 PM »

My first post, change like i said will jump to your page (result_search.php).
Like you said in that file you put:
php session_start(); include('snews.php');..) will work with your function

My preference is:
- php session_start();
- NOT include snews.php
- Connect database
- get $_POST aand clean it to avoid sql injection
- Create your function to retrieve information from database and show results
Logged
Need a Job on Europe. Linkdin - Facebook / Group

adminphp

  • Full Member
  • ***
  • Karma: 4
  • Posts: 150
  • you must be a great snewser .
Re: change search page result in other page
« Reply #7 on: November 12, 2011, 04:46:01 PM »

My first post, change like i said will jump to your page (result_search.php).
Like you said in that file you put:
php session_start(); include('snews.php');..) will work with your function

My preference is:
- php session_start();
- NOT include snews.php
- Connect database
- get $_POST aand clean it to avoid sql injection
- Create your function to retrieve information from database and show results
i share the steps you give .. but unfortunally rui mendes, I dont know exactly how to do that (a little bit)   could you please explain how i can have ( CONNECT db ) and geting get $_POST;

 i found this part in //center function my snews.php

Code: [Select]
switch(true) {
case isset($_POST['search_query']): search(); return; break;

what does this section says;
« Last Edit: November 12, 2011, 04:57:27 PM by adminphp »
Logged
“Fifty years of programming language research, and we end up with C++?”

Rui Mendes

  • Development,Testing, Support
  • Hero Member
  • *****
  • Karma: 195
  • Posts: 1009
  • sNews1.7
    • Comunidade Portuguesa
Re: change search page result in other page
« Reply #8 on: November 12, 2011, 10:28:55 PM »

I think you need only make change on red-color
Quote
// SEARCH FORM
function searchform() { ?>
   <form id="search_engine" method="post" action="<?php echo 'search.php'; ?>" accept-charset="<?php echo s('charset');?>">
      <p><input class="searchfield" name="search_query" type="text" id="keywords" value="<?php echo l('search_keywords');
?>" onfocus="document.forms['search_engine'].keywords.value='';" onblur="if (document.forms['search_engine'].keywords.value == '') document.forms['search_engine'].keywords.value='<?php echo l('search_keywords'); ?>';" />
      <input class="searchbutton" name="submit" type="submit" value="<?php echo l('search_button')?>" /></p>
   </form>
<?php }
Download here my search_file

About your question, when search  button was press, will send $_POST['search_query'] is true and jump to function search.
This $_POST['search_query'] contains the words that user wrote
Logged
Need a Job on Europe. Linkdin - Facebook / Group

adminphp

  • Full Member
  • ***
  • Karma: 4
  • Posts: 150
  • you must be a great snewser .
Re: change search page result in other page
« Reply #9 on: November 13, 2011, 07:07:43 PM »

i did the same thing you share;  but it does not working; no change in the page ( when i click sumbit search the page index.php which it shows results  but contrary to what i want)
Logged
“Fifty years of programming language research, and we end up with C++?”

Rui Mendes

  • Development,Testing, Support
  • Hero Member
  • *****
  • Karma: 195
  • Posts: 1009
  • sNews1.7
    • Comunidade Portuguesa
Re: change search page result in other page
« Reply #10 on: November 15, 2011, 02:17:18 AM »

Are you sure is not working?
My demo is working, see here
Logged
Need a Job on Europe. Linkdin - Facebook / Group

Rui Mendes

  • Development,Testing, Support
  • Hero Member
  • *****
  • Karma: 195
  • Posts: 1009
  • sNews1.7
    • Comunidade Portuguesa
Re: change search page result in other page
« Reply #11 on: November 15, 2011, 02:19:01 AM »

I just add this code anywhere in search.php
Quote
s('language') != 'EN' && file_exists('lang/'.s('language').'.php') == true ? include('lang/'.s('language').'.php') : include('lang/EN.php');
Logged
Need a Job on Europe. Linkdin - Facebook / Group

adminphp

  • Full Member
  • ***
  • Karma: 4
  • Posts: 150
  • you must be a great snewser .
Re: change search page result in other page
« Reply #12 on: November 15, 2011, 08:38:18 PM »

after my checking all codes you gave me i found some mistakes in some lines and i correct them ;    now my input search when i click search the search.php  show directly as i want  but there is a problem in it ;  here is the alert it give when i search some thing

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/aljazeer/public_html/search.php on line 147

mistakes noted ;
Code: [Select]
  <form id="search_engine" method="post" action="<?php echo "result_search.php"?>" accept-charset="<?php echo s('charset');?>">
after that you gave me the same code include the same line but with a different changes or mistake ( look at  <?php echo "result_search.php"; ?>  file name string wih ("..")  
but the second string ( '....' )
as i said the function  you gave it working now but still having some problems,  do you know r where is the problem exactly?.
thanks rui mendes for ur help you really did some thing good for us. ;)
« Last Edit: November 15, 2011, 08:43:04 PM by adminphp »
Logged
“Fifty years of programming language research, and we end up with C++?”

Rui Mendes

  • Development,Testing, Support
  • Hero Member
  • *****
  • Karma: 195
  • Posts: 1009
  • sNews1.7
    • Comunidade Portuguesa
Re: change search page result in other page
« Reply #13 on: November 16, 2011, 01:05:56 AM »

I like to help.

In my demo I think everything is working, maybe you have some issue somewhere.
Try use my example, change database settings only, (I upload again with last change).

In your line 147 before $result = mysql_query($query);
put this a tell me what you got
echo $query;
Logged
Need a Job on Europe. Linkdin - Facebook / Group

adminphp

  • Full Member
  • ***
  • Karma: 4
  • Posts: 150
  • you must be a great snewser .
Re: change search page result in other page
« Reply #14 on: November 16, 2011, 04:07:46 AM »

In your line 147 before $result = mysql_query($query);
put this a tell me what you got
echo $query;
i got the same alert problem but now in line 147

see it ;

SELECT a.id FROM articles AS a LEFT OUTER JOIN categories as c ON category = c.id AND c.published ='YES' LEFT OUTER JOIN categories as x ON c.subcat = x.id AND x.published ='YES' WHERE position != 2 AND a.published = 1 AND a.visible = 'YES' AND (title LIKE "%pro%" || text LIKE "%pro%" || keywords_meta LIKE "%pro%") &&(title LIKE "%program%" || text LIKE "%program%" || keywords_meta LIKE "%gram%") ORDER BY id DESC LIMIT 20
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/aljazeer/public_html/search.php on line 148

i just want to say that i tried to put
      $query = $query." ORDER BY id DESC";
but does not working at all,    may be the problem is in the connect to DB to find results why we dont put the same  
//SEARCH ENGINE in search.php


It might return an error if the result of the SELECT contained no rows, but I could be wrong. The code looks ok, I'm not sure what the problem could be.
« Last Edit: November 16, 2011, 04:13:52 AM by adminphp »
Logged
“Fifty years of programming language research, and we end up with C++?”
Pages: [1] 2