/    Sign up×
Community /Pin to ProfileBookmark

sql search query help

I have made a sql query to search a database on various fields that should be between a range of values or between various multiple choices

[code=php]
<?php require_once(‘Connections/dbconn.php’); ?>
<?php
$vareyecolor_rsVis = “%”;
if (isset($_POST[‘eye_color’])) {
$vareyecolor_rsVis = (get_magic_quotes_gpc()) ? $_POST[‘eye_color’] : addslashes($_POST[‘eye_color’]);
}
$varbrlo_rsVis = “%”;
if (isset($_POST[‘brlo’])) {
$varbrlo_rsVis = (get_magic_quotes_gpc()) ? $_POST[‘brlo’] : addslashes($_POST[‘brlo’]);
}
$varbrhi_rsVis = “%”;
if (isset($_POST[‘brhi’])) {
$varbrhi_rsVis = (get_magic_quotes_gpc()) ? $_POST[‘brhi’] : addslashes($_POST[‘brhi’]);
}
$varwstlo_rsVis = “%”;
if (isset($_POST[‘wstlo’])) {
$varwstlo_rsVis = (get_magic_quotes_gpc()) ? $_POST[‘wstlo’] : addslashes($_POST[‘wstlo’]);
}
$varwsthi_rsVis = “%”;
if (isset($_POST[‘wsthi’])) {
$varwsthi_rsVis = (get_magic_quotes_gpc()) ? $_POST[‘wsthi’] : addslashes($_POST[‘wsthi’]);
}
$varhiplo_rsVis = “%”;
if (isset($_POST[‘hiplo’])) {
$varhiplo_rsVis = (get_magic_quotes_gpc()) ? $_POST[‘hiplo’] : addslashes($_POST[‘hiplo’]);
}
$varhiphi_rsVis = “%”;
if (isset($_POST[‘hiphi’])) {
$varhiphi_rsVis = (get_magic_quotes_gpc()) ? $_POST[‘hiphi’] : addslashes($_POST[‘hiphi’]);
}
$varhtlo_rsVis = “%”;
if (isset($_POST[‘htlo’])) {
$varhtlo_rsVis = (get_magic_quotes_gpc()) ? $_POST[‘htlo’] : addslashes($_POST[‘htlo’]);
}
$varhthi_rsVis = “%”;
if (isset($_POST[‘hthi’])) {
$varhthi_rsVis = (get_magic_quotes_gpc()) ? $_POST[‘hthi’] : addslashes($_POST[‘hthi’]);
}
$varhcolor_rsVis = “%”;
if (isset($_POST[‘hair_color’])) {
$varhcolor_rsVis = (get_magic_quotes_gpc()) ? $_POST[‘hair_color’] : addslashes($_POST[‘hair_color’]);
}
$varwarea_rsVis = “%”;
if (isset($_POST[‘w_area’])) {
$varwarea_rsVis = (get_magic_quotes_gpc()) ? $_POST[‘w_area’] : addslashes($_POST[‘w_area’]);
}

if(empty($offset))
$offset=0;
define(ROWS,25);
mysql_select_db($database_dbconn, $dbconn);
$query_rsVis = sprintf(“SELECT users.id, users.color_eyes, users.foto1, users.foto2, users.foto3, users.alias_name, users.meas_bres, users.meas_waist, users.meas_hip, users.height, users.cv1_date, users.cv1_title, users.cv1_contents FROM users WHERE users.color_eyes=’%s’ AND users.meas_bres>’%s’ AND users.meas_bres<‘%s’ AND users.meas_waist>’%s’ AND users.meas_waist<‘%s’ AND users.meas_hip>’%s’ AND users.meas_hip<‘%s’ AND users.height>’%s’ AND users.height<‘%s’ AND users.hair_color=’%s’ AND users.w_area=’%s'”, $vareyecolor_rsVis,$varbrlo_rsVis,$varbrhi_rsVis,$varwstlo_rsVis,$varwsthi_rsVis,$varhiplo_rsVis,$varhiphi_rsVis,$varhtlo_rsVis,$varhthi_rsVis,$varhcolor_rsVis,$varwarea_rsVis);
$rsVis = mysql_query($query_rsVis, $dbconn) or die(mysql_error());

$totalRows_rsVis = mysql_num_rows($rsVis);

[/code]

Here the query only works if both the range of values is selected.

How do I modify this query if a person wants to give the option”All records” or does not insert any value in the range of values(that means all records ,of say meas_waist,no range to be specified)

Somebody pls help!!

Thanks

Ashokvas

to post a comment
PHP

20 Comments(s)

Copy linkTweet thisAlerts:
@scragarJan 10.2005 — [code=php]
<?
$a = $_POST['result_1'];
if($a == ""){
$a = "%";
};

mysql_query("SELECT * FROM my_tbl WHERE feild1 LIKE '$a';");
[/code]
Copy linkTweet thisAlerts:
@ashokvasauthorJan 11.2005 — Thanks for the suggestion.

But what I want is that suppose the user does not fill any value range for certain fields,then the quuery should give the result for all values for those fields.He only puts the values for certain fields and leaves the others blank.

Hope I am able to make my point clear.

Your suggestion may not work here.

Regards

Ashokvas
Copy linkTweet thisAlerts:
@scragarJan 11.2005 — for text feilds you should always use like for comparisons, after all you want them case sensitive preferably with wildcards(commonly repesented as an * not a % but 2 str_replace functions will sort that out), as for numbers just check if it's blank and if so(or it's not a number) replace it with an extreamity("> -1" or "< 2000000" works well)

