943,866 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 2507
  • PHP RSS
Jul 2nd, 2004
0

search and results problem

Expand Post »
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:&nbsp;
<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>
&nbsp;&nbsp;
<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>
&nbsp;&nbsp;

<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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
charter is offline Offline
11 posts
since Jun 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: PHP Feezing with a function
Next Thread in PHP Forum Timeline: php error when using invision board





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC