PDA

View Full Version : upload and arranging data



chechu
10-24-2007, 02:27 PM
Hey guys,
I'm looking for a script that can upload data, and show them after chosing certain criterias. F.ex: a visitor types his adress in, and another visitor can find his data by chosing different inputs (by name, city,...).
Might be done with php, but please note that I am no good at that whatsoever (after looking at this forum, I often feel that I'm no good at any language ...).

boogyman
10-24-2007, 03:13 PM
you would like to do two things here.. 1 upload 2 searchability

there are tutorials on here about how to upload files / etc into a databse
having another person able to search is just another query and you can do it any server-side language... I would suggest whatever you are most comfortable / already exists on the site. eg( if your site uses php its not wise to do this in asp or visa versa )

searching the database for a specific item is really dependant on the criteria you wish to allow them to search but a basic query is soemthing like


SELECT field(s) FROM table WHERE field = 'condition'

but without more details as to what you wish accomplish all we can give are the generic versions.

chechu
10-24-2007, 05:04 PM
What I'd like to find is that I can give his current company and contact data, so that another, by chosing an item, can find my data.

F.ex.: I am looking for the sales manager of CC, so I look into 'Sales Manager' and 'CC', and then come up with the adress, tel, etc.
It's like building up a network.

boogyman
10-24-2007, 05:35 PM
to me I would think that this should be spread over a couple of tables, however it all depends on how your database is set up I will do it the way I would do it, and also I will do it as if they were all in 1 table



SELECT c.company_name, che.title, che.work_telephone, e.fname, e.surname, e.address, e.home_telephone FROM Company_has_employees AS che LEFT JOIN employees AS e ON che.employee_id = e.employee_id LEFT JOIN company AS c ON che.company_id = c.company_id WHERE c.company_name = 'CC' AND che.title = 'Sales Manager'"

now let me brake that down.


SELECT c.company_name, che.title, che.work_telephone, e.fname, e.surname, e.address, e.home_telephone

grabs the fields that will be displayed to the user from the appropriate tables


FROM Company_has_employees AS che LEFT JOIN Employees AS e ON che.employee_id = e.employee_id LEFT JOIN Company AS c ON che.company_id = c.company_id

uses the reference table Company_has_employees to bridge between the company info and the employee info... this is best for optimization because plugging in a unique id is cuts down on maintanence and provides the ability for 1 person to work for multiple companies / have multiple titles. The joins are based upon the reference table lining them up / pulling them in according to the appropriate unique identity.
NOTE: Table AS abbreviation is a method of shortening what you need to write... if you did not want to use the abbreviation / do not feel comfortable in how to use it I would suggest that you write out the whole table like

SELECT Company.company_name, Company_has_employees.title, Company_has_employees.work_telephone, Employees.fname, Employees.surname etc...


WHERE c.company_name = 'CC' AND che.title = 'Sales Manager'"
this is how the field is widdled down to get a specific result... in your case you want the company CC and the title of Sales Manager.

this example is assuming the database is structured somewhat like
TABLE Company_has_employees
company_id
employee_id
title
work_telephone

TABLE Company
company_id
company_name

TABLE Employees
employee_id
fname
surname
address
home_telephone

okay that was how I would do it in an optimized database, if all the info is in 1 table the query will be alot smaller but accomplish the same thing

SELECT company_name, title, work_telephone fname, surname, home_telephone, address FROM People WHERE company_name = 'CC' AND title = 'Sales Manager'

with a database structure like
TABLE People
company_name
fname
surname
title
work_telephone
address
home_telephone

both of them accomplish the same thing but in the first example the database is optimized for redundancy.


if you give us a better picture of the structure of your database we can help you create a more customized query, however I, we, suggest that you try it out yourself first and bring any questions / errors that you receive.

chechu
10-25-2007, 11:27 AM
Wow, thanks so much for your reply, that seems to be very much into details. But I don't understand it, sorry. How exactly would this look like, if you were to place the html code of a page; how would your code be placed in it ? Then I can see how it works, and start playing with it (hopefully).

boogyman
10-25-2007, 11:37 AM
you couldn't use that in a html page. as I said before you would need some sort of server-side programming language. I will use php as an example.


<?php

$db = array(
'host' => 'localhost',
'username' => 'mysqluser',
'password' => 'mysqlpass',
'dbname' => 'database_name'
);

$link = mysqli_connect($db['host'], $db['username'], $db['password'], $db['dbname'])
or die("Error: Trouble connecting to the server");

if( $link )
{
$query = mysql_query("__my_query__");
if( !$query ) { die("Error: Trouble query cannot execute") }
else
{
while( $row = mysql_fetch_assoc($query) )
{
doSomething();
}
}
}
?>

chechu
10-25-2007, 12:00 PM
Thanks a lot. So I upload this file, and then I only need a html file where the choices can be made, like in a contact form, and make the action go to the php-page, right ?
Where will the data be stored ? And how will they grafically come up ?
Lots of questions, as I have absolutely no idea how this works ...

boogyman
10-25-2007, 12:07 PM
Thanks a lot. So I upload this file, and then I only need a html file where the choices can be made, like in a contact form, and make the action go to the php-page, right ?

umm I would suggest using a php page from the get go.


Where will the data be stored ? And how will they grafically come up ?
that example is how to get data from a mysql database via PHP


Lots of questions, as I have absolutely no idea how this works ...
then maybe you should read http://www.php-mysql-tutorial.com/ and if you have any specific questions we can answer those

chechu
10-25-2007, 12:20 PM
Thanks. I'll have a look at this.