hope this helps.
Copy linkTweet thisAlerts:
@ashokvasauthorJan 12.2005 — Thanks for the suggestion,but I am still not sure what to do.

Can you pls show me what to change in my script.

Take the case of var 'eyecolor' which gets its values from a dropdownmenu.If a user selects "All" here how does the query get affected?Also inthe field 'meas_waist' there is a range ofvalues tobe entered.In case the user leaves these fields blANK,THEN should I use the extremeties as default values ?

Ashokvas
Copy linkTweet thisAlerts:
@scragarJan 12.2005 — [code=php]<?
$myquery = "SELECT * FROM users WHERE 1";

if (isset($_POST['eye_color'])) {
$vareyecolor_rsVis = (get_magic_quotes_gpc()) ? $_POST['eye_color'] : addslashes($_POST['eye_color']);
}
if(isset($vareyecolor_rsVis) || $vareyecolor_rsVis == ""){
$myquery .= " AND color_eyes='$vareyecolor_rsVis'";
};[/code]


works as well, in this example I just compound the query as I go along thus making it so if there is no result to search for(the feild is left as a blank string in this example although you could check it against "all" or "everything"...) it just doesn't test it.
Copy linkTweet thisAlerts:
@ashokvasauthorJan 12.2005 — Thanks for your help which is as follows

PHP:
--------------------------------------------------------------------------------


<?

$myquery = "SELECT * FROM users WHERE 1";

if (isset($_POST['eye_color'])) {

$vareyecolor_rsVis = (get_magic_quotes_gpc()) ? $_
POST['eye_color'] : addslashes($_POST['eye_color']);

}

if(isset($vareyecolor_rsVis) || $vareyecolor_rsVis == ""){

$myquery .= " AND color_eyes='$vareyecolor_rsVis'";

};
--------------------------------------------------------------------------------




I do not understand the following:

1)"SELECT * FROM users WHERE 1";

what does WHERE 1 mean?

2)If the user does not fill any value for 'eye_color' this will give empty value to the variable($vareyecolor_rsVis == "")

in this case the search result will be blank as there are no records where 'eye_color' is blank.

What I want is that when this variable is not set,then the search result should include all the records for all the values of 'eye_color'that have been entered in the database.

In efect it means that the " AND color_eyes='$vareyecolor_rsVis'"

should not be part of the query at all.

Hence the query should include this AND color_eyes='$vareyecolor_rsVis'part if the 'eye_color' is not set to "".

Hope I have been able to explain my problem.

Maybe I am new so I am giving you so much trouble.

Thanks once again for the effort.

Ashok vas
Copy linkTweet thisAlerts:
@scragarJan 12.2005 — [i]Originally posted by ashokvas [/i]

Thanks for your help which is as follows

PHP:
--------------------------------------------------------------------------------


<?

$myquery = "SELECT * FROM users WHERE 1";

if (isset($_POST['eye_color'])) {

$vareyecolor_rsVis = (get_magic_quotes_gpc()) ? $_
POST['eye_color'] : addslashes($_POST['eye_color']);

}

if(isset($vareyecolor_rsVis) || $vareyecolor_rsVis == ""){

$myquery .= " AND color_eyes='$vareyecolor_rsVis'";

};
--------------------------------------------------------------------------------




I do not understand the following:

1)"SELECT * FROM users WHERE 1";

what does WHERE 1 mean?
[/quote]

the 1 returns true, this is just used so we can just use AND codes as oposed to having to find the first result in the search and have it use the where clause(which is a considerable peice of code)

2)If the user does not fill any value for 'eye_color' this will give empty value to the variable($vareyecolor_rsVis == "")

in this case the search result will be blank as there are no records where 'eye_color' is blank.

What I want is that when this variable is not set,then the search result should include all the records for all the values of 'eye_color'that have been entered in the database.

In efect it means that the " AND color_eyes='$vareyecolor_rsVis'"

should not be part of the query at all.

Hence the query should include this AND color_eyes='$vareyecolor_rsVis'part if the 'eye_color' is not set to "".
[/quote]

which is why the if is there, if no result is submited(the isset psrt) or it's blank(the == "" part) do nothing, otherwise write out the required where clause.
Copy linkTweet thisAlerts:
@ashokvasauthorJan 12.2005 — scragar wrote

quote:

'which is why the if is there, if no result is submited(the isset psrt) or it's blank(the == "" part) do nothing, otherwise write out the required where clause.'


if the user does not enter anything,then (the=="") part returns true and the query is added to the query string.We want that it should not be added to the query.

