Forum Moderators: coopster

Message Too Old, No Replies

Problem with advanced search in phpclassifieds

Drop down menu options appear to have a line break

         

travelbuff

9:43 pm on Aug 22, 2003 (gmt 0)

10+ Year Member



Hello php wizards:

I am having a problem with searching custom fields in deltascripts php classifieds.

When field type is defined as a drop-down menu, I can get the options, which are stored in a .txt file to display on the search page, but the search always turns up empty.

Here is the code for the search field:

==============
if ($varname<>"custom_field_1")
{
print("<tr>");
print("<td width=\"50%\" valign=\"top\"> $ad_caption </td>");
print("<td width=\"50%\" valign=\"top\">");
print("<input type=\"text\" name=\"$varname\" size=\"$fieldsize\" class='txt' value=\"$value\" />");
print("</td>");
print("</tr>");
}
if ($varname == "custom_field_1")
{
$options = file("options/locations.txt");
$num_options = count($options);
print("<tr>");
print("<td width=\"50%\" valign=\"top\"> $ad_caption </td>");
print("<td width=\"50%\" valign=\"top\">");
print "<select size='1' name='$varname'>";
print "<option selected>$options[$i]";
for ($i=0; $i<$num_options; $i++)
{
print "<option value='$options[$i]' ";
print ">$options[$i]</option>";
}
print "</select>&nbsp;&nbsp;&nbsp;";
==============

I did a view source on the search page output and it looks like this:

==============
<select size='1' name='custom_field_1'><option selected><option value='az
' >az
</option><option value='ar
' >ar
</option><option value='ak
' >ak
</option><option value='tx
' >tx
</option></select>
===============

So I figured that since the txt file uses line breaks between options, that was tripping up the search, so I tried to trim the break:

===============
$options1 = trim($options, " \n. " );
for ($i=0; $i<$num_options; $i++)
{
print "<option value='$options1[$i]' ";
print ">$options1[$i]</option>";
}
===============

but then the options in the dropdown just vertically spelled ARRAY.

Any thoughts? Am I even on the right track? I am a php newbie so please be gentle w/me :)

Should I post the whole contents of search.php (400 lines)?

Thanks for your help!

jatar_k

6:32 pm on Aug 23, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Should I post the whole contents of search.php (400 lines)?

uh, no thank you

it sounds more like the actual script is not getting the value from the drop down. Does it know to look for 'custom_field_1' which happens to be the varname for the value from the dropdown?

travelbuff

4:46 am on Aug 24, 2003 (gmt 0)

10+ Year Member



Yes, the script will search just fine if the searchbox is just a textfield rather than a dropdown.

Birdman

1:55 pm on Aug 24, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



travelbluff,

The problem could stem from these two lines:


print "<option value='$options[$i]' ";
print ">$options[$i]</option>";

There are a few ways to print to a web page, but I suggest you stick with one method, just to keep it organized.

Here is a nice method, called heredoc [php.net], where you don't need to escape quotes:


if ($varname<>"custom_field_1")
{
print <<<HTML
<tr>
<td width="50%" valign="top"> $ad_caption </td>
<td width="50%" valign="top">
<input type="text" name="$varname" size="$fieldsize" class="txt" value="$value" />
</td>
</tr>
HTML;
}
if ($varname == "custom_field_1")
{
$options = file("options/locations.txt");
$num_options = count($options);
print <<<HTML
<tr>
<td width="50%" valign="top"> $ad_caption </td>
<td width="50%" valign="top">
<select size="1" name="$varname">
<option selected>$options[$i]</option>
HTML;
for ($i=0; $i<$num_options; $i++)
{
print "<option value=\"$options[$i]\">$options[$i]</option>";
}
print "</select>&nbsp;&nbsp;&nbsp;";

Also, you never closed the first <option selected> tag in your original.

Hopefully, that will get you going in the right direction.

Birdman