Current location: Hot Scripts Forums » Programming Languages » PHP » PHP url var to Jquery then pass back to PHP MYSQL Query

PHP url var to Jquery then pass back to PHP MYSQL Query

Reply
  #1 (permalink)  
Old
New Member
 
Join Date: Jan 2013
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
PHP url var to Jquery then pass back to PHP MYSQL Query

Hi! for http://site.php?search.php?user=user.name

I'm trying to add a condition on [WHERE user=$user to mysql query but it seemed search-data.php is not reading the $user = $_GET["user"];

search-data.php
PHP Code:

       $fetch mysql_query("SELECT * FROM viewreport2 WHERE user='$user' AND comp_name REGEXP '^$param' OR email REGEXP '^$param' OR f_name REGEXP '^$param' OR l_name REGEXP '^$param'");


        
/*
           Retrieve results of the query to and build the table.
           We are looping through the $fetch array and populating
           the table rows based on the users input.
         */
        
while ( $row mysql_fetch_object$fetch ) ) {
            
$sResults .= '<tr id="'$row->id '">';
            
$sResults .= '<td><a style=\'text-decoration : none;\' href=\'crmview.php?id=' $row->id'&user=' $row->user .'\'>' $row->comp_name '</a></td>';
            
$sResults .= '<td>' $row->comp_ind '</td>';
            
$sResults .= '<td>' $row->f_name ' ' $row->l_name'</td>';
            
$sResults .= '<td>' $row->desig '</td>';
            
$sResults .= '<td>' $row->phone_a'-' $row->phone_b'-' $row->phone_c'</td>';
            
$sResults .= '<td>' $row->mobile_a'-' $row->mobile_b'-' $row->mobile_c'</td>';
            
$sResults .= '<td>' $row->email '</td>';
            
$sResults .= '<td>' $row->date '</td>';
            
$sResults .= '<td>' $row->user '</td></tr>';
        }

    } 
So I've tried addin var user = getUrlVars()["user"]; to jquery-search.js but i'm not sure if im doing this the right way.

HTML Code:
 $(document).ready(function(){
        /*
         Set the inner html of the table, tell the user to enter a search term to get started.
         We could place this anywhere in the document. I chose to place it
         in the table.
        */
        $('#results').html('<p style="padding:5px;">Enter a search term to start filtering.</p>');

        /* When the user enters a value such as "j" in the search box
         * we want to run the .get() function. */
        $('#searchData').keyup(function() {

            /* Get the value of the search input each time the keyup() method fires so we
             * can pass the value to our .get() method to retrieve the data from the database */
            var searchVal = $(this).val();
	var user = getUrlVars()["user"];  <==== ADDED THIS and PASS TO MYSQL SEARCH WHERE

            /* If the searchVal var is NOT empty then check the database for possible results
             * else display message to user */
            if(searchVal !== '') {

                /* Fire the .get() method for and pass the searchVal data to the
                 * search-data.php file for retrieval */
                $.get('data/search-data.php?searchData='+searchVal, function(returnData) {
                    /* If the returnData is empty then display message to user
                     * else our returned data results in the table.  */
                    if (!returnData) {
                        $('#results').html('<p style="padding:5px;">Search term entered does not return any data.</p>');
                    } else {
                        $('#results').html(returnData);
                    }
                });
            } else {
                $('#results').html('<p style="padding:5px;">Enter a search term to start filtering.</p>');
            }

        });

    });
the main search.page

HTML Code:
<div id="container">
    <div id="dataTable">
        <div class="ui-grid ui-widget ui-widget-content ui-corner-all">
            <div class="ui-grid-header ui-widget-header ui-corner-top clearfix">

                <div class="header-left">
                    <!-- Left side of table header -->
                </div>

                <div class="header-right">
                    Search: <input style="width:150px;" id="searchData" type="text" method="post"></div>
                </div>

            <table class="ui-grid-content ui-widget-content cStoreDataTable" id="cStoreDataTable">
                <thead>
                    <tr>
                        <th class="ui-state-default">Company</th>
                        <th class="ui-state-default">Industry</th>
                        <th class="ui-state-default">Contact Name</th>
                        <th class="ui-state-default">Designation</th>
                        <th class="ui-state-default">Phone</th>
                        <th class="ui-state-default">Mobile</th>
                        <th class="ui-state-default">Email</th>
                        <th class="ui-state-default">Date</th>
						<th class="ui-state-default" value="<?php echo "$user" ?>" >USER</th>
						</tr>
                </thead>
                <tbody id="results"></tbody>
            </table>
            <div class="ui-grid-footer ui-widget-header ui-corner-bottom">
                <div class="grid-results">Results </div>
            </div>
        </div>
    </div>
</div>
Reply With Quote

Featured Marketplace Scripts (view more)

Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
jQuery Sliders AHHHHH jickpictures JavaScript 0 01-18-11 06:50 PM
ASP or PHP which is better? nepala The Lounge 9 07-14-10 05:48 AM
PHP Redirect based on username, url, using php and mysql Vai PHP 2 05-10-08 02:40 AM
link to iframe//help moose JavaScript 1 01-29-05 12:26 PM
Scrollbar!!!!!! LiLSweetie HTML/XHTML/XML 8 07-22-04 05:01 PM


All times are GMT -5. The time now is 10:38 PM.
vBulletin® Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.