Sorry if I am not understanding correctly


Ashokvas
Copy linkTweet thisAlerts:
@ashokvasauthorJan 13.2005 — I wrote the query as follows and it works fine if some of the fields are kept blank.If all fields are kept blank,then 6 records are showneven though there are only 2 records in the table.Pls visit http://www.accordweb.info/access_user/SearchVisit.htm and keep the fields blank.Can any onehelp me out??


[code=php]
<?php require_once('Connections/dbconn.php'); ?>
<?php
$query_rsVis = "SELECT users.id, users.color_eyes, users.foto1, users.foto2, users.foto3, users.alias_name, users.meas_bres, users.meas_waist, users.meas_hip, users.height, users.cv1_date, users.cv1_title, users.cv1_contents FROM users ";

if (isset($_POST['eye_color'])) {
$vareyecolor_rsVis = (get_magic_quotes_gpc()) ? $_POST['eye_color'] : addslashes($_POST['eye_color']);
}
if(isset($vareyecolor_rsVis) && $vareyecolor_rsVis !== ""){
$query_rsVis .= " WHERE color_eyes='$vareyecolor_rsVis'";
}

if (isset($_POST['brlo'])) {
$varbrlo_rsVis = (get_magic_quotes_gpc()) ? $_POST['brlo'] : addslashes($_POST['brlo']);
}
if(isset($varbrlo_rsVis) && $varbrlo_rsVis !== ""){
$query_rsVis .= " AND users.meas_bres>='$varbrlo_rsVis'";
}


if (isset($_POST['brhi'])) {
$varbrhi_rsVis = (get_magic_quotes_gpc()) ? $_POST['brhi'] : addslashes($_POST['brhi']);
}
if(isset($varbrhi_rsVis) && $varbrhi_rsVis !== ""){
$query_rsVis .= " AND users.meas_bres<='$varbrhi_rsVis'";
}



if (isset($_POST['wstlo'])) {
$varwstlo_rsVis = (get_magic_quotes_gpc()) ? $_POST['wstlo'] : addslashes($_POST['wstlo']);
}
if(isset($varwstlo_rsVis) && $varwstlo_rsVis !== ""){
$query_rsVis .= " AND users.meas_waist>='$varwstlo_rsVis'";
}

if (isset($_POST['wsthi'])) {
$varwsthi_rsVis = (get_magic_quotes_gpc()) ? $_POST['wsthi'] : addslashes($_POST['wsthi']);
}
if(isset($varwsthi_rsVis) && $varwsthi_rsVis !== ""){
$query_rsVis .= " AND users.meas_waist<='$varwsthi_rsVis'";
}


if (isset($_POST['hiplo'])) {
$varhiplo_rsVis = (get_magic_quotes_gpc()) ? $_POST['hiplo'] : addslashes($_POST['hiplo']);
}
if(isset($varhiplo_rsVis) && $varhiplo_rsVis !== ""){
$query_rsVis .= " AND users.meas_hip>='$varhiplo_rsVis'";
}

if (isset($_POST['hiphi'])) {
$varhiphi_rsVis = (get_magic_quotes_gpc()) ? $_POST['hiphi'] : addslashes($_POST['hiphi']);
}
if(isset($varhiphi_rsVis) && $varhiphi_rsVis !== ""){
$query_rsVis .= " AND users.meas_hip<='$varhiphi_rsVis'";
}


if (isset($_POST['htlo'])) {
$varhtlo_rsVis = (get_magic_quotes_gpc()) ? $_POST['htlo'] : addslashes($_POST['htlo']);
}
if(isset($varhtlo_rsVis) && $varhtlo_rsVis !== ""){
$query_rsVis .= " AND users.height>='$varhtlo_rsVis'";
}
if (isset($_POST['hthi'])) {
$varhthi_rsVis = (get_magic_quotes_gpc()) ? $_POST['hthi'] : addslashes($_POST['hthi']);
}
if(isset($varhthi_rsVis) && $varhthi_rsVis !== ""){
$query_rsVis .= " AND users.height<='$varhthi_rsVis'";
}

if (isset($_POST['hair_color'])) {
$varhcolor_rsVis = (get_magic_quotes_gpc()) ? $_POST['hair_color'] : addslashes($_POST['hair_color']);
}
if(isset($varhcolor_rsVis) && $varhcolor_rsVis !== ""){
$query_rsVis .= " AND users.hair_color='$varhcolor_rsVis'";
}

if (isset($_POST['w_area'])) {
$varwarea_rsVis = (get_magic_quotes_gpc()) ? $_POST['w_area'] : addslashes($_POST['w_area']);
}
if(isset($varwarea_rsVis) && $varwarea_rsVis !== ""){
$query_rsVis .= " AND users.w_area='$varwarea_rsVis'";
}
if(empty($offset))
$offset=0;
define(ROWS,25);
mysql_select_db($database_dbconn, $dbconn);



$rsVis = mysql_query($query_rsVis, $dbconn) or die(mysql_error());

