Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,155,898 members, 7,828,163 topics. Date: Wednesday, 15 May 2024 at 04:04 AM

Need Help On This - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Need Help On This (1398 Views)

I Need Help On Laravel With Voyager / I Need Help On The Comptia Network+ (N10-006) Certification / I Need Help On Java (2) (3) (4)

(1) (Reply) (Go Down)

Need Help On This by skyhighweb(m): 11:26am On Apr 24, 2017
hello am just gonna write it out what the problem is am using php i have a table for example with users and transport and what they selected for example,in my table i have this data as below.

jemery selected car
steve009 selected car
monay selected bike
labert selected car
lalaland selected bike

i need a code that will have a drop down menu when i click cars it will show the users and when i click bike it will show the users, hope u understand, thanks.
Re: Need Help On This by hexy40: 8:29pm On Apr 24, 2017
I dont get what the problem is. Are u having problem with the html, the structure of the data Base, or sql or everything .
First set up a database table containing two columns(users and transport) eg.
CREATE DATABASE vehicle;
USE vehicle;
CREATE TABLE users_transport(
id int(80) NOT NULL AUTO_INCREMENT,
users varchar(80) NOT NULL,
transport varchar(80) NOT NULL,
PRIMARY KEY(id)
);

now fill the database table with the info you listed.Ie names under "users" and car/bike under "transport"

Next : Write the php...? what will be in the drop down menu? the cars or the users?
Re: Need Help On This by skyhighweb(m): 10:15pm On Apr 24, 2017
hexy40:
I dont get what the problem is. Are u having problem with the html, the structure of the data Base, or sql or everything .
First set up a database table containing two columns(users and transport) eg.
CREATE DATABASE vehicle;
USE vehicle;
CREATE TABLE users_transport(
id int(80) NOT NULL AUTO_INCREMENT,
users varchar(80) NOT NULL,
transport varchar(80) NOT NULL,
PRIMARY KEY(id)
);

now fill the database table with the info you listed.Ie names under "users" and car/bike under "transport"

Next : Write the php...? what will be in the drop down menu? the cars or the users?
the users will b in the drop down menu, when i select cars the menu will b the users
Re: Need Help On This by skyhighweb(m): 10:16pm On Apr 24, 2017
sql
Re: Need Help On This by hexy40: 8:14am On Apr 25, 2017
Go to the console, copy and past these to create the data base and table


CREATE DATABASE vehicle;
USE vehicle;
CREATE TABLE users_transport(
id int(80) NOT NULL AUTO_INCREMENT,
users varchar(80) NOT NULL,
transport varchar(80) NOT NULL,
PRIMARY KEY(id)
);

INSERT INTO users_transport
(users,transport)VALUES
('steve009','car'),
('maonay','bike');
('labert','car');
('lalaland','bike');



Then open a php file and paste these:


<?php mysql_connect("localhost","root","" ) ;?>
<?php
$sel=mysql_select_db("vehicle" ) ;
?>
<html>
<form action="theNameOfThephpPage.php" method="POST">
<input type="submit" name="vehicle" value="car"/>
<input type="submit" name="vehicle" value="bike"/>
</form>

<?php
$selected=null;
if(isset($_POST['vehicle'])){$selected=urldecode($_POST['vehicle']);}

$s= "SELECT * FROM users_transport WHERE transport='$selected'";
$se= mysql_query($s);
echo"<select>";
while($sel=mysql_fetch_array($se))
{$us= $sel['users'];
echo "<option>".$us."</option>";

}
echo"</select>";

?>


</html>


this should run fine.
Then take your time to study the codes and mould it into what you want it to be.
Re: Need Help On This by Adesege(m): 8:15am On Apr 25, 2017
You need a normalized datatbase to achieve that.

First, you will have a table with list of users. Then another table with list of transport/cars.

You create another table for what users selects having foreigns keys to their parent table.

Then on the home page, you select all from the table "what users have selected" and join it with their parent table to get the car and user's name.

You display the car name on the first select dropdown. To display the users, you may need to use ajax or submit the form when users change the first select box or click on a submit button.

I hope you understand this
Re: Need Help On This by Adesege(m): 8:21am On Apr 25, 2017
hexy40:
Go to the console, copy and past these to create the data base and table


CREATE DATABASE vehicle;
USE vehicle;
CREATE TABLE users_transport(
id int(80) NOT NULL AUTO_INCREMENT,
users varchar(80) NOT NULL,
transport varchar(80) NOT NULL,
PRIMARY KEY(id)
);

INSERT INTO users_transport
(users,transport)VALUES
('steve009','car'),
('maonay','bike');
('labert','car');
('lalaland','bike');



Then open a php file and paste these:


<?php mysql_connect("localhost","root","" ) ;?>
<?php
$sel=mysql_select_db("vehicle" ) ;
?>
<html>
<form action="theNameOfThephpPage.php" method="POST">
<input type="submit" name="vehicle" value="car"/>
<input type="submit" name="vehicle" value="bike"/>
</form>

<?php
$selected=null;
if(isset($_POST['vehicle'])){$selected=urldecode($_POST['vehicle']);}

$s= "SELECT * FROM users_transport WHERE transport='$selected'";
$se= mysql_query($s);
echo"<select>";
while($sel=mysql_fetch_array($se))
{$us= $sel['users'];
echo "<option>".$us."</option>";

}
echo"</select>";

