1
xgarb
Bit of a toughie - database column into select field - Solved!
  • 2003/10/24 17:11

  • xgarb

  • Not too shy to talk

  • Posts: 154

  • Since: 2003/3/30


Hi all,

I'm in xoopsmembers/index.php, changing some of the search choices in the form. I want one of them to be a pull down that is populated from the user table (it's a country list) rather than populated from xoopslists.

This is so members can only search countries where there are actually members, rather than pulling the whole country list from xoopslists.

I took a look at the 'criteria' class, but have no idea how it works!

Thanks,

Andrew

2
dawilby
Re: Bit of a toughie - database column into select field - how?
  • 2003/10/24 20:09

  • dawilby

  • Module Developer

  • Posts: 31

  • Since: 2002/1/3 0


Andrew:

This is maybe possible but requires more than than you probably think.

First of all you have to ask your users to always fill in the "user_from" field. This is an option which has to be implemented into the contact form.

Second option is to use the users emailaddress and determine where they come from. This option requires the Xoopslists.

Indeed a toughie

3
xgarb
Re: Bit of a toughie - database column into select field - how?
  • 2003/10/26 11:39

  • xgarb

  • Not too shy to talk

  • Posts: 154

  • Since: 2003/3/30


Hi,

Thanks for your answer.

I've actually changed the user input and editing forms already to include a 'choose your country' pull down list (which is populated from xoopslists).

I now want it so when people want to use the member search form to find members they are only given the choice of countries that actually have members.

The SQL would be something like SELECT DISTINCT country FROM users, but I've no idea how to do this with the way XOOPS generates it's pull down form fields.

Thanks,

Andrew

4
dawilby
Re: Bit of a toughie - database column into select field - how?
  • 2003/10/26 16:03

  • dawilby

  • Module Developer

  • Posts: 31

  • Since: 2002/1/3 0


Quote:
I've actually changed the user input and editing forms already to include a 'choose your country' pull down list (which is populated from xoopslists).

What do you store in the DB?
example: Netherlands or NL

5
xgarb
Re: Bit of a toughie - database column into select field - how?
  • 2003/10/27 18:02

  • xgarb

  • Not too shy to talk

  • Posts: 154

  • Since: 2003/3/30


Netherlands at the moment. Makes it easier for the user info page.

Andrew

6
Mithrandir
Re: Bit of a toughie - database column into select field - how?

Not using SMARTY templates:

echo "";

That working for ya?

7
xgarb
Re: Bit of a toughie - database column into select field - how?
  • 2003/10/28 10:41

  • xgarb

  • Not too shy to talk

  • Posts: 154

  • Since: 2003/3/30


Hiya,

I just got an empty pull down with your code. I moved it around a bit to this...

$sql = "SELECT DISTINCT location FROM ".$xoopsDB->prefix("users")." ORDER BY location";
$result = $xoopsDB->query($sql);
echo "";

Which gives me a pull down with "Array" as the key and the value for five select options rather than the country names. There are five countries in the DB but only 4 unique, so I'm not sure what's going on there.

The other problem is that I can't just stick this on the page with the code. Maybe I'd need to make a function or something.

Thanks,

Andrew

8
Mithrandir
Re: Bit of a toughie - database column into select field - how?

Try this:
function UserDropDownMenu () {
global 
$xoopsDB;
$sql "SELECT DISTINCT location FROM ".$xoopsDB->prefix("users")." ORDER BY location";
$result $xoopsDB->query($sql);
echo 
"";
while (
$location $xoopsDB->fetchArray($result)) {
echo 
".$location["location"]."'>".$location["location"]."";
}
echo 
"";
}

9
xgarb
Re: Bit of a toughie - database column into select field - how?
  • 2003/10/31 13:40

  • xgarb

  • Not too shy to talk

  • Posts: 154

  • Since: 2003/3/30


OK I've worked out a way to do this now. Thanks for everyones help.

1) I drop the following code into xoopslists (creates an array same as other lists)...

function &member_location ()
{
global $xoopsDB;
$locations = array();
$sql = "SELECT DISTINCT location FROM xoops_users ORDER BY location";
$result = mysql_query($sql);

while($location = $xoopsDB->fetchArray($result)){

$locations[$location['location']] = $location['location'];
}

return $locations;
}

2) Make a copy of formselectcountry and change the contents to

class XoopsFormSelectLocation extends XoopsFormSelect
{

function XoopsFormSelectLocation($caption, $name, $value=null, $size=1)
{
$this->XoopsFormSelect($caption, $name, $value, $size);
$this->addOptionArray(XoopsLists::member_location());
}
}

3) Save this as formselectlocation.php and add this to xoopsformloader.php

4) You can then use it in members/index.php the same as the other select form fields ie...

$location_text = new XoopsFormSelectLocation(_MM_COUNTRY, 'location', 'location');



Sweet!

Andrew

Login

Who's Online

390 user(s) are online (300 user(s) are browsing Support Forums)


Members: 0


Guests: 390


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits