I'm developing a searcher and I made a function that gets the data from a db, saves each ad in a variable and saves pagination (from another function) in another variable, so they can be returned in an array to be printed in the html later.
It works like this: you hit a buy or rent button and you go to the search page (/search?do?=buy/rent) then you have to select the property type, optionally a city/zone and hit search. Ajax sends the data via post (to search.php, the same file), hides the first container and shows the second container that has the list of properties with a pagination at the end of the page.
These are the main variables and a script to hide/show containers:
$mode = filter_input(INPUT_GET, 'do', FILTER_SANITIZE_STRING); // buy or rent
$prop_type = filter_input(INPUT_POST, 'prop_type', FILTER_SANITIZE_STRING); // res or com AJAX
$city = filter_input(INPUT_POST, 'city', FILTER_SANITIZE_NUMBER_INT); // AJAX
$zone = filter_input(INPUT_POST, 'zone', FILTER_SANITIZE_NUMBER_INT); // AJAX
$page_number = filter_input(INPUT_GET, 'page', FILTER_SANITIZE_NUMBER_INT);
if (isset($page_number) && $page_number >= 1) {
$cont1 = 'display: none;';
$cont2 = NULL;
// need a way to get the prop_type (the checked checkbox before changing the page) without using $_GET.
} else {
$cont1 = NULL;
$cont2 = 'display: none;';
}
This is the function:
function get_prop_data($prop_type, $city, $zone, $page_number, $table, $targetpage) {
if ($prop_type == 'res') {
$table2 = 'res_prop';
} else if ($prop_type == 'com') {
$table2 = 'com_prop';
}
if ($city != 0) {
$optional_cond = ' WHERE t2.city = ' . $city;
$optional_cond2 = NULL;
if ($zone != 0) {
$optional_cond2 = ' AND t2.zone = ' . $zone;
}
} else $optional_cond = $optional_cond2 = NULL;
$mysqli = new mysqli('127.0.0.1', 'db', '123456', 'name');
// pagination
if ($stmt = $mysqli->prepare('SELECT COUNT(id) FROM ' . $table)) {
$stmt->execute();
$stmt->bind_result($totalitems);
$stmt->fetch();
if (!isset($page)) {
$page = (int)$page_number <= 0 ? 1 : (int)$page_number;
}
$limit = 4;
if ($page > ceil($totalitems / $limit)) {
$page = ceil($totalitems / $limit);
}
$start = ($page - 1) * $limit;
$stmt->close();
if ($stmt = $mysqli->prepare(' SELECT t1.id, t2.*
FROM ' . $table . ' t1
INNER JOIN ' . $table2 . ' t2 ON t2.id = t1.id
' . $optional_cond . $optional_cond2 . '
LIMIT ?, ?')) {
$stmt->bind_param('ii', $start, $limit);
$stmt->execute();
$stmt->bind_result($id, $id, $type, $status, $bhk, $baths, $area1, $area2, $age, $description, $price, $city, $zone, $img1, $img2, $img3, $img4);
$test = "";
while ($row = $stmt->fetch()) {
if ($status === 0) {
$possesion = 'En construcción';
} else if ($status === 1 || $status === 2) {
$possesion = 'Inmediata';
} else $possesion = 'Desconocida';
if ($prop_type == 'res') {
$is_res = '<p><span class="bath">Bed</span>: <span class="two">' . $bhk . ' BHK</span></p>
<p><span class="bath1">Baths</span>: <span class="two">' . $baths . '</span></p>';
} else $is_res = NULL;
$test .= '<div class="box-col">
<div class="col-sm-6 left-side ">
<img class="img-responsive" src="' . $img1 . '" alt="">
</div>
<div class="col-sm-6 middle-side">
<h4>Disponibilidad: ' . $possesion . '</h4>
' . $is_res . '
<p><span class="bath2">Built-up Area</span>: <span class="two">' . $area1 . ' m²</span></p>
<p><span class="bath3">Plot Area</span>: <span class="two">' . $area2 . ' m²</span></p>
<p><span class="bath4">Age of property</span>: <span class="two">' . $age . ' Year(s)</span></p>
<p><span class="bath5">Price</span>: <span class="two">' . $price . ' €</span></p>
<div class="right-side">
Contact Builder
</div>
</div>
<div class="clearfix"> </div>
</div>
';
$pagination = functions::getPaginationString($page, $totalitems, $limit, $adjacents = 1, $targetpage, $pagestring = "&page=");
}
} //else echo "Statement failed: " . $mysqli->error . "<br>";
} //else echo "Statement failed: " . $mysqli->error . "<br>";
return array($test, $pagination);
}
This is the main code:
if (empty($_GET)) {
echo 'under construction';
}
else if (isset($mode) && $mode == 'buy') {
$table = 'to_sell';
$targetpage = '/search?do=buy';;
if (isset($prop_type)) {
$data = get_prop_data($prop_type, $city, $zone, $page_number, $table, $targetpage);
$test = $data[0];
$pagination = $data[1];
}
}
else if (isset($mode) && $mode == 'rent') {
$table = 'to_rent';
$targetpage = '/search?do=rent';;
if (isset($prop_type)) {
$data = get_prop_data($prop_type, $city, $zone, $page_number, $table, $targetpage);
$test = $data[0];
$pagination = $data[1];
}
}
else {
echo 'invalid url';
}
This is the AJAX script that sends the checkbox value via post (it's not working correctly, I don't get an undefined error in $prop_type (I don't know why???) but I get it in $table2, that it's inside the if ($prop_type == '')):
$('.search, .pagination').click(function() { // search button and change page
if ($('#res_prop').is(':checked')) {
$prop_type = $('#res_prop').val();
}
else if ($('#com_prop').is(':checked')) {
$prop_type = $('#com_prop').val();
}
$.post('search.php', { // same file, maybe self
prop_type: $prop_type,
city: $('select[name=city]').val(), // optional
zone: $('select[name=zone]').val(), // option value="0" by default
success: function(){
$('.cont-1').hide();
$('.cont-2').show();
}
});
});
It works perfectly if I manually set $prop_type = 'res';. Any ideas?
Another problem is that the pagination buttons link does not work, it just triggers the ajax script (they need to send the data, otherwise the script will restart when changing pages).
I really would appreciate any optimization to the scripts. Thanks.
You're mixing your javascript and php here.
In PHP you declare a variable with $varname, in Javascript, $ represents the jQuery operator. As such your code that says $prop_type is totally invalid since this is javascript code. You're telling jQuery to execute some functionality called prop_type which doesn't exist, and as such you're getting an error that this is undefined.
if ($('#res_prop').is(':checked')) {
var prop_type = $('#res_prop').val();
}
else if ($('#com_prop').is(':checked')) {
var prop_type = $('#com_prop').val();
}
And change the line which reads prop_type: $prop_type, to prop_type: prop_type,
If you want to import the <div class="results"></div> container with ajax:
you should use this tested and working code:
$(document).ready(function(){
$('.search, .pagination').click(function() { // search button and change page
$prop_type = '';
if ($('#res_prop').is(':checked')) {
$prop_type = $('#res_prop').val();
}
else if ($('#com_prop').is(':checked')) {
$prop_type = $('#com_prop').val();
}
$.ajax({
method: "POST",
url: "go.php",
data: {
'prop_type': $prop_type,
'city': $('select[name="city"]').val(),
'zone': $('select[name="zone"]').val()
}
}).done(function(data) {
var _html = $.parseHTML(data);
$('.cont-1').hide();
$('.cont-2').show();
$(_html).each(function(i, el) {
if (el.className == 'results') {
$('.results').html($(el).html());
};
});
});
return false;
});
});
Related
I try search value (ean) and if exist in database return title product assigned to this ean.
I've 2 tables:
products
product_details
in products table I have EAN and in product_details I've title.
products.id = product_details.product_id
View:
<div class="form-group">
<label><?= trans("search"); ?></label>
<input type="text" id="input_product_exist" class="form-control" placeholder="<?= trans("category_name"); ?>">
<div id="product_search_result" class="category-search-result"></div>
</div>
Script in view:
<script>
$(document).on("input", "#input_product_exist", function () {
var val = $(this).val();
val = val.trim();
if (val.length > 1) {
var data = {
"ean": val,
"sys_lang_id": sys_lang_id
};
data[csfr_token_name] = $.cookie(csfr_cookie_name);
$.ajax({
type: "POST",
url: base_url + "ajax_controller/search_products",
data: data,
success: function (response) {
var obj = JSON.parse(response);
if (obj.result == 1) {
document.getElementById("product_search_result").innerHTML = obj.content;
}
}
});
} else {
document.getElementById("product_search_result").innerHTML = "";
}
});
ajax_controller:
//search products
public function search_products()
{
$ean = $this->input->post('ean', true);
$products = $this->category_model->search_products_by_ean($product_ean);
$content = '<ul>';
if (!empty($products)) {
foreach ($products as $item) {
$content .= '<li>' . html_escape($item->name) . ' - <strong>' . trans("id") . ': ' . $item->id . '</strong></li>';
}
$content .= '</ul>';
} else {
$content = '<p class="m-t-15 text-center text-muted">' . trans("no_records_found") . '</p>';
}
$data = array(
'result' => 1,
'content' => $content
);
echo json_encode($data);
}
category_model.php
//search products by ean
public function search_products_by_ean($product_ean)
{
$this->db->select('products.id, product_details.title as name');
$this->db->join('product_details', 'product_details.product_id = products.id');
$this->db->like('name', clean_str($product_ean));
//$this->db->where('visibility', 1);
//$this->db->order_by('categories.parent_id');
$this->db->order_by('name');
$query = $this->db->get('products');
return $query->result();
}
Now I try start search: white page.
I check in log console:
jquery.min.js:4 POST https://thisismywebsite.com/ajax_controller/search_products 500
send # jquery.min.js:4
ajax # jquery.min.js:4
(anonymous) # add-product:1581
dispatch # jquery.min.js:3
q.handle # jquery.min.js:3
#update:
I think still I have any issue in step 3, category_model/search_products_by_ean
Here I build working query in phpmyadmin:
SELECT products.ean, product_details.title FROM products INNER JOIN product_details ON products.id = product_details.product_id;
and I get correct output:
#update
you can enable php errors with
error_reporting(E_ALL);
ini_set('display_errors', 1);
for view current error not 500
in ajax controller your must send $ean not $product_ean
//search products
public function search_products()
{
$ean = $this->input->post('ean', true);
// $products = $this->category_model->search_products_by_ean($product_ean);
$products = $this->category_model->search_products_by_ean($ean);//istead $product_ean
$content = '<ul>';
if (!empty($products)) {
foreach ($products as $item) {
$content .= '<li>' . html_escape($item->name) . ' - <strong>' . trans("id") . ': ' . $item->id . '</strong></li>';
}
$content .= '</ul>';
} else {
$content = '<p class="m-t-15 text-center text-muted">' . trans("no_records_found") . '</p>';
}
$data = array(
'result' => 1,
'content' => $content
);
echo json_encode($data);
}
I am using the following plugin
http://plugins.krajee.com/star-rating
I'm trying to send the rating submitted to the database but the values are not being recorded.
require_once $doc_root . '/includes/act_initiate_article_xref.php';
$rating_value = (#$user_article_xref_row['rating'] > 0) ? $user_article_xref_row['rating'] . ' stars' : 'unrated';
$article_rating = '<span class="line-sep">Rated:</span> ' . $rating_value;
if ($_SESSION['user_id'] == 1 || $_SESSION['user_id'] == 41) {
$rating_value_attr = (isset ($user_article_xref_row['rating'])) ? ' value="' . $user_article_xref_row['rating'] . '"' : '';
$article_rating .= '<span class="line-sep">Your rating: </span> <input id="input-21d" type="number" class="rating"' . $rating_value_attr . ' data-min=0 data-max=5 step=0.5 data-size="xs">';
}
and the code for act_initiate_article_xref.php
<?
/**
* reads user_article_xref
*/
$this_routine[] = "includes/act_initiate_article_xref.php";
/**
* no direct access allowed
*/
$doc_root = $_SERVER['DOCUMENT_ROOT'];
require_once $doc_root . '/includes/act_check_valid_access.php';
$table_title = 'user_article_xref';
$user_id = (isset ($_SESSION['user_id'])) ? $_SESSION['user_id'] : 0;
$fields = '`id`, `hits`, `rating`';
$match_where = '`user_id` = ' . $user_id . ' and `article_id` = ' . $article_id;
$article_result = $db->selectByStrings($fields, $table_title, $match_where, null, 1);
#if ($_SESSION['user_id'] == 1) { echo "<br>21. select $fields from $table_title where $match_where<pre>";print_r($_SESSION);echo "</pre>"; }
/**
* if there is already a record, update it
* if there isn't already a record, insert it
* either way, $user_article_xref_row holds details for any ajax rating update
*/
if ($db->getNumRows($article_result) > 0) {
$user_article_xref_row = $db->getNextRow($article_result);
$hits = $user_article_xref_row['hits'] + 1;
$pairs_array = array ('hits' => $hits);
$id_where = '`id` = ' . $user_article_xref_row['id'];
$update_result = $db->updateByArray($table_title, $pairs_array, $id_where);
$test = 'update';
} else {
$hits = 1;
$user_article_xref_row = array ('user_id' => $user_id, 'article_id' => $article_id, 'hits' => $hits);
$insert_result = $db->insertByArray($table_title, $user_article_xref_row);
$test = 'insert';
}
#if ($_SESSION['user_id'] == 1) { echo "<br>37. $test<pre>";print_r($user_article_xref_row);echo "</pre>"; }
?>
I know this post is a little old but just in case. In the star-rating.js I added an ajax post to my php file to the set.listenClick function. Hope this helps.
self.listenClick(self.$rating, function(e) {
if (self.inactive) {
return false;
}
pos = self.getPosition(e);
var div_id = self.$element.attr('id');
self.setStars(pos);
self.$element.trigger('change').trigger('rating.change', [self.$element.val(), self.$caption.html()]);
self.starClicked = true;
var rating = self.$element.val();
$.ajax({
type:"POST",
url:"rating.php",
data:"div="+div_id+"&rating="+rating,
success: function(res){
console.log("Rating was posted " + div_id + rating);
return res;
}
});
});
I'm actually trying to create a ( more or less ) instant chat.
There's just one thing left to go, until it's finished. And that's a DB check for new entries every second by PHP itself.
A while loop works great for it, because i can exit it perfectly.
The Problem is, that the "every second" thing isn't working.
I tried a sleep(1), but that causes a 1 minute server freeze, until the script has been completed.
Hope someone can help me, i'm actually frustrated about this problem.
elseif($latestID != 'undefined' && $_POST['returnafter'] == '60')
{
$timeout = '60';
$i = '0';
while ($i != $timeout)
{
$chat_content = "";
$i++;
$getLastID = mysql_query("SELECT id, userid, content, time_posted FROM (SELECT * FROM chat_system ORDER BY id DESC LIMIT 150) chat_system WHERE id > '" . $latestID . "' $extraQuery ORDER BY id ASC");
while ($lastID = mysql_fetch_object($getLastID))
{
$rowID = $lastID->id;
$user_posted_id = $lastID->userid;
$chat_content = $lastID->content;
$chat_posted = $lastID->time_posted;
$getUserData = mysql_query("SELECT username, avatar, loggedIn FROM account_data WHERE account_id=('" . $user_posted_id . "')");
while ($userData = mysql_fetch_object($getUserData))
{
$username = $userData->username;
$useravatar = $userData->avatar;
$loginStatus = $userData->loggedIn;
}
if ($loginStatus == '1')
{
$onlineStatus = '<img src="./images/3DArt/newOnline.png" class="chat_onlineStatus">';
}
else
{
$onlineStatus = '<img src="./images/3DArt/newOffline.png" class="chat_onlineStatus">';
}
if (date('Y-m-d', $chat_posted) == date('Y-m-d'))
{
$time_posted = strftime('Heute, %H:%M', $chat_posted);
}
elseif (date('Y-m-d', $chat_posted) == date('Y-m-d', strtotime("Yesterday")))
{
$time_posted = strftime('Gestern, %H:%M', $chat_posted);
}
elseif (date('Y-m-d', $chat_posted) < date('Y-m-d', strtotime("Yesterday")))
{
$time_posted = strftime("%A, %d %B %Y %H:%M", $chat_posted);
}
if (isset($_POST['parseEmoticons']) && $_POST['parseEmoticons'] == 'true')
{
$chat_content = emoticons($chat_content);
}
$newChatRow.= '<div class="chatRow" id="' . $rowID . '">
<div class="chatRow_container">
<div><img src="' . $useravatar . '" class="chatAvatar">' . $onlineStatus . '<b>' . $username . '</b>
</div>
</div>' . $modActions . '
<div class="chat_mainMsg">
' . $chat_content . '
</div>
<div class="chatTime">' . $time_posted . '</div>
</div>';
}
$content = str_replace(array(
'\r\n',
'\r',
'\n'
) , "<br />", $newChatRow);
if(!empty($chat_content)) { echo $newChatRow; $i = $timeout; return false; }
if(empty($chat_content)) { sleep(1); return true; }
}
}
I think, this informations should be enough. If not, just ask.
EDIT: The request is initialized by Ajax and on success the request repeats.
That's why PHP have to check for 60 seconds.
you should let the clientside decide what messages it "like" to receive.
eg you call your messages.php class - per ajax on the client side and pass a timestamp when the last time was the script requested new messages
example:
ajax interval with 1 second loop call the messages.php?last=123456 and receive all messages that were created after or equal this timestamp. now you update in javascript the last timestamp and so on.
or you use a perfect framework (if possible) that is designed perfectly for your task to solve this.
http://socket.io/ (or js keyword websockets)
I have a comics website. A feature it has is to allow users to search comics... the search will instantly parse the input and return thumbnail results based on matching title and keywords.
Originally, the search would return all of the results, and the bounding search box would expand infinitely downward, holding every single comic result. I thought it may be a nice touch to limit the results to 4, and display a message like "load 5 remaining images" if the user chooses to do so.
If they click on that message, I wanted limiting php variable to be removed or changed.
So far, it loads with the limit, and shows a link...
EDIT: Latest Code:
search_field.php (the search file that get's included on a page... this file calls search.php via JQuery):
<?php $site = (isset($_GET['site']) ? ($_GET['site']) : null); ?>
<div id="sidebar" class="searchborder">
<!--Allow users to search for comic-->
<!--<span class="search">Search for <?php// echo (($site == "artwork") ? 'artwork' : 'a comic'); ?> </span>-->
<script type="text/javascript">
function GetSearch(mySearchString){
$.get("./scripts/search.php", {_input : mySearchString, _site : '<?php echo $site ?>'},
function(returned_data) {
$("#output").html(returned_data);
}
);
}
</script>
<center>
<table>
<tr>
<td>
<span class="search">
<img src="./images/SiteDesign/Search.png" />
<input type="text" onkeyup="GetSearch(this.value)" name="input" value="" />
<!--<input id="site" type="hidden" value="<?php// echo $site; ?>">-->
</span>
</td>
</tr>
</table>
</center>
<span id="output"> </span>
</div>
search.php, the file that's called to parse the string and return the results:
<?php
//Query all images:
include 'dbconnect.php';
$site = $_GET['_site'];
$input = (isset($_GET['_input']) ? ($_GET['_input']) : 0);
$siteChoice = (isset($_GET['_choice']) ? ($_GET['_choice']) : $site);
$start = (isset($_GET['_start']) ? ($_GET['_start']) : null);
echo "start: " . $start;
//if user goes to hittingtreeswithsticks.com... no "site" value will be set... so I need to set one
if ($site == null) {
$site = "comics";
}
if ($siteChoice == "artwork") {
$sql = "SELECT id, title, keywords, thumb FROM artwork";
$thumbpath = "./images/Artwork/ArtThumbnails/";
}
else if ($siteChoice == "comics") {
$sql = "SELECT id, title, keywords, thumb FROM comics";
$thumbpath = "./images/Comics/ComicThumbnails/";
}
else {
$sql = "SELECT id, title, keywords, thumb FROM $site";
if ($site == "artwork") {
$thumbpath = "./images/Artwork/ArtThumbnails/";
}
else {
$thumbpath = "./images/Comics/ComicThumbnails/";
}
}
/* For this to work, need all comics replicated in an "All Comics" file along with "All Thumbnails"
else {
$sql = "SELECT id, title, thumb FROM comics
UNION
SELECT id, title, thumb FROM artwork";
$thumbpath = "./images/AllThumbnails/";
}*/
$imgpaths = $mysqli->query($sql);
mysqli_close($mysqli);
$idresult = array();
$imgresult = array();
$thumbresult = array();
//CHECK IF $INPUT == IMAGE PATH
if (strlen($input) > 0)
{
while ($row = $imgpaths->fetch_assoc())
{
//query against key words, not the image title (no one will remember the title)
if (stripos($row['keywords'], $input) !== false || strtolower($input)==strtolower(substr($row['title'],0,strlen($input))))
//if (strtolower($input)==strtolower(substr($row['title'],0,strlen($input))))
{
array_push($idresult, $row['id']);
array_push($imgresult, $row['title']);
array_push($thumbresult, $row['thumb']);
}
}
//ECHO RESULTS ARRAY
if(count($imgresult) == 0)
{
echo "<p>no suggestions</p>";
}
else
{
echo "<ul>";
$k = 0;
$max = 4;
if (count($imgresult) > $max) {
while ($k < count($imgresult) && $k < $max)
{
echo '<li>
<span class="sidebarimages"><a href=".?action=viewimage&site=' . $siteChoice . '&id=' . $idresult[$k] . '">
<img src="./scripts/thumber.php?img=.'.$thumbpath.$thumbresult[$k].'&mw=90&mh=90"/></a></span>
</li>';
$k++;
}
$difference = count($imgresult)-$k;
echo "<br/><i><a href='.?action=homepage&site=" . $siteChoice . "&start=4' class='loadSearch'>load " . $difference . " more result" . (($difference != 1) ? 's' : '') . "... </a></i>";
}
else {
while ($k < count($imgresult))
{
echo '<li>
<span class="sidebarimages"><a href=".?action=viewimage&site=' . $siteChoice . '&id=' . $idresult[$k] . '">
<img src="./scripts/thumber.php?img=.'.$thumbpath.$thumbresult[$k].'&mw=90&mh=90"/></a></span>
</li>';
$k++;
}
}
echo "</ul>";
}
}
?>
<script type="text/javascript">
$(".loadSearch").click(function() {
//alert("Test");
$.get("./search.php", {_start : 4},
function (returned_data) {
$("#moreResults").html(returned_data);
}
);
});
</script>
Try this:
<script type="text/javascript">
$("#loadSearch").click(function() {
$.get('URL WITH QUERY', function(data) {
$('#results').html(data);
});
});
</script>
From what i get all you need is when "load more" is clicked only new results should be shown.
Load more has to be a url same as your search url.
Search/Autocomplete URL - example.com/autocomplete?q=xkd
Load More URL - example.com/autocomplete?q=xkd&start=4&max=1000
Just add two parameters to your url. start and max. Pass them to your queries and you get exact result.
Only verify Start < Max and are integers intval() and not 0 empty(). Also if Max <= 4 then dont show load more.
I would give all of your results back, then try to determine your results. If more then 4, loop out the first 4 results. If the user clicks on the load more button your start looping from your 4th element. That way you only need to hit the server once (per search).
Try to give back your results in json, so you can format it the way you like in your html file.
In pseudo code:
searchTerm = 'hello';
resultsFromServer = getResults($searchterm);
resultcounter = count(resultsFromServer);
if(resultcounter > 4)
loop 4 results
else
loop all results
$(".loadSearch").click(function(e) {
//alert("Test");
e.preventDefault();
$.get("./search.php", {_start : 4},
function (returned_data) {
$("#moreResults").html(returned_data);
}
);
I ended up going with jquery show and hide functions.
PHP Snippet:
//ECHO RESULTS ARRAY
if(count($imgresult) == 0)
{
echo "<p>no suggestions</p>";
}
else
{
echo "<ul>";
$k = 0;
$max = 4;
while ($k < count($imgresult) && $k < $max)
{
echo '<li>
<span class="sidebarimages"><a href=".?action=viewimage&site=' . $siteChoice . '&id=' . $idresult[$k] . '">
<img src="./scripts/thumber.php?img=.'.$thumbpath.$thumbresult[$k].'&mw=90&mh=90"/></a></span>
</li>';
$k++;
}
$difference = count($imgresult)-$k;
echo '<div id="moreResults">';
while ($k < count($imgresult))
{
echo '<li>
<span class="sidebarimages"><a href=".?action=viewimage&site=' . $siteChoice . '&id=' . $idresult[$k] . '">
<img src="./scripts/thumber.php?img=.'.$thumbpath.$thumbresult[$k].'&mw=90&mh=90"/></a></span>
</li>';
$k++;
}
echo '</div>';
if (count($imgresult) > $max) {
?>
<br />Load <?php echo $difference; ?> more result<?php echo (($difference != 1) ? 's' : ''); ?>...
<?php
}
echo "</ul>";
}
}
Jquery:
<script type="text/javascript">
$("#moreResults").hide();
$("#showMore").click(function() {
$("#moreResults").show();
$("#showMore").hide();
});
ok maybe i must put all my code:
<?php
include('header_application.php');
$obj_clean->check_user();
$limit = 10;
if(!isset($_GET['page']))
$page = 1;
else
$page = $_GET['page'];
$from = (($page * $limit) - $limit);
$msg = "";
if (isset($_GET['unblock']))
{
$code = $obj_clean->unblockUser($_GET['unblock'],$_GET['code']);
if ($code == "error")
{
$msg = "Could not delete message!";
}
else
{
$msg = "You have unblocked ".$code;
}
}
//Get dynamic data required for this page from the database
$users = $obj_clean->getContacts($_SESSION['user_id'], $from, $limit);
$rows = $obj_clean->getContactsCount($_SESSION['user_id']);
include ("header.php");
?>
<div class="innerContainer">
<head>
<script type="text/JavaScript">
function yesnolist(val)
{
var e = confirm('Do you want to send a free chat request?');
if (e == true)
{
window.location.href = "http://www-rainbowcode-mobi/confirmfreechat.php";
//window.location('http://www-rainbowcode-mobi/confirmfreechat.php');
return true;
}
else
return false;
}
</script>
</head>
<span class="headings2">CONTACTS</span>
<?php if (isset($msg) && !empty($msg)) echo "<br/><font color='red'>".$msg."</font>"; ?>
<br/><br/>
<?php
if (count($users) > 0)
{
echo "<table width='100%' cellpadding='0' cellspacing='0' border='0'>";
foreach ($users as $user)
{
//Breaks the unique code into 3 parts so that the numeric part can be a different colour
$codeLength = strlen($user['unique_code']);
$firstPartLength = $codeLength - 5;
$uniqueCode3 = substr($user['unique_code'], -2);
$uniqueCode2 = substr($user['unique_code'], -5, 3);
$uniqueCode1 = substr($user['unique_code'], 0, $firstPartLength);
echo '<tr>';
echo '<td>';
echo '<a class="charcoal_link" style="line-height: 20px;" href="'.ADDRESS.'view_profile.php?id='.$user['profile_id_contact'].'">'.$uniqueCode1.'<span class="pink_text">'.$uniqueCode2.'</span>'.$uniqueCode3.'</a>';
$requestor_id = $_SESSION['user_id'];
$profile_id = $user['profile_id_contact'];
$rel1 = $obj_clean->hasRelation($requestor_id,$profile_id);
$rel2 = $obj_clean->hasRelation($profile_id,$requestor_id);
if($rel1 && $rel2)
{
echo " ";
//echo 'Free Chat';
echo 'Free Chat';
}
echo "</td>";
echo "</tr>";
}
echo "</table>";
}
else
{
echo "You have no contacts yet";
}
?>
</div>
<?php include("footer.php"); ?>
hope this will help better
Free Chat
should be:
Free Chat
try this:
function yesnolist()
{
if (confirm('Do you want to send a free chat request?'))
window.location = "http://www-rainbowcode-mobi/confirmfreechat.php";
}
.
.
.
<a href="#" onClick="yesnolist()">
I'd assume changing the URLs to valid domains might help things, so try:
window.location.href = "http://www.rainbowcode.mobi/confirmfreechat.php";
window.location('http://www.rainbowcode.mobi/confirmfreechat.php');
function yesnolist()
{
var e = confirm('Do you want to send a free chat request?');
if (e == true)
{
window.location = "http://www-rainbowcode-mobi/confirmfreechat.php";
return true;
}
else
return false;
}
and
<label onClick="return yesnolist();">Free Chat</a>
You can not pass onclick event on (a href="") tag because href part redirects the page and after that the javascript redirect part is called.
Or
(a href="#" onclick="return yesnolist();")Free Chat(/a)