$totalRows_rsVis = mysql_num_rows($rsVis);


?><?php
if ($totalRows_rsVis != 0)
{
$prevOffset=$offset-ROWS;

$nextOffset=$offset+ROWS;

if(!mysql_data_seek($rsVis,$offset))
echo "Error seeking data";?>

[/code]

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<!-- TemplateBeginEditable name="doctitle" -->

<title>Untitled Document</title>

<!-- TemplateEndEditable -->

<!-- TemplateBeginEditable name="head" -->

<!-- TemplateEndEditable -->

<style type="text/css">

<!--

body,td,th {

font-family: Verdana, Arial, Helvetica, sans-serif;

font-size: 9px;

color: #000000;

font-style: normal;

}

body {

background-color: #D9DAE7;

margin-left: 0px;

margin-top: 0px;

margin-right: 0px;

margin-bottom: 0px;

}

h1,h2,h3,h4,h5,h6 {

font-family: Arial, Helvetica, sans-serif;

}

h1 {

font-size: 24px;

color: #000000;

}

h2 {

font-size: 18px;

color: #000000;

}

h3 {

font-size: 16px;

color: #000000;

}

h4 {

font-size: 14px;

color: #000000;

}

h5 {

font-size: 12px;

color: #000000;

}

h6 {

font-size: 10px;

color: #000000;

}

-->

</style>

<link href="Templates/Bodytext.css" rel="stylesheet" type="text/css" />

</head>

<body>

<div align="center">

<table width="699" border="0" cellpadding="10" cellspacing="0" bgcolor="#FFFFFF">

<tr>

<td width="679">

<table width="635" height="825" border="0" cellpadding="5" cellspacing="0">

<tr>

<td height="66" colspan="4"><p><img src="Graphics/SearchBar.jpg" width="625" height="43" /></p>

</td>

</tr>




[code=php]

<?php
for($rowCounter=0;
(($rowCounter<ROWS)&&

($row_rsVis = mysql_fetch_assoc($rsVis)));
$rowCounter++){ ?>

[/code]

<tr>

<td align="center" valign="top"><a href="ModelStatsVisit.php?id=<?php echo $row_rsVis['id'];?>">Stats</a></td>

<td align="left" valign="top">&nbsp;


<td align="center" valign="top"><a href="Sorry3.php">Curriculum</a></td>

<td align="center" valign="top"><a href="Sorry3.php">Book</a></td>

</tr>

<tr>

<td width="76" height="119" align="left" valign="top"><img src="thumbs/<?php echo $row_rsVis['foto1']; ?>" width="73" height="100" border="0" /></td>

<td width="367" align="left" valign="top"><h5> <?php echo $row_rsVis['alias_name']; ?></h5>

<p>Height:<?php echo $row_rsVis['height']; ?> cm, Measures:<?php echo $row_rsVis['meas_bres']; ?>-<?php echo $row_rsVis['meas_waist']; ?>-<?php echo $row_rsVis['meas_hip']; ?>. Latest assignment: (CV1Date) <strong><?php echo $row_rsVis['cv1_date']; ?>, </strong>(CV1 Title) <strong><?php echo $row_rsVis['cv1_title']; ?></strong>, (CV1 Text)<font class="normal">:<a href="Sorry3.php">For

more information &gt;&gt;&gt;</a>.</font>

<p>&nbsp;


<td width="86" align="center" valign="top"><img src="thumbs/<?php echo $row_rsVis['foto2']; ?>" width="72" height="100" border="0" /></td>


<td width="75" align="center" valign="top"><img src="thumbs/<?php echo $row_rsVis['foto3']; ?>" width="72" height="100" /></td>

</tr>

<tr>
<td height="23" colspan="4"><img src="Graphics/SimpleLine.jpg" width="625" height="5" /></td>
</tr>
<tr><td height="23" colspan="4"><div align="center">
<table width="635" border="0" cellspacing="0" cellpadding="5">

<tr>

[code=php]

<?php }
echo($offset+1)."-".
($rowCounter+$offset)." of";
echo" $totalRows_rsVis records found matching".
" your criterian<br>";
if($offset>0)
echo "nt<a href="search_Visitor_Result.php"?offset=".rawurlencode($previousOffset).">Previous</a>";

else
echo "<br>Previous";

if(($row_rsVis !=false)&&($totalRows_rsVis >$nextOffset))

echo"nt<a href="search_Visitor_Result.php"?offset=".rawurlencode($nextOffset).">Next</a>";

else
echo " Next";

}
else
{
header("Location:search_Visitor_Result2.php");
exit;
}
echo"<br><br><a href="SearchVisit.htm">Back to Search</a><br>";

?> [/code]

<td><table width="625" height="43" border="0" cellpadding="0" cellspacing="0" background="Graphics/Bar.gif">

<tr align="center" valign="middle">

<td width="57"><a href="SearchVisit.htm">Model Search </a></td>

<td width="44">News</td>

<td width="59">New Models </td>

<td width="53">New Faces </td>

<td width="66">Feature Models</td>

