TOPIC:

Select, retrieve datas from database 11 years 3 months ago #31779

  • Topic Author
  • jem24h
  • Offline
  • Fresh Breezer
  • Fresh Breezer
  • Posts: 15
  • Thanks: 0
Hi :),

I spent a lot of time trying to figure out how to retrieve datas from the database, so now that I succeed, here is what I did.


Sorry, for my poor english, but i'm french... Besides I've got the french version, so a few terms must be different


je me suis très largement inspiré de This Topic helped me a lot

On my experience, it works in QUICKMODE with the version 1.72 of breezingforms

Step 1 :
- In the tree, select your form (not the field! ;)),
- Select the "advanced" tab
- Click on "more options"
- Select the tab "Form pieces"
- Click on the custom radio button

Step 2 :
You'll have to write or addapt the folloing snippet to get datas from your DB
I am a newbie in programing so this piece of code is probably not optimized ;)
        //ATTENTION, DO NOT MODIFY THE VARIABLE $test

        $this->execPieceByName('ff_InitLib');
	$test = "";
	mysql_connect("127.0.0.1","root","");//ADAPT THIS ACCORDING TO YOUR SERVEUR
	mysql_select_db("PAT");//REMPLACE "PAT" BY THE NAME OF YOUR DB
	$lien='Select * from TabMais6';//YOUR REQUEST SQL
	$image=mysql_query($lien) or die (mysql_error());
	while($uneligne=mysql_fetch_assoc($image))
		{
		$test .=  "0;{$uneligne['col2']};{$uneligne['id']}\n";
                //HERE "col2" AND "id" ARE 2 ATTRIBUTE FROM MY DATABASE
		}

Step 3 :
Once this is done, copy the the function below after your the previous code
I took it from the website that I named earlier. It works perfectly without touching anything
function ff_setSelectList($name, $value)
{
  global $ff_processor;
  for ($r = 0; $r < $ff_processor->rowcount; $r++) {
    $row =& $ff_processor->rows[$r];
    if ($row->name==$name)
      $row->data2 = $value;
    unset($row);
  } // for
} // ff_setSelectList

Step 4 :
One more thing to do and we're done :silly:
Now, we have to call the previous function, so write this under the function.
ff_setSelectList('NAME OF THE FIELD', $test);
//WRITE THE NAME OF THE FIELD AND DON'T TOUCH THE $test VARIABLE

Step 5 : SAVE ! and observe the result

If you want to do it one more time for another field, do it all over again without the step 3 and changing the name of the variable $test(at the begining and at the end).
I hope it'll help you and you'll have less trouble doing it than I had :laugh:!

If you want to go further using this you can do a Hierselect (2 dependant lists linked to to the database). I managed to do this : see Re: how change values to select list...?
Enjoy B)

Please Log in or Create an account to join the conversation.

Last edit: Post by jem24h.

Re: Select, retrieve datas from database 11 years 3 months ago #33022

  • K4RL0S
  • Offline
  • Fresh Breezer
  • Fresh Breezer
  • Posts: 10
  • Thanks: 0
Hi,

I've tried all you wrote, but a few questions, could you give me a hand please?
Step 1 OK.
Step 2 I wrote this as You said:
$this->execPieceByName('ff_InitLib');

$test = "";
mysql_connect("localhost","USER","PASS");
mysql_select_db("DB");
$lien='Select * from jos_modalidad_a12"; //MY TABLE
$image=mysql_query($lien) or die (mysql_error());
while($uneligne=mysql_fetch_assoc($image))
{
$test .= "0;{$uneligne};{$uneligne}\n";//MY FIELD TO ADD
}

Step 3: (Without touching anything)
function ff_setSelectList($name, $value)
{
global $ff_processor;
for ($r = 0; $r < $ff_processor->rowcount; $r++) {
$row =& $ff_processor->rows[$r];
if ($row->name==$name)
$row->data2 = $value;
unset($row);
} // for
} // ff_setSelectList

Step 4: (I think here is my mistake) ff_setSelectList('NAME OF THE FIELD', $test);
Question 1: Where I have to put this?
Question 2: Name of the FIELD (You mean the select-list from my form right)?

Sorry for my english haha.
Thank's in advance :)

Please Log in or Create an account to join the conversation.

Re: Select, retrieve datas from database 11 years 3 months ago #33066

  • Topic Author
  • jem24h
  • Offline
  • Fresh Breezer
  • Fresh Breezer
  • Posts: 15
  • Thanks: 0
Hi K4RL0S B)

What you did seems right to me.
Here are the answers to your questions :

Answer 1 :
You have to put ff_setSelectList('NAME OF THE FIELD', $test); at the end of what you wrote before
All your codes go here (or see the image below) :
- In the tree, select your form (not the field! ),
- Select the "advanced" tab
- Click on "more options"
- Select the tab "Form pieces"
- Before form (or something like that)
- Click on the custom radio button



Answer 2 :
NAME of the field is the name you put for your selectlist form
The image show you where you entered it :

