6 Replies - 820 Views - Last Post: 22 April 2012 - 08:14 PM Rate Topic: -----

#1 shorne29  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 21-April 12

Question on PHP code for Ajax search form

Posted 21 April 2012 - 03:24 PM

I was hoping someone could point me in the right direction on how to use the code for displaying information from my MySql database...I have the database hooked up right but I don't have a clue on how to grab images and the link of the image from the database. I think I just have to fill in my information but I have no idea what areas. Any help would be greatly appreciated!

The code I have is this:
<?php

// file for database connection
include('inc/db.inc.php');

// configuration file
include('inc/config.inc.php');

if(isset($_GET['p'])) {
  $page_number = $_GET['p'];
  $arraySearch = $_GET['terms'];
  $show_count = $_GET['count'];
  settype($page_number, 'integer');
}
$nospaces = substr($_GET['terms'],0,4);
  $offset = ($page_number - 1) * $records_number;
// check for an empty string and display a message.
if ($_GET['terms'] == "") {
  echo  '<div id="counter">ex. write &acute;here and&acute; or &acute;search&acute; without quotes.</div>';
// minim 3 characters condition
  } else if(strlen($_GET['terms']) < $limitchar) {
 echo '<div id="counter">'. $limitchar .' characters minimum</div>';
// no spaces in first 4 letters
  } else if(preg_replace('/[a-zA-Z0-9]/', '', $nospaces))  {
 echo '<div id="counter">Please use letters or numbers in first 4 characters</div>';
  } else  {

// explode search words into an array
  $arraySearch = explode(" ", $_GET['terms']);
// table fields to search
  $arrayFields = array(0 => $first_field, 1 => $second_field);
  $countSearch = count($arraySearch);
  $a = 0;
  $b = 0;
  $query = "SELECT * FROM $table_name WHERE (";
  $countFields = count($arrayFields);
  while ($a < $countFields)
  {
    while ($b < $countSearch)
    {
      $query = $query."$arrayFields[$a] LIKE '%$arraySearch[$b]%'";
      $b++;
      if ($b < $countSearch)
      {
        $query = $query." AND ";
      }
    }
    $b = 0;
    $a++;
    if ($a < $countFields)
    {
      $query = $query.") OR (";
    }
  }
  $query = $query.") LIMIT $offset, $records_number;";
  $search = mysql_query($query);
  
  
// get number of search results
  $arrayFields = array(0 => $first_field, 1 => $second_field);
  $countSearch = count($arraySearch);
  $a = 0;
  $b = 0;
  $query = "SELECT * FROM $table_name WHERE (";
  $countFields = count($arrayFields);
  while ($a < $countFields)
  {
    while ($b < $countSearch)
    {
      $query = $query."$arrayFields[$a] LIKE '%$arraySearch[$b]%'";
      $b++;
      if ($b < $countSearch)
      {
        $query = $query." AND ";
      }
    }
    $b = 0;
    $a++;
    if ($a < $countFields)
    {
      $query = $query.") OR (";
    }
  }
  $query = $query.")";
  $count_results = mysql_query($query);
  $numrows = mysql_num_rows($count_results);

// no results
if($numrows == 0) {
		echo '<div id="counter">No results found</div>';

// show results
} else {

echo '<div id="results">
<div id="results_top"><p><b>'. $_GET['terms'] .'</b> - '. $numrows .' results found</p></div>
';

while($row = mysql_fetch_assoc($search)) {

$urltitle = str_replace(" ","_", $row['title']);

echo '<div class="item">
<div class="details"><a href="http://www.onlinegamez.net/'.$urltitle.'-'.$row['id'].'.html" style="float:left;"><img src="http://www.onlinegamez.net/files/image/'.$row['icon'].'" width="90" height="65" alt="'.$row['title'].'"/></a><a href="http://www.onlinegamez.net/'.$urltitle.'-'.$row['id'].'.html" class="title">'.$row['title'].'</a><br />
'.$row['description'].'</div>
<div class="played"><span>'.$row['timesplayed'].'</span>
<p>played</p></div>
<div style="clear:both;"></div></div>'; 
}
// pagination
  $maxPage = ceil($numrows/$records_number);

  $nav = '';
for($page = 1; $page <= $maxPage; $page++) {
  if ($page == $page_number)     {
     $nav .= "$page";
  }
  else
  {
      $nav .= "<a href=\"javascript:htmlData('search.php','terms=".$_GET['terms']."&amp;p=$page')\">$page</a>";
  }
}

if ($page_number > 1) {

  $page = $page_number - 1;
  $prev = "<a href=\"javascript:htmlData('search.php','terms=".$_GET['terms']."&amp;p=$page')\">&laquo;</a>";

  $first = "<a href=\"javascript:htmlData('search.php','terms=".$_GET['terms']."&amp;p=1')\">First</a>";
}
else {
  $prev = '';
  $first = '';
}

if ($page_number < $maxPage) {
  $page = $page_number + 1;
  $next = "<a href=\"javascript:htmlData('search.php','terms=".$_GET['terms']."&amp;p=$page')\">&raquo;</a>";

  $last = "<a href=\"javascript:htmlData('search.php','terms=".$_GET['terms']."&amp;p=$maxPage')\">Last</a>";
}
else {
  $next = '';
  $last = '';
}
  echo $data;
echo "<div id=\"results_bottom\"><p>$first $prev $nav $next $last</p></div>
</div>";
	}
 }