<td width="55"><a href="Sorry3.php">Model's book</a></td>

<td width="68">Branding Guide </td>

<td width="66">Model's Guide </td>

<td width="104"><p><a href="register.php">Registration<br />

Forms &amp; Photos</a> </p>

</td>

<td width="53">Contact Us </td>

</tr>

</table></td>

</tr>

</table>

</div></td>

</tr>

<tr>

<td height="23" colspan="4"><div align="center">Modelbranding.com is a business division of CD Computer &amp; Development Ltda. and is an Internet News and Information Provider. The webcontents do not necessarily express the policies or opinion of the company or Modelbranding.com. The content is the exclusive responsibility of its author or creator. All rights reserved. </div></td>

</tr>

<tr>

<td height="46" colspan="4">&nbsp;</td>

</tr>

<tr valign="top">

<td height="406" colspan="4"><!-- TemplateBeginEditable name="KeyWords" --><!-- TemplateEndEditable --></td>

</tr>

</table></td>

</tr>

</table>

</div>


</body>

</html>

<?php

mysql_free_result($rsVis);

?>
Copy linkTweet thisAlerts:
@scragarJan 13.2005 — Parse error: parse error, unexpected '<' in /home/httpd/vhosts/accordweb.info/httpdocs/access_user/search_Visitor_Result.php on line 109

and now I'm getting:

Parse error: parse error, unexpected '}' in /home/httpd/vhosts/accordweb.info/httpdocs/access_user/search_Visitor_Result.php on line 224


search revealed some blank listings, you could just use an if to do nothing in this instance or find a way to doublecheck the database(run OPTIMISE tblName or FIX TABLE tblName and see if you get a similar error)

And in your code you need to be carefull, neglecting to add a name results in a Mysql error, WHERE clause expected.
Copy linkTweet thisAlerts:
@ashokvasauthorJan 13.2005 — Dear Scragar,

Sorry as I was trying out some modifications.Now the page is OK.Pls have a look.

Also I have changed the start of the query as per your suggestion as follows
[code=php]
$query_rsVis = "SELECT users.id, users.color_eyes, users.foto1, users.foto2, users.foto3, users.alias_name, users.meas_bres, users.meas_waist, users.meas_hip, users.height, users.cv1_date, users.cv1_title, users.cv1_contents FROM users WHERE 1";

if (isset($_POST['eye_color'])) {
$vareyecolor_rsVis = (get_magic_quotes_gpc()) ? $_POST['eye_color'] : addslashes($_POST['eye_color']);
}
if(isset($vareyecolor_rsVis) && $vareyecolor_rsVis !== ""){
$query_rsVis .= " AND color_eyes='$vareyecolor_rsVis'";
}.....................
[/code]


But I amgetting 6 results whereas I have only 2 records in my table.

Also could you tell me how to make the next/previous page links work.I seem to be stuck on that also.

Thanks

Ashokvas
Copy linkTweet thisAlerts:
@scragarJan 13.2005 — if you have MyPHPAdmin you should check out the database through that, alternativly just add DISTINCT to the query so it only returns one bad result then ignore it with an if around you search.

[code=php]for($rowCounter=0;
(($rowCounter<ROWS)&&

($row_rsVis = mysql_fetch_assoc($rsVis)));
$rowCounter++){
if($row_rsVis['foto1'] != ""){

//normal code(with HTML and stuff) here.

};};[/code]


as for the next buttons whats wrong with them? Do they not appear or just not work as you expect?
Copy linkTweet thisAlerts:
@ashokvasauthorJan 14.2005 — Thanks .There were extra blank records inthe table and that is why they were showing up.

The Next/previous buttons require some query string to be attached to the hyperlink on the next/previous buttons so that when you click on them ,you are taken to the next page.I am not clear what to do here.

Can you help me???

Ashokvas
Copy linkTweet thisAlerts:
@scragarJan 14.2005 — [code=php]
$request =array();
if(isset($_POST['eye_color'])){
$request = $_POST;
}else{
$request = $_GET;
};

// replace your reading $_POST for reading $request EG:

if (isset($request['eye_color'])) {
$vareyecolor_rsVis = (get_magic_quotes_gpc()) ? $_request['eye_color'] : addslashes($request['eye_color']);
};

// then provide your links to go like:
echo("<a href="?eye_color=".$request['eye_color']."&nextThing="$request['nextThing'].".....&page=$i">$i</a>");[/code]