Attachments:

Please Log in or Create an account to join the conversation.

Re: Select, retrieve datas from database 11 years 3 months ago #33191

  • K4RL0S
  • Offline
  • Fresh Breezer
  • Fresh Breezer
  • Posts: 10
  • Thanks: 0
Thank's for the fast answer jem24h. :)

I'm still without add fields to my select-list :(

My data is loaded but not shown and my select-list dissapear :blink:

I know my data is loaded because I add "echo $test" at the end and then show the field, what else could be wrong?...

Thank's for help man. [img/]

Please Log in or Create an account to join the conversation.

Re: Select, retrieve datas from database 11 years 1 month ago #38496

  • K4RL0S
  • Offline
  • Fresh Breezer
  • Fresh Breezer
  • Posts: 10
  • Thanks: 0
I've tried with this code only to populate a select-list:

$this->execPieceByName('ff_InitLib');

$test = "";
for ($i = 0; $i < 10; $i++) {
$test .= "0;Product {$i};value{$i}\n";
}

function ff_setSelectList($name, $value)
{
global $ff_processor;
for ($r = 0; $r < $ff_processor->rowcount; $r++) {
$row =& $ff_processor->rows[$r];
if ($row->name==$name)
$row->data2 = $value;
unset($row);
} // for
} // ff_setSelectList

ff_setSelectList('temas411', $test);

... but nothing :(
Can somebody help me please?

Please Log in or Create an account to join the conversation.

Re: Select, retrieve datas from database 11 years 1 month ago #38500

  • Topic Author
  • jem24h
  • Offline
  • Fresh Breezer
  • Fresh Breezer
  • Posts: 15
  • Thanks: 0
Hi !
According to me this line isn't accurate :
$test .= "0;Product {$i};value{$i}\n";

I don't think it returns what's expected
You also need to call the database before.

I've change the code I use, it's now much easier, you can try with it :
$this->execPieceByName('ff_InitLib');

	mysql_connect("127.0.0.1","root","");
	mysql_select_db("PAT");
	
		//FUNCTION THAT LIST DATAS 
	function ff_setSelectList($name, $value)
	{
		global $ff_processor;
		for ($r = 0; $r < $ff_processor->rowcount; $r++) 
		{
				$row =& $ff_processor->rows[$r];
				if ($row->name==$name)
				$row->data2 = $value;
				unset($row);
		} // for
	} // ff_setSelectList
	
	// FONCTION NORMALE
	function liste($table, $col_a_afficher, $col_id, $nom_du_champs) 
	{
        $val = "";
		$lien='Select * from '.$table.'';
		$image=mysql_query($lien) or die (mysql_error());
		$vide =  "0;;!empty\n";
		while($uneligne=mysql_fetch_assoc($image))
			{	
			$a=utf8_encode($uneligne[$col_a_afficher]);
			if(isset($_POST[$nom_du_champs])) $val .=  "1;{$a};{$uneligne[$col_id]}\n";
			else $val .=  "0;{$a};{$uneligne[$col_id]}\n";
			}
		$test =  $vide.$val;
		ff_setSelectList($nom_du_champs, $test);
	}

	
liste("TabMais2", "col1", "id", "type_sol");

mysql_close();

you just need to change this :
	mysql_connect("127.0.0.1","root","");
	mysql_select_db("PAT");

and this
liste("TabMais2", "col1", "id", "type_sol");
the 1st value is the name of the table you call
the 2nd is what's gonna be shown (enter the name of the col you need)
the 3rd is the value sent by the form (enter the name of the col you need)
the 4th value is the name of the field

i'm not sure to understand what you wanna do so try with this if Product and Value are cols from your tab
liste("YOUR_TABLE_NAME", "Product", "value", "temas411");

Try like this, it should work

Please Log in or Create an account to join the conversation.

Moderators: ForumSupport
Time to create page: 0.052 seconds

BreezingForms Pro 1.4.7 for WordPress Released!

Available in the membership section.

September Discount!

Massive discounts on all subscriptions!

Get Your Subscription Here

Quick Links

Downloads

BreezingForms

ContentBuilder

BreezingCommerce

Templates

Documentation

BreezingForms

ContentBuilder

BreezingCommerce

Apprendre BreezingForms (French Community)

Apprendre et maîtriser BreezingForms par des tutoriels et exemples, le tout en français

breezingforms.eddy-vh.com

Questions et réponses sur les forums de l'AFUJ

AFUJ

Special Offer

Summer Sale! All subscriptions at a special price!

Includes prio support, all of our current and future Joomla!® extensions and Joomla!® templates for the duration of your membership.

Get it from here

3rd Party Discount - 25% Off

We help you to keep your costs under control. If you are a new member and purchased a form building tool from a different form vendor, then you'll get a 25% discount on our subscription plans.

How to receive the discount:

Send us a quick email to sales@crosstec.org with a proof of purchase (for example a paypal receipt), await payment instructions and enjoy your membership!