HELP ORDERING BY $value1 $value2???????

Hi guys

I bought a very cool search engine script that displays the information from my MYSQL database but the bad thing about it is that it doesnt have the option to order by row ASC | DESC.

I found where I can add that in the coding by simply adding this "ORDER BY $table $order, I would like the value $table to be a list/menu drop down with at least 3 of my main rows (for example name, age, aboutme) and obviously the $order would be either value ASC or DESC which I would like to use with 2 radio buttons… but my question is how can I do that? how can I “save” the options that people are choosing or clicking?

I included in the search.php a file (sort.php) that I could use to insert those values, I dont know if that helps or if it doesnt make any sense and i should do everything inside search.php, but if i put this <?php $order ="ASC" ?> it works… so i just need to find a way to do something like <? $order = $value_that_changes; ?> and somehow make that $value_that_changes grab the info from the radio buttons and retain it… ughhhh… im so lost! please help ::slight_smile: ::slight_smile: ::slight_smile:

You need to use forms.

See the following tutorial: http://www.tizag.com/phpT/forms.php

What you want to do is have your form handling script take the values that your user input, and use those in your query

Hi, thanks for replying.

I am familiar with the and $_POST, the problem is if i put a form, as soon as i hit submit it loads the other .php page that contains all the coding to display the results and this search engine is running that page in the back and updates “live” thru a javascript… so i just need to store this values somewhere that can be detected by the process.php, i dont want to load it… i just want it to grab those values

Here is my coding:

HEAD of the searching page:

[code]

[/code]

BODY

<!-- begin form --> <div id="form"> <table width="100%" height="50" border="0" cellspacing="0" cellpadding="0"> <tr> <td align="center" valign="middle" scope="col"><span class="fontregisteryet"> <input type="text" class="blackfontverdana" id="terms" onfocus="if ( this.value == this.defaultValue ) this.value = ''" onblur="if ( this.value == '' ) this.value = this.defaultValue" onkeyup="getScriptPage('show_results','terms','1')" value="type your search here" size="45" /> </span></td> </tr> </table> </div> </p> </div> <p> <!-- end form -->

Now the process.php has this:
[php]<?php
// file for database connection
include(‘inc/db.inc.php’);
include(‘inc/sort.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 ‘

e.g. Type ´Denver´ or ´Blonde´ or ´21´ or ´120´ without quotes.
’;
// minim 3 characters condition
} else if(strlen($_GET[‘terms’]) < $limitchar) {
echo ‘
’. $limitchar .’ characters minimum
’;
// no spaces in first 4 letters
} else if(preg_replace(’/[a-zA-Z0-9]/’, ‘’, $nospaces)) {
echo ‘
Please use letters or numbers in first 4 characters
’;
} else {

// explode search words into an array
$arraySearch = explode(" “, $_GET[‘terms’]);
// table fields to search
$arrayFields = array(0 => $first_field, 1 => $second_field, 2 => $third_field, 3 => $forth_field, 4 => $fifth_field, 5 => $sixth_field, 6 => $seventh_field, 7 => $eigth_field, 8 => $nineth_field, 9 => $tenth_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]%’ AND verified=‘yes’";
$b++;
if ($b < $countSearch)
{
$query = $query." AND “;
}
}
$b = 0;
$a++;
if ($a < $countFields)
{
$query = $query.”) OR (";
}
}
$query = $query.") ORDER BY $table $sortby LIMIT $offset, $records_number;";
$search = mysql_query($query);[/php]… ETC, ETC ETC… but that is where i put $table and $sortby and thats where the values would go to…

If you want to load it dynamically (read: without a page load) You will need to use AJAX. I don’t know how much Javascript you know, but you could possibly use a javascript library like jQuery to make it a bit easier.

Teaching you AJAX is somewhat beyond the scope of a PHP help board post’s scope, but there are plenty of tutorials on line that can be reached via google. I’m assuming that the search engine itself uses some sort of AJAX call. you can try altering that AJAX call to include the two fields you have to sort/filter, and change the PHP page that the AJAX request is sent to to take these variables in consideration.

You are right, it uses 2 .js files… very very very little code in those… i sent you a private message to avoid disturbing viewers with code that is no php… but really, my site is 99% php and this is stopping me from finishing it… i would really appreciate if you could help me :’(

Sponsor our Newsletter | Privacy Policy | Terms of Service