Then just read in the number so you know where in the redords to skip to(although this isn't the best description you should be able to understand roughly what I mean right?)
Copy linkTweet thisAlerts:
@ashokvasauthorJan 14.2005 — Scragar wrote :

PHP:
--------------------------------------------------------------------------------



$request =array();

if(isset($_POST['eye_color'])){

$request = $_
POST;

}else{

$request = $_GET;

};
--------------------------------------------


I DO NOT UNDERSTAND WHY THIS IS REQUIRED?WHY ONLY if(isset($_POST['eye_color'])) then....

// replace your reading $_POST for reading $request EG:

if (isset($request['eye_color'])) {

$vareyecolor_rsVis = (get_magic_quotes_gpc()) ? $_request['eye_color'] : addslashes($request['eye_color']);

};


DOES THIS HAVE TOBE FOR ALL THE VARIABLES IN MY QUERY??

// then provide your links to go like:

echo("<a href="?eye_color=".$request['eye_color']."&nextThing="$request['nextThing'].".....&page=$i">$i</a>");


--------------------------------------------------------------------------------
WHAT ABOUT USING THIS FOR LINKS ON NEXT/PREVIOUS -WILL THIS WORK ON BOTH OR DO HAVE THEY HAVE TO BE DIFFERENT?THERE WILL BE A PREVIOUS OFFSET AND A NEXT OFFSET AS PER ME.


PLEASE LET ME KNOW

ASHOKVAS
Copy linkTweet thisAlerts:
@scragarJan 14.2005 — FIRST OF ALL TAKE OF CAPS LOCK.

I DO NOT UNDERSTAND WHY THIS IS REQUIRED?WHY ONLY if(isset($_POST['eye_color'])) then....[/quote]
eye_color was the first thing I saw in your form, essesntialy all you need is to check if the page was sent from a form(the main search) or a link(the next/previous buttons)

DOES THIS HAVE TOBE FOR ALL THE VARIABLES IN MY QUERY??[/quote]

All you need to do is replace every instance of $_POST with $request, not much if you copy it into word, use the find/replace thing then copy it back to your text editor(not a WYSIWYG editor!)

WHAT ABOUT USING THIS FOR LINKS ON NEXT/PREVIOUS -WILL THIS WORK ON BOTH OR DO HAVE THEY HAVE TO BE DIFFERENT?THERE WILL BE A PREVIOUS OFFSET AND A NEXT OFFSET AS PER ME.[/quote]
[code=php]
if(!isset($request['page'])){
$request['page'] = 1;
};
$request['page']--;
if($request['page'] != 0){
echo("<a href="?eye_color=".$request['eye_color']."&...&page=".($request['page'] - 1)."">previoust</a>");
};
if($request['page'] != $NumberOfPages){
echo("<a href="?eye_color=".$request['eye_color']."&...&page=".($request['page'] + 1)."">next</a>");
};
?>
[/code]
Copy linkTweet thisAlerts:
@ashokvasauthorJan 14.2005 — [i]Originally posted by scragar [/i]

[B][code=php]
$request =array();
if(isset($_POST['eye_color'])){
$request = $_POST;
}else{
$request = $_GET;
};

// replace your reading $_POST for reading $request EG:

if (isset($request['eye_color'])) {
$vareyecolor_rsVis = (get_magic_quotes_gpc()) ? $_request['eye_color'] : addslashes($request['eye_color']);
};

// then provide your links to go like:
echo("<a href="?eye_color=".$request['eye_color']."&nextThing="$request['nextThing'].".....&page=$i">$i</a>");[/code]

Then just read in the number so you know where in the redords to skip to(although this isn't the best description you should be able to understand roughly what I mean right?) [/B][/QUOTE]


Dear Scragar,

I donot understand why you are testing for POST(eye_color) being set and then proceeding.

Also the part

"if (isset($request['eye_color'])) {

$vareyecolor_rsVis = (get_magic_quotes_gpc()) ? $_request['eye_color'] : addslashes($request['eye_color']);

};

"

should be done for all the variables in the query.?

The links for Previous page and Next page will be same or different?They both have to go to different pages of the search result.

Have I understood you properly?
Copy linkTweet thisAlerts:
@ashokvasauthorJan 14.2005 — Sorry for the CAPS LOCKS.No offence meant.!!

Also sorry for psoting my reply again but I did not check page 2 where your reply was displayed.Please excuse me.I guess I should be more careful when I use this forum!!

I do not understand the 3 line of this code block ($request['page']--; )


"if(!isset($request['page'])){

$request['page'] = 1;

};

$request['page']--; ......"

Further I still amnot clear on the links to Next/Previous pages.

The search form is throwing up a large number of results and I want to display 25 records on each page.SoI have already set some variables like $offset,$previousOffset etc.Can you pls suggest how all of this should beput together.

Thanks

Ashokvas
Copy linkTweet thisAlerts:
@scragarJan 14.2005 — [code=php]if(!isset($request['page'])){ //if they have not provided a page no.
$request['page'] = 1; // set it to one.
}; //end if
$request['page']--; // deduct one from it's value so it starts at zero and not 1.

[/code]


The second part can wait till tommorow morning when I've not got college OK?
Copy linkTweet thisAlerts:
@ashokvasauthorJan 16.2005 — Dear Scragar,

I was able to get the Next/Previous buttons working and now the entire page works fine.

I must really thank you for all the tips and suggestions and I have shown the final script below.

It is slightly different from what you suggested ,but the basics are as per you

[code=php]
<?php require_once('Connections/dbconn.php'); ?>
<?php

