How do a populate a drop down menu from a database without repeating the data? - sql

I am trying to create a search field that is a dynamically populated drop down menu. The code to query the database and populate the menu is as follows:
<form action="<?=$SERVER['PHP_SELF'];?>" method="post" name="nameSearch">
<label for="nameMenu">
<p>Choose a name from the drop down menu<br />
to retrieve all the data for that person.</p>
</label>
<select name="dateMenu" id="dateMenu">
<option value="0" selected="selected">Choose a name</option>
<?php
$sql_search = 'SELECT id, name from $tbl_name';
$query_search = mysql_query($sql_search);
while($row = mysql_fetch_array($query_search))
{
echo '<option value=' . $row['id'] . '>' . $row['name'] . '</option>';
}
?>
</select>
<input type="submit" name="searchName" value="Find">
</form>
The problem is that because the database holds information that causes it to store the same name repeatedly I get the same name listed as an option in my drop down menu.
The DB looks like so:
----------------------------------------------------------
| id | name | uniqueImage | date | time |
----------------------------------------------------------
| 1 | John | uniqueImage001.png | 2011-03-11 | 14:21:20 |
| 2 | James| uniqueImage002.png | 2011-03-11 | 14:24:30 |
| 3 | Joe | uniqueImage003.png | 2011-03-11 | 14:26:10 |
| 4 | John | uniqueImage004.png | 2011-03-11 | 14:40:10 |
| 5 | Joe | uniqueImage005.png | 2011-03-11 | 14:56:32 |
| 6 | Joe | uniqueImage006.png | 2011-03-11 | 15:02:50 |
| 7 | James| uniqueImage007.png | 2011-03-11 | 15:21:25 |
| 8 | John | uniqueImage008.png | 2011-03-11 | 15:26:30 |
----------------------------------------------------------
and the menu options returned look like so:
<option value="1">John</option>
<option value="2">James</option>
<option value="3">Joe</option>
<option value="4">John</option>
<option value="5">Joe</option>
<option value="6">Joe</option>
<option value="7">James</option>
<option value="8">John</option>
What I need is for the drop down menu to be more like this:
<option value="1">John</option>
<option value="2">James</option>
<option value="3">Joe</option>
This way I can get all of the unique images associated with a particular user. I don't need every name in the DB returned in my query, simply each name only one time. I am thinking I may need to set up a relational DB scheme, but I am trying to avoid this. Is there any other way to set this up? Thanks.

Change your SQL to SELECT DISTINCT id, name from $tbl_name

Change your database call to be:
SELECT id, name from $tbl_name group by id, name

Related

How to create column for selected parameter?

I have this query that pulls results based on the selected LOV parameter: nvl(:Role, role))
SELECT role,subject
FROM HS_SUBJECT_INCIDENTS
WHERE entitlement not in(select entitlement from HS_SUBJECT_INCIDENTS where role in nvl(:Role, role))
AND subject in (select subject from HS_SUBJECT_INCIDENTS where role in nvl(:Role, role))
So if the user selected 'Finance' for the parameter value, the results now show:
| Role | Subject |
------------------------
| Marketing | Business |
| Marketing | Business |
| Analytics | Business |
I want the results to show like this:
| Role | Subject | SelectedParameter |
--------------------------------------------
| Marketing | Business | Finance |
| Marketing | Business | Finance |
| Analytics | Business | Finance |
What do I have to put in the select statement to include a column for the parameter value that was selected?
Just select it:
SELECT role, subject, :Role as SelectedParameter
FROM . . .

Unable to select option with Selenium IDE

