Log in

View Full Version : data from one combo to another



raihan
04-03-2013, 03:23 PM
Hi,
I have created few tables and combo boxes in my site. Please have a check on raihans.co.uk, log in with userdb, pwd: open. then hover on User Log In/Out and click on DB Test.

The Country, State or Province names are entered manually through codes.
I wishes to get the country entries in 1st Combo from my table (named, 'Test_Country') in mysql. Then as I click on any country, on the 2nd combo it will show the State from another table (named, 'Test_State'). Just as it is now, but from the database tables.

My table entries are like:
Table Fields
------ ----------
Test_Country - Country_Name, CountryID
Test_State - State_Name, StateID
Test_CountryState - CountryID, StateID

How I may do that, pls help me.

Thanking you in advance.


Raihan

raihan
04-05-2013, 09:15 PM
Hi,

No one replied anything yet to me.

Anyway, I have tried a bit with myself. I am using Joomla 3.0 and for using my code in the Article I have used 'Sourcerer' extension. As mentioned before, please have a look on my site raihans.co.uk, then login as 'dbuser', password is 'passwd'. Hover on User Log In/Out, then click on DB Test.

I have use the code as below in my Article:



<?php** $link = mysql_connect("localhost", "DB_User", "DB_Pwd");
** mysql_select_db("DB_Name");
** $query = "SELECT Column_Name FROM DB_Table";
** $result = mysql_query($query);
** while ($line = mysql_fetch_array($result))** {
** foreach ($line as $value) {
**** echo*"This*is*<font*color=\"blue\">$value </font>! <br />";
** }* }
** mysql_close($link);
?>


Note: Don't know why showing '*', instead of 'space' in the code, when submitted this reply.
At the moment it showing the data from a column in a table, but showing twice. Can't figure-out, why? Can anyone please help me.

Thanks in advance.

Raihan

james438
04-08-2013, 02:04 AM
Sorry, but some questions get neglected sometimes. If you put the code in code tags you probably won't have that problem. It also makes code easier to read. As to your original question. I did look at your site a while back. Why not use javascript like you have been? It would be better than using php/mysql in this case. Why do you want to use php/mysql instead? I guess I am not quite sure what you are trying to accomplish.

raihan
04-08-2013, 04:07 PM
Thanx a lot for ur reply. I will try as u suggest me. If I do with Javascript, then pls get back to me sometime.

Raihan

raihan
04-15-2013, 10:10 AM
Hi, I have made a bit progress. I have the list of data from a column in the Table, to Combo Box. I have used the following code in my Joomla article:

{source}
<select>
<option value="" selected>Select a country</option>
<?php
$link = mysql_connect("Domain_Name","DB_User","DB_User_Passwd");
if (!$link)
{ die('Could not connect to Database: ' . mysql_error());
}
mysql_select_db("conct",$link);
$category = "SELECT Country_Name FROM Test_Country";
$query_result = mysql_query($category);
while($result = mysql_fetch_assoc($query_result))
{
?>
<option value = "<?php echo $result['Country_Name']?>"><?php echo $result['Country_Name']?></option>
<?php
} ?>
</select>
{/source}

But, I want as soon as I click on any item on the list, another list of data will retrieve from corresponding table. Just as example on the top, in my site. Is there anyone may help me, please.

Thanking you in advance.

Raihan
UK