$query_rsVis = "SELECT users.id, users.color_eyes, users.foto1, users.foto2, users.foto3, users.alias_name, users.meas_bres, users.meas_waist, users.meas_hip, users.height, users.cv1_date, users.cv1_title, users.cv1_contents FROM users WHERE 1";

$browseString="";
if (isset($_GET['eye_color'])) {
$vareyecolor_rsVis = (get_magic_quotes_gpc()) ? $_GET['eye_color'] : addslashes($_GET['eye_color']);
}
if(isset($vareyecolor_rsVis) && $vareyecolor_rsVis !== ""){
$query_rsVis .= " AND color_eyes='$vareyecolor_rsVis'";

$browseString.="eye_color=".rawurlencode($vareyecolor_rsVis)."&amp";
}

if (isset($_GET['brlo'])) {
$varbrlo_rsVis = (get_magic_quotes_gpc()) ? $_GET['brlo'] : addslashes($_GET['brlo']);
}
if(isset($varbrlo_rsVis) && $varbrlo_rsVis !== ""){
$query_rsVis .= " AND users.meas_bres>='$varbrlo_rsVis'";
$browseString.="brlo=".rawurlencode($varbrlo_rsVis)."&amp";
}


if (isset($_GET['brhi'])) {
$varbrhi_rsVis = (get_magic_quotes_gpc()) ? $_GET['brhi'] : addslashes($_GET['brhi']);
}
if(isset($varbrhi_rsVis) && $varbrhi_rsVis !== ""){
$query_rsVis .= " AND users.meas_bres<='$varbrhi_rsVis'";
$browseString.="brhi=".rawurlencode($varbrhi_rsVis)."&amp";
}



if (isset($_GET['wstlo'])) {
$varwstlo_rsVis = (get_magic_quotes_gpc()) ? $_GET['wstlo'] : addslashes($_GET['wstlo']);
}
if(isset($varwstlo_rsVis) && $varwstlo_rsVis !== ""){
$query_rsVis .= " AND users.meas_waist>='$varwstlo_rsVis'";
$browseString.="wstlo=".rawurlencode($varwstlo_rsVis)."&amp";
}

if (isset($_GET['wsthi'])) {
$varwsthi_rsVis = (get_magic_quotes_gpc()) ? $_GET['wsthi'] : addslashes($_GET['wsthi']);
}
if(isset($varwsthi_rsVis) && $varwsthi_rsVis !== ""){
$query_rsVis .= " AND users.meas_waist<='$varwsthi_rsVis'";
$browseString.="wsthi=".rawurlencode($varwsthi_rsVis)."&amp";
}


if (isset($_GET['hiplo'])) {
$varhiplo_rsVis = (get_magic_quotes_gpc()) ? $_GET['hiplo'] : addslashes($_GET['hiplo']);
}
if(isset($varhiplo_rsVis) && $varhiplo_rsVis !== ""){
$query_rsVis .= " AND users.meas_hip>='$varhiplo_rsVis'";
$browseString.="hiplo=".rawurlencode($varhiplo_rsVis)."&amp";
}

if (isset($_GET['hiphi'])) {
$varhiphi_rsVis = (get_magic_quotes_gpc()) ? $_GET['hiphi'] : addslashes($_GET['hiphi']);
}
if(isset($varhiphi_rsVis) && $varhiphi_rsVis !== ""){
$query_rsVis .= " AND users.meas_hip<='$varhiphi_rsVis'";
$browseString.="hiphi=".rawurlencode($varhiphi_rsVis)."&amp";
}


if (isset($_GET['htlo'])) {
$varhtlo_rsVis = (get_magic_quotes_gpc()) ? $_GET['htlo'] : addslashes($_GET['htlo']);
}
if(isset($varhtlo_rsVis) && $varhtlo_rsVis !== ""){
$query_rsVis .= " AND users.height >='$varhtlo_rsVis'";
$browseString.="htlo=".rawurlencode($varhtlo_rsVis)."&amp";
}
if (isset($_GET['hthi'])) {
$varhthi_rsVis = (get_magic_quotes_gpc()) ? $_GET['hthi'] : addslashes($_GET['hthi']);
}
if(isset($varhthi_rsVis) && $varhthi_rsVis !== ""){
$query_rsVis .= " AND users.height <='$varhthi_rsVis'";
$browseString.="hthi=".rawurlencode($varhthi_rsVis)."&amp";
}

if (isset($_GET['hair_color'])) {
$varhcolor_rsVis = (get_magic_quotes_gpc()) ? $_GET['hair_color'] : addslashes($_GET['hair_color']);
}
if(isset($varhcolor_rsVis) && $varhcolor_rsVis !== ""){
$query_rsVis .= " AND users.hair_color='$varhcolor_rsVis'";
$browseString.="hair_color=".rawurlencode($varhcolor_rsVis)."&amp";
}

if (isset($_GET['w_area'])) {
$varwarea_rsVis = (get_magic_quotes_gpc()) ? $_GET['w_area'] : addslashes($_GET['w_area']);
}
if(isset($varwarea_rsVis) && $varwarea_rsVis !== ""){
$query_rsVis .= " AND users.w_area='$varwarea_rsVis'";
$browseString.="w_area=".rawurlencode($varwarea_rsVis);
}
if(empty($offset))
$offset=0;
define(ROWS,4);


