Hi Guys, First of all thanks for taking time to read my thread. I'm learing PHP/MYSQL and by now I'm in a position to understand syntax and other basic things. One thing that I'm unable to understand, neither found any explanation about it online. My query is, when we code any website using PHP/MYSQL (I use komodo edit or Eclipse), how can I put LOGIN BOX (with user name and password boxes) anywhere I want on the page. For Example, look at the file here On right hand side, there is drop box for selecting country, once country is selected, the pages refreshes and states and cities of that country display. When I look at the code, I'm not able to understand how it is done. How can I put entire system (country drop down menu, states, cities) on LEFT hand side (adjacent to "FOR SALE" section). How to retrieve data from database and just display anywhere I want at index page? how it will be done. If I have 20 countries in database, how to display all the countries at footer (list). Is it done by DIV? (sorry for being layman). I would be very thankful to whosoever will answer my question. Many Many thanks Archc
It could be done a number of ways, but without looking at the code it is hard to help. One way it could be done is to hide a div on submit. Another way it could be done is load different data depending on the URL. For example, if the user selects a country on the page 'countries.php' it could refresh the page and put a variable in the URL such as 'countries.php?country=India' and extract the information from the database on the variable 'india' As I say, without looking at the code or the webpage, it's hard to help, but more than likely it is using an if submit statement such as: if (isset ($_GET['submit'])) { //Get country from url $country = $_GET['country']; //Query database depending on the URL variable } PHP:
Hi Mate, Thankyou very much for the reply. I don't want to get it done.. it was just an example. I just wanted to explain what my concern is. My question is still not answered. I'm asking in general, how can we do this part: "If I have 20 countries in database, how to display all the countries at footer (list). Is it done by DIV? (sorry for being layman). I want to retrieve data from database and display where I want on the page. How it will be done? Not just country, any data which is present in database, how we display at any page, anywhere ?
Firstly you need to connect to your database, see this tutorial: http://www.w3schools.com/php/php_mysql_connect.asp Secondly you need to select the table which contains your data and then pull the data from the rows, see here: http://www.tizag.com/mysqlTutorial/mysqlselect.php (this one also contains the connect code). The way you display the results is up to you. For best practice, I'd display the data in DIVs, here is some example code: //Login to mySQL mysql_connect("localhost", "username", "password") or die(mysql_error()); //select the database you wish to extract data from mysql_select_db("database_name") or die(mysql_error()); //Get a value from the URL $country_id = $_GET['country']; //Query the database for all results where the ID = $country_id $result = mysql_query("SELECT * FROM countries WHERE country_id = '$country_id'"); //Make sure there's rows if(mysql_num_rows($result)!=0) { while($row = mysql_fetch_array($result)) { //Ok there are rows, display the data (in this example, the data is a hyperlink echo "<div><a href=\"countries.php?id=" . $row['id'] . "\">" . $row['title'] . "</a></div><br />"; } } PHP:
helo....can someone help me... i have problem.. => i want to used if else statement...i have 3 condition(from database, total1, total2, total3)..then for each total i want to used if else statement.. => example... if total1 > 3 { score = 1; } else score = 0; => but how i want to write for condition total2 and total 3....
if ($total1 > = 3){ $score = 1;} else { if ($total2 > = 3){ $score = 1;} else { if $total3 > = 3){ $score = 1; }}} PHP: Not sure exactly what your script is doing but if you're adding totals from each you'd use something like: $score = 0; if $total1 > = 3){ $score = $score+1;} else { if $total2 > = 3){ $score = $score+1; } echo $score; PHP: If the both of the above = > 3 then the output would be 2.
This bit is your connection: //Login to mySQL mysql_connect("localhost", "username", "password") or die(mysql_error()); //select the database you wish to extract data from mysql_select_db("database_name") or die(mysql_error()); PHP: Change username, password and database name.