TeamPhotoshop
Reviews, updates and in depth guides to your favourite mobile games - AppGamer.com
Forum Home Latest Posts Search Help Subscribe

just got mysql but I dont know what to do

Page: 1 2 Reply
Sep 8th 2003#121050 Report
Member since: Apr 12th 2001
Posts: 27
Hi there.
Good advice from Marble there

It seems like you need to sit down and think a bit about this a bit in order to separate data-storage, serverside code and presentation code before you start to code.

Print this tutorial: http://www.gurusnetwork.com/tutorials/php/dynamic_php_mysql_1.html

Now sit down and go through it together with your favourite brew

It covers the database, the SQL, the PHP and the HTML for a simple example site that holds all content in a very simple database plus it gives you a web interface to admin your content as well.

It's a really basic approach and it explains it all from beginning to end. If you use it online it's riddled with links to the best tool you will ever find, the PHP online manual.

Yes, I'm biased, I did after all write it
However, I've gotten positive feedback from several readers so I guess it might help you as well.
Good luck/Dan
Reply with Quote Reply
Sep 8th 2003#121060 Report
Member since: Mar 29th 2003
Posts: 1326
Yeah I use SmartFTP so I'll make some directories and make my connection file. Then I'll check out that tutorial and see how much easier it might make this process. It sounds like a good example, but I might take you up on your example, too, Marble. We'll see. Thanks both of you for your help.

tom
Reply with Quote Reply
Sep 8th 2003#121090 Report
Member since: Mar 29th 2003
Posts: 1326
OK I read through the first page of your tutorial and it seems fairly simple but it does not relate to what Marble was talking about. I did not know that I had any MySQL installed on my machine or that it was needed. I thought that all the work I was doing would be through coded PHP pages on my server.

You mention a PHPMySQL-admin program but you don't say that its neccesary. Do I have to do all this stuff at the DOS prompt, Marble? I want to learn it well, with no shortcuts (downloaded files, helper programs, etc.).

I guess the problem I'm having is that every place I've been has a different way of doing it. It seems that your way, Marble, is the cleanest and purest way of doing it, which results in a better knowledge of how it all works.

Thanks again.

tom
Reply with Quote Reply
Sep 8th 2003#121091 Report
Member since: Nov 26th 2001
Posts: 2586
DmS - one thing I would add in your SQL create table is with the id - add PRIMARY KEY. It's essential to get used to creating primary keys with relational databases. There should always be one field (or more if a composite key) that is numeric and a unique identifier (which you have) but should be designated as a 'primary' identifier. mySQL is a bit looser with keys (and mySQL doesn't use foreign keys - yet), but other databases aren't as lenient and its good practice to instinctly use them.

But it is looking real sweet DmS.... I still have to read through it all. Good one to print out.

He does do something similar, but different - trhaynes. He uses functions more than I do. I use includes for the connection, but either way works just fine. There may be an advantage to using functions that I am not aware of.
Reply with Quote Reply
Sep 8th 2003#121098 Report
Member since: Nov 26th 2001
Posts: 2586
So for retrieving data from a database:
1. you connect (thus $objConn)
2. you create a query (example):
[PHP]$strSQL_example = "SELECT sm_name, sm_year FROM table_single_malt ORDER BY sm_year ASC";[/PHP]

This would take the fields sm_name and sm_year from the table table_single_malt, and then put them in order by year youngest to oldest (ASC --> reverse order, DESC default - which is reverse)

Then if you want to display the data:
[PHP]$objSM = mysql_query($strSQL_example, $objConn);[/PHP]

So now you use your SQL and the connection to retrieve the data. If your SQL was an insert command you would insert the data (using an html form).

Now there is a php mysql array function if you are listing more than one item (useful for like news or displaying a list of things, or listing shoutbox replies.... etc.) and use a loop (while works fine.) to display it in a table:

[PHP]
print "";
while($smArray = mysql_fetch_array($objSM)){
$name = $smArray['sm_name'];
$year = $smArray['sm_year'];
print "";
}
print "
";
print "Brand: ".$name." is from ".$year."";
print "
";
[/PHP]

mysql_fetch_array is a handy little function that retrives the info and puts it into an array, then you create variables for each item in the array.

That is just a simple little query that will loop through each brand of scotch and display the result in a table - note I put the table tags outside the loop, so it only repeats rows and columns for every brand I have in the database.

Now to view shouts stored in a database (for example), just create a query to get them all, order by number or something (if you want to), then loop and display all of them. So when someone clicks "View All Shouts" you are using a simple little php page to display them.
Reply with Quote Reply
Oct 9th 2003#124237 Report
Member since: Apr 12th 2001
Posts: 27
Been away for a while, hence slow on reply...

Thanx for the comments Marble
I know it's off topic a bit, but the sql parts is in there for one purpose only, to get started. Even a site this simple should have a real database design, not a simple table. That however is way beyond the scope of that tutorial

And the functions, the reason why I use functions so much is to introduce a programming style that separates the sites design (html) from the php-code as much as possible. Call it the first steps toward OOP-programming.

I've got another tutorial in approval stages as a step 2 of this one where I go through the basics of OOP in PHP on the exact same functionality, that's when the separation of logic and html relly starts to make sense.

trhaynes
How is it going?
Have you gotten anything running yet?

As for the dos-prompt, no, you usually don't have to use dos or shell access to create your database. There are a lot of tools out there that will help you. Most hosts that offer MySQL also offers PHPMyAdmin as a tool for you to use as well.

But if you really want to get down and dirty ;) learn to do it at the prompt, that will always be there for you.

As for coding inside the HTML, in includes or in functions, that's up to you. As you start you need to get the very basic stuff down and whatever way that you feel good with is fine to start with.
/Dan
Reply with Quote Reply
Oct 12th 2003#124535 Report
Member since: Aug 7th 2002
Posts: 355
Reply with Quote Reply
Oct 27th 2003#126620 Report
Member since: Mar 29th 2003
Posts: 1326
Yeah I feel bad for making all you guys do all that teaching. I realized that I wasn't qualified to be using MySQL at all, since I had not even learned PHP yet. I have done some simple PHP, and when I get a little better at it, I will be printing out this thread and using it to do some MySQL.

So sorry that I havent replied - your information did not go to waste, however, and I apologize if it seemed that way to either of you. Marble - do you mind if I PM you about a simple (<50 lines) affiliates system (with a text files) that I am working on? Nobody is replying at PHPfreaks, so... If you don't read this in the next couple of days then I will send it anyways.

Thanks again for all your help and I apologize - I guess it was just a little misunderstanding between us.

tom
Reply with Quote Reply
Oct 27th 2003#126626 Report
Member since: Nov 26th 2001
Posts: 2586
Not at all Tom.... I am in a position where I have plenty of time in front of the pc, so I don't mind helping at all. If it's easier you can email me:

[email]john@recordinglair.com[/email]

and identify yourself in the subject for the first email as I am getting a lot of spam on this email lately (and I don't want to accidently delete it.) =)
Reply with Quote Reply
Page: 1 2 Back to top
Please login or register above to post in this forum