mysql_select_db($database_dbconn, $dbconn);
$scriptName="search_Visitor_Result.php";




$rsVis = mysql_query($query_rsVis, $dbconn) or die(mysql_error());

$totalRows_rsVis = mysql_num_rows($rsVis);


?><?php
if ($totalRows_rsVis != 0)
{
$previousOffset=$offset-ROWS;

$nextOffset=$offset+ROWS;

if(!mysql_data_seek($rsVis,$offset))
echo "Error seeking data";?>

[/code]

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<link rel="stylesheet" href="style.css" type="text/css">

<html>

<head>

<title>Untitled Document</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

</head>

<body background="Graphics/page-bg.jpg" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">

<table width="789" border="0" align="center" cellpadding="0" cellspacing="0">

<tr>

<td><img src="Graphics/topbanner2.jpg" width="789" height="135"></td>

</tr>

</table>

<table width="789" border="0" align="center" cellpadding="0" cellspacing="0">

<tr>

<td><img src="Graphics/topnav.jpg" width="789" height="51"></td>

</tr>

</table>

<table width="789" border="0" align="center" cellpadding="0" cellspacing="0">

<tr>

<td><img src="Graphics/tabletop2.jpg" width="789" height="47"></td>

</tr>

</table>

<table width="789" border="0" align="center" cellpadding="0" cellspacing="0" background="Graphics/tablebg2.jpg">

<tr>

<td align="center"><form name="form1" method="get" action="search_Visitor_Result.php">

<div align="center">

<table width="670" border="0" cellpadding="10" cellspacing="0">

<tr>

<td width="657" valign="top">

<table width="635" height="825" border="0" cellpadding="5" cellspacing="0" class="black11px">

<tr>

<td colspan="4"><p>&nbsp;</p>

</td>

</tr>

[code=php]
<?php
for($rowCounter=0;
(($rowCounter<ROWS)&&

($row_rsVis = mysql_fetch_assoc($rsVis)));
$rowCounter++){ ?>[/code]

<tr>

<td valign="top"><a href="ModelStatsVisit.php?id=<?php echo $row_rsVis['id'];?>">Stats</a></td>

<td align="left" valign="top">&nbsp;

<td valign="top"><a href="Sorry3.php">Curriculum</a></td>

<td valign="top"><a href="Sorry3.php">Book</a></td>

</tr>

<tr>

<td width="76" height="119" valign="top"><img src="thumbs/<?php echo $row_rsVis['foto1']; ?>" width="73" height="100" border="0" /></td>

<td width="367" align="left" valign="top"><h5> <?php echo $row_rsVis['alias_name']; ?></h5>

<p>Height:<?php echo $row_rsVis['height']; ?> cm, Measures:<?php echo $row_rsVis['meas_bres']; ?>-<?php echo $row_rsVis['meas_waist']; ?>-<?php echo $row_rsVis['meas_hip']; ?>.

Latest assignment: (CV1Date) <strong><?php echo $row_rsVis['cv1_date']; ?>, </strong>(CV1

Title) <strong><?php echo $row_rsVis['cv1_title']; ?></strong>,

(CV1 Text)<font class="normal">:<a href="Sorry3.php">For more

information &gt;&gt;&gt;</a>.</font>

<p>&nbsp;

<td width="86" align="center" valign="top"><img src="thumbs/<?php echo $row_rsVis['foto2']; ?>" width="72" height="100" border="0" /></td>

<td width="75" align="center" valign="top"><img src="thumbs/<?php echo $row_rsVis['foto3']; ?>" width="72" height="100" /></td>

</tr>

<tr>

<td height="23" colspan="4"><table width="100%" border="0" cellpadding="0" cellspacing="0" background="Graphics/bar.jpg">

<tr>

<td>&nbsp;</td>

</tr>

</table></td>

</tr>

<tr>

<td height="23" colspan="4"><div align="center">

<table width="635" border="0" cellspacing="0" cellpadding="5">

<tr>
[code=php]
<?php }
echo($offset+1)."-".
($rowCounter+$offset)." of";
echo" $totalRows_rsVis records found matching".
" your criterian<br>";
if($offset>0)
echo "nt<a href="".$scriptName."?offset=".rawurlencode($previousOffset)."&amp;".$browseString."">Previous</a>";

else
echo "<br>Previous";

if(($row_rsVis !=false)&&($totalRows_rsVis >$nextOffset))

echo"nt<a href="".$scriptName."?offset=".rawurlencode($nextOffset)."&amp;".$browseString."">Next</a>";

else
echo " Next";

}
else
{
header("Location:search_Visitor_Result2.php");
exit;
}
echo"<br><br><a href="SearchVisit.htm">Back to Search</a><br>";

?>[/code]



Thanks very very much

Ashokvas
×

Success!

Help @ashokvas spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...