PDA

View Full Version : MySQL/PHP/JQUERY - Advice?


cocoonfx
06-04-2010, 10:29 PM
Hi

I am have put together a MySQL database which lists regions and countries. I have then found a Jquery script to create a nice toggle effect. So when you click on the region the list of countries appear. At the moment all the countries appear.

However I am not sure if I have created my database correctly for me to be able to link the region names to the countries.

i.e when i click on Africa the African countries will appear.

I have an id on the table but this is just for each line.

Would it be better to have a unique id for each region and then a country id i.e
Region | Country | R_ID |
East Africa | Cameroon | 1 |
East Africa | Kenya | 1 |
West Africa | Congo | 2 |
Europe | UK | 3 |
Europe | Germany | 3 |

Then my query in PHP would be

$query =sprintf("SELECT * FROM guide");
$result =mysql_query($query);
$rowLoc = mysql_fetch_array($result);

<table>
<?php do {?>
<tr>
<td><button><?PHP echo $rowLoc['Region'];?> </button></td>
</tr>
<?php }while ($rowLoc = mysql_fetch_array($result)); ?>
</table>
// results

<div id="test">
<?php do {?>
<li><?PHP echo $rowLoc['Country'];?> - <?PHP echo $rowLoc['Capital City'];?></li>

<?php }while ($rowLoc = mysql_fetch_array($result)); ?>

</div>

<script>
$("button").click(function () {
$("#test").slideToggle("slow");
});
</script>

Link : http://www.gossipxo.com/travel_guide.php

If any one can advice on the database I can work out the rest i think...

edbr
06-05-2010, 12:55 AM
not saying its best but i would approach it by having a country table and a capitals table and linking them by country

cocoonfx
06-06-2010, 03:01 PM
Hi Edbr

I have taken your advice and also followed DJ tutorials on dynamic drop downs which is getting me closer to where i want to be with this little project. However I have got a problem as the page which the script is on as a user login for vbulletin which every time you select a drop down auto directs the user to the login for vbulletin.

I need both to work can any one suggest how to get the drop downs to work with out getting the page to redirect to vbulletin

this is the page which redirects

http://www.gossipxo.com/travel_guide2.php

And this is the page which works with out the login area

http://www.gossipxo.com/travel_guide.php

Any suggestions would be appreciated..

edbr
06-07-2010, 01:43 AM
what happens if you remove this

<script type="text/javascript" src="/forum/clientscript/vbulletin_md5.js (http://www.dreamweaverclub.com/forum/view-source:http://www.gossipxo.com/forum/clientscript/vbulletin_md5.js)"></script

cocoonfx
06-11-2010, 10:38 AM
I think I tried this but I will do it again... let you know what happens.

cocoonfx
06-13-2010, 10:01 AM
Hi


I removed the line of script but it still redirects the page.

cocoonfx
06-14-2010, 10:25 PM
I have worked out what the issue was.

Please see below. - In the form I had to place a "?" at the end to stop the redirect. I also need to change the javascript from [0] to [1]

<form id="TGcountry" name="TGCountry" method="post" action="travel_guide.php?" >
<select name="Region" onchange="document.forms[1].submit()">

edbr
06-15-2010, 01:05 AM
nice one, didnt have a clue