PDA

View Full Version : Mental block for PHP


borzoid
10-06-2005, 01:16 AM
Greetings,

I've worked with software that uses php for sometime now and in editing it and rearranging things I've become fairly comfortable about the principles behind a lot of the coding.

Now I want to write some functions of my own. I've been reading tutorials until I'm blue in the face and the simple functions shown in the tutorials were pretty understandable. But then I tried to go on and learn the code to do what I want and have been totally overwhelmed with the tons of stuff I've read - most of which didn't make sense to me.

So hopefully someone here can tell me if what I want to achieve is possible and give me a bit of a start so I can break this mental block about learning php.

I have 3 tables

table: Animals
fields: animal_id, titles_prefix, name, titles_suffix, DOB, breeders, sire_id, dam_id

table: Sires
fields: sire_id, animal_id //the animal_id is that of the parent not the child

table: Dams
fields: dam_id, animal_id //the animal_id is that of the parent not the child

What I want to do is for the selected animal from table: Animals echo the animals information on two lines (concatenating the name and two titles fields) and then setting the sire_id and dam_id as variables to be used in the next instance of the function.

The next instance of the function would use that variable to find the animal_id for the sire or dam and print their information and set their sire_ids and dam_ids as new variables. As I understand it each instance of the function would need to use a different variable name to all work on the same page (sire, gsireS, gsireD, dam, gdamS, gdamD, etc...) - as you can guess I'm trying to write a simple pedigree. I don't need to be able to search backwords from parent to child, just display each successive generation.

Does this make sense and is it possible.

Thank you in advance. I would be greatful for any push in the right direction so I can say "doh....that's how that works"

connie

Tynan
10-06-2005, 11:11 AM
the tables are in MYSQl or such like I assume

seems straightforward enough to me, not that I'm better than basic in this

Using the info supplied from the user, use php to build a query to the database to pull out the info you want from the other two tables that's linked to the info you've been given

use php to manilupate that data to give you the output to screen you need

Relatively straightforward stuff with all respect, not sure that it's a function as such, more a simple html/php page with a form that returns some text after running a query to the database

look up some simple php MYSQL tutorials I'd have thought, good to learn it from the ground up

HTH

Tynan
10-06-2005, 11:18 AM
get it working for one generation first is my advice, once you've mastered that the further generations bit will be a matter of adding a bit of a loop after changing the variable to the id of the next animal to search for

rush4hire
10-06-2005, 08:47 PM
Everything you need is like:
here
http://www.w3schools.com/
and here
http://www.php.net/manual/en/

Concerning databases and PHP, I like these references:
http://www.php.net/manual/en/ref.uodbc.php
http://www.php.net/manual/en/ref.mysql.php
http://www.w3schools.com/sql/default.asp


Esp odbc, cause it's all ready to go on microsoft.

borzoid
10-06-2005, 09:14 PM
Thank you all for the input and references. Every little bit helps.

It does seem relatively simple to me as well. That's what got me thinking that maybe "I" could do it. I'm okay with the select from the database, the echo and concatenate, and even setting the variable the first time.

What I'm having a hard time figuring out is that when I'm toward the end of the pedigree and I set $gggsireS = sire_id, there will be several instances of sire_id on the page. Do I have to write something special to ensure that it selects the sire-id from that particular instance of the function?

Also If I put the function in one cell and use it to set the variable how do I pass the variable to the next cell. Is this a case of global variables? (another topic not addressed clearly in the tutorials I've read).

The individual function is relatively simple - it's how it will all go together with the multiple instances in one page. I have been told that it may be better to write it as a class but I'm definitely not that far yet.

Again, thanks for your help.

Connie