?>


Is This A Good Question/Topic? 0
  • +

Replies To: Question on PHP code for Ajax search form

#2 JSammy  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 23
  • Joined: 20-April 11

Re: Question on PHP code for Ajax search form

Posted 22 April 2012 - 11:28 AM

I'm sorry, I'm a bit confused on what you are trying to do.
Is there a problem with this code? or are you wanting to know where to include the connection to the MySQL Database..?

Let me know and I'll do my best to help you.
Was This Post Helpful? 0
  • +
  • -

#3 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 5723
  • View blog
  • Posts: 22,635
  • Joined: 23-August 08

Re: Question on PHP code for Ajax search form

Posted 22 April 2012 - 12:41 PM

This is likely one of those "I found sum c0dez on da net...make dem work for me plzzzzzzzz!!!!" questions.

Which is why no one's bothered answering it. It's "help vampire" central.
Was This Post Helpful? 0
  • +
  • -

#4 shorne29  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 21-April 12

Re: Question on PHP code for Ajax search form

Posted 22 April 2012 - 06:54 PM

View PostJSammy, on 22 April 2012 - 11:28 AM, said:

I'm sorry, I'm a bit confused on what you are trying to do.
Is there a problem with this code? or are you wanting to know where to include the connection to the MySQL Database..?

Let me know and I'll do my best to help you.

Thank you for replying! I bought this PHP script Ajax Search form and the guy who created it is from overseas and every time I asked him a question I don't know if he is being arrogant or he just doesn't know English very well?? In this script I can search with results that come up with an icon, title and description. I am confused on how to upload the icon He put "files" that I uploaded to my database which shows Field, Type, Function, Null, and Value. On what he has for an icon is (ex.bike.jpg) but I was wondering if there is way in phpMyAdmin database that I have to put a link in the Value field and also how to link the search result to where the search item is within my website. I have all the files if you would like to see them if that would help? or if you would like to see what I purchased to see what I mean for what it looks like in action the link is http://codecanyon.ne...preview/112439. If you type 'here' in the search box it will show you some results. So to sum it all up I don't know how to connect the image icon and the page link to the page result.

View Postshorne29, on 22 April 2012 - 06:50 PM, said:

View PostJSammy, on 22 April 2012 - 11:28 AM, said:

I'm sorry, I'm a bit confused on what you are trying to do.
Is there a problem with this code? or are you wanting to know where to include the connection to the MySQL Database..?

Let me know and I'll do my best to help you.

Thank you for replying! I bought this PHP script Ajax Search form and the guy who created it is from overseas and every time I asked him a question I don't know if he is being arrogant or he just doesn't know English very well?? In this script I can search with results that come up with an icon, title and description. I am confused on how to upload the icon He put "files" that I uploaded to my database which shows Field, Type, Function, Null, and Value. On what he has for an icon is (ex.bike.jpg) but I was wondering if there is way in phpMyAdmin database that I have to put a link in the Value field and also how to link the search result to where the search item is within my website. I have all the files if you would like to see them if that would help? or if you would like to see what I purchased to see what I mean for what it looks like in action the link is http://codecanyon.ne...preview/112439. If you type 'here' in the search box it will show you some results. So to sum it all up I don't know how to connect the image icon and the page link to the page result.

I guess the link I gave doesn't show...this one is it http://codecanyon.ne...rch-form/112439
Was This Post Helpful? 0
  • +
  • -

#5 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2503
  • View blog
  • Posts: 8,564
  • Joined: 08-August 08

Re: Question on PHP code for Ajax search form

Posted 22 April 2012 - 07:41 PM

You paid too much for the script. It's poorly organized and is ripe for SQL injection attacks. I'd start over from scratch.
Was This Post Helpful? 0
  • +
  • -

#6 floppyspace  Icon User is offline

  • D.I.C Head

Reputation: 25
  • View blog
  • Posts: 187
  • Joined: 04-February 10

Re: Question on PHP code for Ajax search form

Posted 22 April 2012 - 07:51 PM

First, man why did you buy a script that is over 2 years old, sure it looks cool but there are many free scripts on the web.

However when you say you hooked up the database right are you talking tables or just the db name and passwords in the config.php file?, did you use the files.sql that was provided with the script?

Take a bit of time to see the comments associated with the script you chose they may be able to help you. I glanced at the comments and it would be reasonable to say the answer will be there, just spend some time reading them.
Was This Post Helpful? 0
  • +
  • -

#7 shorne29  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 21-April 12

Re: Question on PHP code for Ajax search form

Posted 22 April 2012 - 08:14 PM

View Postfloppyspace, on 22 April 2012 - 07:51 PM, said:

First, man why did you buy a script that is over 2 years old, sure it looks cool but there are many free scripts on the web.

However when you say you hooked up the database right are you talking tables or just the db name and passwords in the config.php file?, did you use the files.sql that was provided with the script?

Take a bit of time to see the comments associated with the script you chose they may be able to help you. I glanced at the comments and it would be reasonable to say the answer will be there, just spend some time reading them.

Thanks for the response..I'm new to this ...I will take your advice and just drop it...I didn't know it was bad script. Thanks again for your time.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1