Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Recalling information from a MySQL database with PHP...Help...
Old 02-28-2009, 05:56 PM Recalling information from a MySQL database with PHP...Help...
Novice Talker

Posts: 5
Trades: 0
Ok, so I know how to set up a MySQL database and use some basic PHP to get some results, but what I'm trying to do, I think may be over my head, but I'm pretty sure it can be done. I have a database with a list of schools (about 150) and grades and test scores needed to get in. What I would like to do is when someone clicks on the specific school, they are directed to a page with preformed tables and charts, which would be filled in with the information from the database, specific to that school (meaning specific to that specific database row). How do I go about doing this? Any help would be appreciated. Thanks in advance.
jb265536 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-01-2009, 05:20 AM Re: Recalling information from a MySQL database with PHP...Help...
stoot98's Avatar
Ultra Talker

Posts: 427
Name: Stuart
Location: Glasgow, Scotland
Trades: 0
First of all create your link with a parameter of the school's ID (e.g. mypage.php?schoolID=1)

Then on your target page use that variable ($_GET['schoolID']) in your SQL query to pick up the various results you want (grades etc). Then just use that info to display how you want.

Hope this helps!
stoot98 is offline
Reply With Quote
View Public Profile
 
Old 03-01-2009, 12:58 PM Re: Recalling information from a MySQL database with PHP...Help...
Novice Talker

Posts: 5
Trades: 0
when i call the mypage.php?schoolID=1 , how to I initiate the specific database?
jb265536 is offline
Reply With Quote
View Public Profile
 
Old 03-01-2009, 01:54 PM Re: Recalling information from a MySQL database with PHP...Help...
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Quote:
how to I initiate the specific database?
I think that a bit of semantic is needed here, to all speak about the same thing.

First, you have the database server.
A database server can hold several databases, depending of the hard disk size allocated for them.

The databases server can contain several databases. A database is a logical entity, that holds a set of datas.

In a database, you have tables.
A table is the container of informations, where you define which column will hold which type of informations.

In that table, you will record, update or deletes rows, or records.

So, when you ask
Quote:
how to I initiate the specific database?
, I presume that you ask
Quote:
How does the site knows which tables to use?
.
And the answer is : It don't know.
It's up to you to explain in every details what the server should do of which datas, how to handle them and what to do with them.

Expanding what Stoot told you, you have to get back the information passed in the url (the GET parameter) that specify which user to load:
PHP Code:
<?php
if (isset($_GET['schoolId'])){
  
$schoolId=trim(addslashes($_GET['schoolId']));
}
else{
  
//we detect that no school id is given
  
$schoolId=FALSE;
}

if (
$schoolId!==FALSE){
  
//we only do something on the db it the id is passed
  
$q="select * from table where schoolId=$schoolId";
  
$res=mysql_query($q);
  while(
$obj=mysql_fetch_object($res)){
    
//we receive the row from the db, and use it
    
$html=<<<html
School informations:<br/>
&nbsp;&nbsp;name:
{$obj->name}<br/>
&nbsp;&nbsp;address:
{$obj->address}<br/>
&nbsp;&nbsp;city:
{$obj->city}<br/>
<hr/>
html;
    echo 
$html;
  }
}
else{
  echo 
"you haven't specified any shool.";
}
And this, will display the name, address and city (imaginary fields, of course) from the db if a shoolId parameter is given.
If no schoolid parameter is given, a simple message is displayed to the user.

You have a starting point, now you have to determine exactly what to do with your page.
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Reply     « Reply to Recalling information from a MySQL database with PHP...Help...
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.54989 seconds with 12 queries