I can't select an option with Selenium IDE on my system:
Mac High Sierra
Firefox 52
Selenium IDE 2.9.1
(I know its old, but (normally) it works and I can't change it!
The select option has the following values:
<select name="t2_neurol_mot_l_t1" id="t2_neurol_mot_l_t1">
<option value="">Please select</option>
<option value="1">0</option>
<option value="2">0!</option>
<option value="3">1</option>
<option value="4">1!</option>
<option value="5">2</option>
<option value="6">2!</option>
<option value="7" selected="">3</option>
<option value="8">3!</option>
<option value="9">4</option>
<option value="10">4!</option>
<option value="11">5</option>
<option value="12">5*</option>
<option value="13">NT</option>
<option value="14">NT!</option>
<option value="15">NT*</option>
</select>
I need to select the last option NT* with value 15
All of these Commands don't seem to work correctly:
| Command | Target | Value |
| select | id=t2_neurol_mot_l_t1 | label=NT* |
| Command | Target | Value |
| select | id=t2_neurol_mot_l_t1 | NT* |
| Command | Target | Value |
| sendKeys | id=t2_neurol_mot_l_t1 | NT* |
| Command | Target | Value |
| keyDown | id=t2_neurol_mot_l_t1 | NT* |
| Command | Target | Value |
| clickAt | css=select[name=drpReason] option[value=Other] | |
The problem is the command select only selects NT, but not NT*
What would works is:
| Command | Target | Value |
| select | id=t2_neurol_mot_l_t1 | value=15 |
BUT, I dont have the value, so this option is not possible. I need to selected it with the label...
Any ideas? Could it be a problem of entities, since i can't select NT*, but NT! works...
You can try it on this page:
https://www.saccadic-training.com/is_test.html
Best regards
Beat
As * is used as regex criteria, it is not working. I tried with escape for *, it also didn't work.
But we can select NT* with xpath using click command,
| Command | Target | Value |
| click | xpath=//option[text()='NT*']| |
for the records, #Navarasu answers worked for me.
I couldn't select an option from my <select> tag -IDE error was that is was not a select element...)
I achieved filling my select with desired option like this :
**command :** click /// **target :** xpath=xpath_of_my_select
**command :** click /// **target :** xpath=//option[text()='**Foobar**']
any another command so that focus changes
NB : Foobar should be the desired option text value displayed on browser (not the "value" attribute in code if different)
NB : Might not work so well if there are 2 <select> elements

Better way to remove HTML tags in Oracle SQL

I have a comments column and the comments added to release are stored as rich text in comments column. Now i'm trying to process this data and get an human readable output. I'm providing 2 sample comment data i have in my oracle SQL db which i'm trying to process.
Example 1 :
<html>
<body>
<div align="left"><font face="Arial Unicode MS"><span style="font-size:8pt">Display the frulog on the count values</span></font></div>
</body>
</html>
Example 2: <not implemented in this release>
i used the below query to process the html characters
Select (REGEXP_REPLACE(comments),'<.+?>') from test_table;
Note: consider values provided in Example 1 and Example 2 are passed in as column comments in the above SQL command.
the query result for Example 1 was Display the frulog on the count values which is what i'm expecting. result for Example 2 was ''. Value in Example 2 was not an html tag but it still replaced the tags. How can i make the replace statement smart.
Feel free to drop your suggestions .
SQL Fiddle
Oracle 11g R2 Schema Setup:
CREATE TABLE comments ( value ) AS
SELECT '<html>
<body>
<div align="left">
<font face="Arial Unicode MS">
<span style="font-size:8pt">
Display the frulog on the count values
</span>
</font>
</div>
</body>
</html>' FROM DUAL UNION ALL
SELECT '<not implemented in this release>' FROM DUAL UNION ALL
SELECT '<test a="1"
b=''2''
c = 3
d
e = ">" >test</test>' FROM DUAL;
Query 1:
SELECT value,
REGEXP_REPLACE(
value,
'\s*</?\w+((\s+\w+(\s*=\s*(".*?"|''.*?''|[^''">\s]+))?)+\s*|\s*)/?>\s*',
NULL,
1,
0,
'im'
) AS replaced
FROM comments
Results:
| VALUE | REPLACED |
|------------------------------------------|----------------------------------------|
| <html> | Display the frulog on the count values |
| <body> | |
| <div align="left"> | |
| <font face="Arial Unicode MS"> | |
| <span style="font-size:8pt"> | |
| Display the frulog on the count values | |
| </span> | |
| </font> | |
| </div> | |
| </body> | |
| </html> | |
|------------------------------------------|----------------------------------------|
| <not implemented in this release> | (null) |
|------------------------------------------|----------------------------------------|
| <test a="1" | test |
| b='2' | |
| c = 3 | |
| d | |
| e = ">" >test</test> | |
Note: <not implemented in this release> is a valid HTML custom element with tag name not and attributes implemented, in, this and release.
If you only want to replace specific HTML elements then list them at the start of the regular expression:
\s*</?(a|abbr|acronym|address|applet|area|article|aside|audio|b|base|basefont|bdi|bdo|bgsound|big|blink|blockquote|body|br|button|canvas|caption|center|cite|code|col|colgroup|command|content|data|datalist|dd|del|details|dfn|dialog|dir|div|dl|dt|element|em|embed|fieldset|figcaption|figure|font|footer|form|frame|frameset|h1|head|header|hgroup|hr|html|i|iframe|image|img|input|ins|isindex|kbd|keygen|label|legend|li|link|listing|main|map|mark|marquee|menu|menuitem|meta|meter|multicol|nav|nextid|nobr|noembed|noframes|noscript|object|ol|optgroup|option|output|p|param|picture|plaintext|pre|progress|q|rp|rt|rtc|ruby|s|samp|script|section|select|shadow|slot|small|source|spacer|span|strike|strong|style|sub|summary|sup|table|tbody|td|template|textarea|tfoot|th|thead|time|title|tr|track|tt|u|ul|var|video|wbr|xmp)((\s+\w+(\s*=\s*(".*?"|''.*?''|[^''">\s]+))?)+\s*|\s*)/?>\s*

Nested examples in cucumber scenario outline - List or Map values

I have recently seen a cucumber scenario outline like this.
sorry for my bad example below. But the format is in this way.
I really wonder if this type of format is supported by cucumber?
The nested Data tables. Has any one used this type of nested Data table?
If yes is this the below format?
Scenario Outline: Hello World
Given I am logged in as <user>
When I search for <searchTerm>
Then I add the following to my basket:
| <item1> |teapot|
| <item2> |Yorkshire tea|
Examples:
| user | searchTerm |
| Adam | Tea |
Can i make a data table like above
That's not quite how they work.
The nested data tables are used by the step that the table is joined to. It's usually used to do multiple of the same thing, using the data table on the inside as an array. This can include headers, or no headers - depending on how you have written your step. Remember - it's all about communication.
As an example:
Scenario Outline: Hello World
Given I am logged in as <user>
When I search for <searchTerm>
Then I add the following to my basket:
| <item1> |
| <item2> |
Examples:
| user | searchTerm | item1 | item2 |
| Adam | Tea | teapot | Yorkshire tea |
Updated Answer!!
As #kayle mentioned in his answer.. You can write following test scenario's
Scenario Outline: Hello World
Given I am logged in as <user>
When I search for <searchTerm>
Then I add the following to my basket:
| Teapot |
| Yorkshire tea |
Examples:
| user | searchTerm |
| Adam | Tea |
or
Scenario Outline: Hello World
Given I am logged in as <user>
When I search for <searchTerm>
Then I add the following to my basket:
| <item1> |
| <item2> |
Examples:
| user | searchTerm | item1 | item2 |
| Adam | Tea | Teapot| Yorkshire tea|
the second scenario will be useful if you want to add different items for each user. for example:
Scenario Outline: Hello World
Given I am logged in as <user>
When I search for <searchTerm>
Then I add the following to my basket:
| <item1> |
| <item2> |
Examples:
| user | searchTerm | item1 | item2 |
| Adam | Tea | Yorkshire tea | Teapot |
| Tom | Books | book1 | book2 |
Hope it's clear!!

How can I filter by tags in my search?

I have no clue what I'm doing with SOLR so I have so far been able to get by doing simple things and I've been able to get by doing joins in SQL.
I have a table buysellitems which has a lot of fields in it like
+-----------+-------+-------------------+
| buysellid | price | buysellname |
+-----------+-------+-------------------+
| 3558 | 140 | Multi Layer |
| 3561 | 175 | form |
| 3562 | 160 | Floral |
| 3563 | 199 | Specks |
| 3564 | 385 | Ruby Red |
| 3565 | 160 | B&W |
| 3567 | 175 | Pattern |
| 3569 | 125 | Fairy Floss Tunic |
| 3570 | 185 | Brandy Dress |
| 3571 | 85 | Anissa |
+-----------+-------+-------------------+
so I have something like
<entity name="item" id="BuySellID" query="SELECT
i.BuySellID, i.BuySellName, i.Price, ...">
<field name="buysellid" column="buysellid" />
<field name="BuySellName" column="BuySellName" />
<field name="price" column="price" />
...
</entity>
So I have an easy time searching for items by name, I can filter by price, etc.
But users can also specify tags for their items in the buysellitemfeatures table which looks like this:
+-----------+-------------+--------------+
| buysellid | featurename | featurevalue |
+-----------+-------------+--------------+
| 3860 | color | red |
| 3860 | color | white |
| 3861 | tag | leather |
| 3861 | tag | natural |
| 3861 | color | black |
| 3861 | color | pink |
| 3862 | tag | clothing |
| 3862 | color | black |
| 3862 | color | pink |
| 3863 | color | black |
| 3863 | color | pink |
| 3872 | color | black |
| 3872 | color | white |
| 3873 | color | black |
| 3873 | color | white |
| 3874 | color | black |
| 3874 | color | white |
+-----------+-------------+--------------+
How can I filter the search results (which are items) to give items that have "leather" in the tags table even if it's not found in the name? Note that there are several columns for each item, and I'd like to also filter by color as well.
How should I import my data, and how would I query for things like:
Search for leather and display items that either have this tag or have it in its name
Search for the same thing, but filter by the color black (items can have several prominent colors as well)
Thank you for your help.
Keep multi-valued fields for color and tag in your schema.xml. (See What is the use of "multiValued" field type in Solr?). Let's call these fields as s_color and s_tag. Also change the field name for BuySellName to s_BuySellName. (We will see why we keep the s_ prefix in a moment.)
Then in your data-config.xml use sub-entities to get and index the values for these fields:
<entity name="item"
id="BuySellID"
query="SELECT i.BuySellID, i.BuySellName AS s_BuySellName, i.Price, ...">
<entity name="color" query="SELECT featurevalue AS s_color FROM buysellitemfeatures WHERE featurename='color' AND buysellid='${item.BuySellID}'"/>
<entity name="tag" query="SELECT featurevalue AS s_tag FROM buysellitemfeatures WHERE featurename='tag' AND buysellid='${item.BuySellID}'"/>
Now in your schema.xml, you can keep a catch-all text copyField which stores the content of s_BuySellName, s_color and s_tag like:
<copyField source="s_*" dest="catchall"/>
If you search catchall like q=catchall:brown leather bag then it will search name, colors and tags.
Another nice option for you to consider would be faceting. If a user searches for bag then you can show facets for color and tag to drill down.
I have also only recently begun to write SQL operations. Like you, I've wondered how to filter out a large list of GUI options by tags so that a user would be presented only with options that were actually important to him.
Making the tags is easy, but not trivial. You have to come up with an organization of tags that makes sense for your needs.
Filtering involves attaching tags to three entities:
a target entity (say, a user)
a source entity (say, a database record)
a filtration criterion (criteria attached to a GUI control)
Conceptually, filtering is performed easily by performing an SQL INTERSECTION or UNION (or whichever set operation makes the best sense) on the two groups of tags. When the target and the source have all the tags in common with the criteria, that should identify records to display.
BTW, you can attach tags to any records of any database at any time. You can make a database table of tags, and then link any number of tags to the required database rows by using a many-to-many relationship via a bridge table between the database table and the tags table.
I think I'm on the right track. Others are certain to be more authoritative than I am on this, but this is what I've come up with on my own so far.