?>


</html>


this should run fine.
Then take your time to study the codes and mould it into what you want it to be.

A normalized datatbase will be the best to achieve this. Imagine a situation where the user's email or username can be changed, then that means the code may break in between.

So it will be best for him to store the user's and car's information somewhere. And use their ids as foreign keys in other table.

Also, i think the OP wants to be able to select the cars/bike and not click on static buttons.
Re: Need Help On This by hexy40: 8:31am On Apr 25, 2017
Adesege:


A normalized datatbase will be the best to achieve this. Imagine a situation where the user's email or username can be changed, then that means the code may break in between.

So it will be best for him to store the user's and car's information somewhere. And use their ids as foreign keys in other table.

Also, i think the OP wants to be able to select the cars/bike and not click on static buttons.

Judging from the question, i believe the OP is a biginner. One has to be comfortable with one database table before he can combine 2. I just think this will work for the now and he can advance at his own pace.
Re: Need Help On This by hexy40: 9:17am On Apr 25, 2017
Adesege:


A normalized datatbase will be the best to achieve this. Imagine a situation where the user's email or username can be changed, then that means the code may break in between.

So it will be best for him to store the user's and car's information somewhere. And use their ids as foreign keys in other table.

Also, i think the OP wants to be able to select the cars/bike and not click on static buttons.

I have been thinking, in what situation can user name be changed? Once you comfirm email, the user name is permanent in most site if not all sites. My style will still work in life situation
Re: Need Help On This by Adesege(m): 11:11am On Apr 25, 2017
hexy40:

Judging from the question, i believe the OP is a biginner. One has to be comfortable with one database table before he can combine 2. I just think this will work for the now and he can advance at his own pace.

Beginner or not, it is normal coding standard to normalize your database except in some other cases where it may not be applicable.

In this case, normalized database is what the OP needs.
Re: Need Help On This by hexy40: 11:15am On Apr 25, 2017
Adesege:


Beginner or not, it is normal coding standard to normalize your database except in some other cases where it may not be applicable.

In this case, normalized database is what the OP needs.
Please, give us a sample code let's see
Re: Need Help On This by Adesege(m): 6:28pm On Apr 25, 2017
hexy40:
I have been thinking, in what situation can user name be changed? Once you comfirm email, the user name is permanent in most site if not all sites. My style will still work in life situation

No, that's a wrong assertion.

That Nairaland does not allow users change their username doesn't mean Nairaland uses username as foreign keys in other table.

Imagine Nairaland stores usernames as foreign keys in other tables, it will be difficult for them in future to allow users change their username.

Your style is a bad database design practice.

Here's an article on Wikipedia about Normalized database design

https://en.wikipedia.org/wiki/Database_normalization
Re: Need Help On This by Adesege(m): 6:31pm On Apr 25, 2017
hexy40:

Please, give us a sample code let's see

I have given a detailed explanation here. I'm currently incapacitated to give a sample code now.

Adesege:
You need a normalized datatbase to achieve that.

First, you will have a table with list of users. Then another table with list of transport/cars.

You create another table for what users selects having foreigns keys to their parent table.

Then on the home page, you select all from the table "what users have selected" and join it with their parent table to get the car and user's name.

You display the car name on the first select dropdown. To display the users, you may need to use ajax or submit the form when users change the first select box or click on a submit button.

I hope you understand this
Re: Need Help On This by skyhighweb(m): 6:40pm On Apr 25, 2017
since i have been able to get help on that i have another question.

need a simple code or something that will help ne remove content from list so it wont be choosen again by users, as in if its in table that means ssome one choose it so iit wont appear on the list again for users to select it thus avoiding multiple selection
Re: Need Help On This by hexy40: 9:38pm On Apr 25, 2017
Adesege:


I have given a detailed explanation here. I'm currently incapacitated to give a sample code now.


I Understand exactly what you are saying. I don't just agree with you on this particular case. Using three tables where one can serve.
if it were a situation where the user can choose more than one vehicle, then I will agree with you completely, but in this case I will stick with my version
Re: Need Help On This by Adesege(m): 9:49pm On Apr 25, 2017
hexy40:


I Understand exactly what you are saying. I don't just agree with you on this particular case. Using three tables where one can serve.
if it were a situation where the user can choose more than one vehicle, then I will agree with you completely, but in this case I will stick with my version

Well, you dont say cos you dont want to use three tables instead of one then you shouldnt do the normal thing.

In your class in OOP, you were taught Objects, methods and properties, if you haven't forgotten.

The car is an object which might have some methods and properties.

Imagine you have a table called cars amd another table called car_owners.

If you want to reference a car in the car_owner table, which will be the best to use

1. The name of the car
2. The id of the car?
Re: Need Help On This by skyhighweb(m): 10:02pm On Apr 25, 2017
all aguement no codes should i drop the table and column content so i can get a code to work with
Re: Need Help On This by hexy40: 8:37pm On Apr 28, 2017
skyhighweb:
all aguement no codes should i drop the table and column content so i can get a code to work with
I have told u what to do already. Your choice.....' i dont know what u are saying about, all argument and no codes'. I belive I wrote and posted a simple code and a simple database structure.

(1) (Reply)

How To Buy Bitcoin With Hack$ed money highways Using Sofort Account / Windows 10 Activator 2018 / Customized Laptop Skin

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 42
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.