| | |
search and results problem
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jun 2004
Posts: 11
Reputation:
Solved Threads: 0
Can any of the gurus out there please help?
I am having a search problem with PHP and MySQL.
I wish to search the MySql database from 2 criteria.
Using 2 dropdown boxes.
I wish to search from 1 dropdown box called searchtype and another called searchterm. The problem is I cannot get them to work do a proper search.
I can get it to work using just one search criteria but I want the result to be of both criteria being true.
This is the form code for the search:
<form action="resultsus50a.php" method="post">
<p>Search:
<select name="searchtype">
<option value="year">2000</option>
<option value="year">2001</option>
<option value="year">2002</option>
<option value="year">2003</option>
<option value="year">2004</option>
</select>
<p>
<select name="searchterm">
<option value="wk no.">1</option>
<option value="wk no.">2</option>
<option value="wk no.">3</option>
<option value="wk no.">4</option>
<option value="wk no.">5</option>
</select>
<INPUT type=image src="search.gif" value="Search">
</form>
This is the code for the results page:
<?php
// create short variable names
if(ini_get('register_globals') != "1")
{
$post = (floatval(substr(phpversion(), 0, 3)) >= 4.1) ? $_POST : $HTTP_POST_VARS;
foreach($post as $key => $value)
{
$$key = $value;
}
}
$searchtype = addslashes(trim($searchtype));
$searchterm = addslashes(trim($searchterm));
if(!$searchtype || !$searchterm)
{
exit('You have not entered search details. Please go back and try again.');
}
$link_id = @mysql_connect("localhost", "root", "password");
if($link_id === false)
{
exit("Error, Could not connect to the system database. Sorry...");
}
mysql_select_db('charts50', $link_id);
$result = mysql_query("SELECT * FROM `usa` WHERE `{$searchtype}` LIKE '%{$searchterm}` LIKE %'");
?>
</head>
<body background="images/ground.jpg">
<div align="center">
<table class="table" width="760" height="266" border="0" cellpadding="5" cellspacing="0">
<tr>
<td valign="top"><div align="center"><img src="dateImages/we54-31.gif"></div></td>
</tr>
<tr>
<td height="29" class="years-ago">50 YEARS AGO</td>
</tr>
<tr align="left">
<td height="29" colspan="2" class="years-ago">
<table width="100%" border="0" cellspacing="0" cellpadding="1">
<tr class="headings">
<tr>
<th class="headings" width="28">TW</th>
<th class="headings" width="53">LW</th>
<th class="headings" width="28">Wks</th>
<th class="headings" width="340">Title</th>
<th class="headings" width="307">Artist</th>
</tr>
<?php $i = 1; while($row = mysql_fetch_array($result)){
$item = array();
$item['tw'] = stripslashes($row['tw']);
$item['lw'] = stripslashes($row['lw']);
// now we can override that
$item['lw'] = ($item['lw']=='new')
? "<img src=\"images/new2.gif\" alt=\"new!\" />"
: $item['lw'];
$item['wks'] = stripslashes($row['wks']);
$item['title'] = strtoupper(stripslashes($row['title']));
$item['artist'] = stripslashes($row['artist']);
?>
<tr>
<td width="28" class="tw"><?php echo $item['tw']; ?></td>
<td width="53" class="lw"><?php echo $item['lw']; ?></td>
<td width="28" class="wks"><?php echo $item['wks']; ?></td>
<td width="340" class="title"><?php echo $item['title']; ?></td>
<td width="307" class="artist"><?php echo $item['artist']; ?></td>
</tr>
<?php $i++; } ?>
I want the results to be true of both searchtype and searchterm.
If someone could please help by amending the correct code or tell me what I should amend on either the search form or the results code or both. That is true to year and wk no.
I have put 'password' just for this post.
All help is very much appreciated.
I am having a search problem with PHP and MySQL.
I wish to search the MySql database from 2 criteria.
Using 2 dropdown boxes.
I wish to search from 1 dropdown box called searchtype and another called searchterm. The problem is I cannot get them to work do a proper search.
I can get it to work using just one search criteria but I want the result to be of both criteria being true.
This is the form code for the search:
<form action="resultsus50a.php" method="post">
<p>Search:
<select name="searchtype">
<option value="year">2000</option>
<option value="year">2001</option>
<option value="year">2002</option>
<option value="year">2003</option>
<option value="year">2004</option>
</select>
<p>
<select name="searchterm">
<option value="wk no.">1</option>
<option value="wk no.">2</option>
<option value="wk no.">3</option>
<option value="wk no.">4</option>
<option value="wk no.">5</option>
</select>
<INPUT type=image src="search.gif" value="Search">
</form>
This is the code for the results page:
<?php
// create short variable names
if(ini_get('register_globals') != "1")
{
$post = (floatval(substr(phpversion(), 0, 3)) >= 4.1) ? $_POST : $HTTP_POST_VARS;
foreach($post as $key => $value)
{
$$key = $value;
}
}
$searchtype = addslashes(trim($searchtype));
$searchterm = addslashes(trim($searchterm));
if(!$searchtype || !$searchterm)
{
exit('You have not entered search details. Please go back and try again.');
}
$link_id = @mysql_connect("localhost", "root", "password");
if($link_id === false)
{
exit("Error, Could not connect to the system database. Sorry...");
}
mysql_select_db('charts50', $link_id);
$result = mysql_query("SELECT * FROM `usa` WHERE `{$searchtype}` LIKE '%{$searchterm}` LIKE %'");
?>
</head>
<body background="images/ground.jpg">
<div align="center">
<table class="table" width="760" height="266" border="0" cellpadding="5" cellspacing="0">
<tr>
<td valign="top"><div align="center"><img src="dateImages/we54-31.gif"></div></td>
</tr>
<tr>
<td height="29" class="years-ago">50 YEARS AGO</td>
</tr>
<tr align="left">
<td height="29" colspan="2" class="years-ago">
<table width="100%" border="0" cellspacing="0" cellpadding="1">
<tr class="headings">
<tr>
<th class="headings" width="28">TW</th>
<th class="headings" width="53">LW</th>
<th class="headings" width="28">Wks</th>
<th class="headings" width="340">Title</th>
<th class="headings" width="307">Artist</th>
</tr>
<?php $i = 1; while($row = mysql_fetch_array($result)){
$item = array();
$item['tw'] = stripslashes($row['tw']);
$item['lw'] = stripslashes($row['lw']);
// now we can override that
$item['lw'] = ($item['lw']=='new')
? "<img src=\"images/new2.gif\" alt=\"new!\" />"
: $item['lw'];
$item['wks'] = stripslashes($row['wks']);
$item['title'] = strtoupper(stripslashes($row['title']));
$item['artist'] = stripslashes($row['artist']);
?>
<tr>
<td width="28" class="tw"><?php echo $item['tw']; ?></td>
<td width="53" class="lw"><?php echo $item['lw']; ?></td>
<td width="28" class="wks"><?php echo $item['wks']; ?></td>
<td width="340" class="title"><?php echo $item['title']; ?></td>
<td width="307" class="artist"><?php echo $item['artist']; ?></td>
</tr>
<?php $i++; } ?>
I want the results to be true of both searchtype and searchterm.
If someone could please help by amending the correct code or tell me what I should amend on either the search form or the results code or both. That is true to year and wk no.
I have put 'password' just for this post.
All help is very much appreciated.
Last edited by charter; Jul 2nd, 2004 at 5:43 pm. Reason: typo error
![]() |
Similar Threads
- How can we do the Pagination of Search Results. (PHP)
- highlighting search results in a gridview problem (ASP.NET)
- My search results are being hijacked: IE and FF (Viruses, Spyware and other Nasties)
- Google search results redirecting me to random sites [btcar mostly] (Viruses, Spyware and other Nasties)
- IE Explorer/Search Engine problems! (fake/redirect search results) (Viruses, Spyware and other Nasties)
- IE Search results being hijacked (Viruses, Spyware and other Nasties)
- Navigate back to Search Results (ColdFusion)
- Search Results not displayed in Firefox/Safari (VB.NET)
- PHP Search pagination problem (PHP)
Other Threads in the PHP Forum
- Previous Thread: PHP Feezing with a function
- Next Thread: php error when using invision board
| Thread Tools | Search this Thread |
apache api array autocomplete beginner binary broken cakephp checkbox class cms code cookies cron curl data database dataentry date display dropdownlist duplicates dynamic echo email error execution file files firstoptioninphpdroplist folder form forms freelancing function functions google href htaccess html htmlspecialchars image include includingmysecondfileinthechain insert ip javascript joomla jquery js limit link links login mail menu mlm multiple mysql oop paypal pdf pdfdownload php phpvotingscript query radio random regex remote screen script search server session sessions sorting source space sql stored subscription syntax system table tag traffic tutorial tutorials update upload url validator variable video volume web white youtube zend





