How to create drop down menu [closed] - php

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
i'm trying to create dropdown menu, this drop down menu is about name of countries, so when the user for example choose country A then all the posts that are associated with country A will be displayed.
So my question is do i need to create a separate PHP file for every country in order to get the posts that are associated to a particular country?

No you would create your dropdown as usual with
<select name="myCountry">
<option>Country A</option>
<option>Country B</option>
<option>etc lol</option>
</select>
Then have your form point to your PHP processing file, and in there you would do something like.
$selectedCounty = $_GET['myCountry']; //This assigns the selected value from that country dropdown into a usable variable.
Then u query the database.
Lets assume you have a database table called "countries" and a column with the countries listed called "myCountries".
$selectCountryQS = SELECT * FROM countries WHERE myCountries = '$selectedCountry';
Then put it into action
$selectCountryDoIt = mysqli_query('connection variable here', $selectCountryQS ) or die('error mssg'. mysqli_error(conection var here));
Then set a while loop that will grab ALL the posts data that you wanted.
while($row = mysqli_fetch_array($selectCountryDoIt)){
echo $row[' your column data to display here'];
}
This will give you what you need.
Hope this helps. Good luck

Related

Need search a value from database from comma separated string [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I have a table in database that is TEXT field. In this table i have stored my product ids . Now when i go to cart and get all product id of cart i want to match from database field and get only those ids that there stored in product id.
Please see image first.
In this field you will see "check_values" field. here all product ids are stored in comma separated.
Let me take a example
Like i have purchase a product that product id is 161. So i want to match 161 id from "check_value" filed and get only those ids (from images) that having 161.(11,14,15).
Hope you understand my question.
You can use FIND_IN_SET e.g.
SELECT * FROM images WHERE FIND_IN_SET(161, check_values) > 0

How do i set up tables in an mysql database based on member positions? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I am trying to set up tables in a mysql database so that a member can be assigned a position based on their section, group and role.
So if i had a form with three drop down boxes in html like so:
<form>
<select name="section"></select>
<select name="group"></select>
<select name="role"></select>
<button name="setPosition">Set Position</button>
</form>
How do I set up the sql tables so that each drop down can show whats available from there respective table based on the previous selection, and how would the member be assigned to that position in the database?
Thanks,
Edit: Sorry from not being clear, I know how to use ajax to get query's from a database and populate the selects with that data. What I need is the sql tables to be set up so that the selects can be context based, so for example, If I select a value from 'section' the 'group' shows all the groups in that section, which it gets from said table.
The standard way to set this up would be like this, with a members table that holds the id's for the other related tables, it's called "normalizing" the data.
table name columns
--------------------------------------------------
members section_id, group_id, role_id
sections id, section_name
groups id, group_name
roles id, role_name

mysql query to fetch data from database and display it in the form of stacked bar graph using php [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
Hi guys I have Google to get answer for the above question but I got the answer for displaying the plain bar graph one but not stacked bar graph.
My problem is I have to display the stacked bar graph based on the number of count of different categories for example the number of login to the site, reset password, chats etc.And I have to use plugin for displaying of graph.
I would request you guys to please suggest me some thing on this.As I'm new to php.
Thanks in advance guys
I think I understand the question (a good one)
SELECT category, COUNT(category)
FROM users
GROUP BY category
ORDER BY category
This displays the total number of hits for each category. In javascript I use AJAX call to execute the php - mysql, then return the array of counts back to the javascript to display the stack graph.
I executed this code on my system, just substitute "where user_id = 36" for "where date = 31032015" (whatever date format), and change the table "users" to your table name.
$template2=mysql_query("SELECT category, COUNT(category) FROM users where user_id = 36
GROUP BY category ORDER BY category ");
while($template=mysql_fetch_array($template2)){
echo "<tr><td>{$template['COUNT(category)']} {$template['category']}</td></tr>";
}

Create Hidden Association in PHP/MySQLi [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have a MYSQL Db that has a PROFILE-TABLE as well as a KEYWORD-TABLE which holds profiles and the other holds keywords associated with those categories.
Profile-Table
UserID
UserName
UserDept
UserPhoto
UserKeyword > indexes KeywordName (from Keyword-Table)
UserAssociations
Keyword-Table
KeyID
KeywordName
I need to make an association with the categories/keywords.
I want to add a hidden field (UserAssociations) onto my profile form which will display a hidden association where as when you click on a category via a link on the page, it will index first those that are associated. I have written this in PHP and use MYSQLI database.
I have never created associations before needing this. What would be the easiest way to achieve this functionality?
From what I gather, you wish to associate a user profile with keyword. What you need is another table to represent the relationship, something like this:
profile_keywords ( <UserID>, <KeyID> )
Hence, if UserID 4 has associated himself with keyword ID 3, you would have an entry in profile_keywords like this:
UserID, KeyID
---------------
3 4

Strange things happening when I am updating mysql database from my form [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have a form that users use to update items. The form contains input fields such as iten name, item price, quantity etc.
Now, the form is updating, but it is duplicating the item description in the database.
This is the item description adds ends up as:
This is the item description This is the item description.
Is there a way to only update text that has changed? The form is built in php.
Please try this once if you are using mysql
there is 2 solutions for it...
If you want to update value of field if new value changed from existing one. then run query for every field separately one by one of form
update tbalename set fieldname = 'fieldvalue' where table_id = "unique id value" AND fieldname != "fieldvalue";
else
update tbalename set fieldname1 = 'fieldvalue1', fieldname2 = 'fieldvalue2',fieldnamenth = 'fieldvaluenth' where table_id = "unique id value"
It will update all fields value ....
It would be meaningful if u post your code.. But this is the syntax of mysql update query
UPDATE table SET field = 'yourvalue' WHERE id = 'id value'

Categories