PDA

View Full Version : HEPS ME with MySQL and stuff prz


Chojin
Dec 28th, 2006, 08:56 PM
Okay so I have this site: http://www.erickandemily.com

How would I go about making a real live database to store the reviews and automatically generate tables like the one on the front page?

Also, I'm currently hosted with 100megswebhosting, but I found this other group, bluehost.com (http://www.bluehost.com/tell_me_more.html). Their offer is:

200 GB Storage
2,000 GB Bandwidth/mo
50 MySQL databases

Among other things, for something stupid like $7.95/mo, but you have to pay a year in advance. Their website looks a little sketchy though, and having to pay for a year up front screams 'scam' at me. The whole thing sounds a little too good to be true, as my current host is comparatively cheap and is charging me $40/mo for 240GB bandwidth.

Looking at archive.org, the site was founded in 2000 as some crazy dotcom virtual office bullshit, then stolens away in 2003 by its current owner, who's been doing web hosting since then.

What do you guys think? And please answer both questions: HOW MYSQL DATABASE DURR and BLUEHOST SCAM?

kahljorn
Dec 28th, 2006, 11:42 PM
:throwshepatitisfecesinyourface!

Chojin
Dec 29th, 2006, 10:03 PM
HEPS ME METULMILISHA

MetalMilitia
Dec 30th, 2006, 12:30 PM
Assuming the server supports PHP you should be able to access something like 'phpmyadmin' which allows you to create and edit a database and the tables within your database.

Once you have the database set up it's suprisingly simple to grab data out of the database and format it however you want.

Here is a page I made some time ago while I was learning how to do it:

The following code is for the main news page


<link rel="stylesheet" type="text/css" href="style_main.css" media="all" />

<html>
<body class="section-1">
<?php
include 'head.php';

include 'tabMenu.php';

include 'newsContent.php';
?>
</body>

</html>

As you can see it's basically just the head with whatever crap you want in there, then the code for the menu and finally the code for adding news to the page.

The 'newsContent.php' file contains all the code to perform the following actions:

1. Set up the database connection string
2. Select the database we wish to access
3. Create a query
4. Perform the query
5. Copy the results into an array
6. Format and output whatever parts of the array we want to use


1. Set up the database connection string


$dbcnx = mysql_connect("servername e.g. localhost", "username","password"); //set up our connection string

//Do some validation here to check the connection succeeded


2. Select the database (inc. validation)



if (! @mysql_select_db("databasename", $dbcnx) ) //select a database, if we cannot find it generate an error. note: @ disables php errors and lets us use our own
{
echo( "

Unable to locate the tablename database at this time.</p>" );
exit();
}



3. Create the query


$query=" SELECT * FROM news ORDER BY dateSub DESC ";


This would select all items from the news table and order then by the datesubmitted field (DESC reverses the resutls so you get the newest items at the top)

4. Perform the query


$result=mysql_query($query);


This will just pull all selected data out of the database and put it in the variable; "result".

5. Copy the results into an array & 6. Format and output whatever parts of the array we want to use


while($thenews = mysql_fetch_array($result))
{
echo " <div class='newsitem'> ";
echo "<div class='header'> $thenews[title] ('index.php?id=article&artid=$thenews[ID]') </div>";
echo "

$thenews[synop] </p>";
echo "

Posted by $thenews[authName] at $thenews[dateSub] </p>";
echo "</div>";
}


Here loop through all of our results (a while loop will keep going while a certain critera is true, in this case the critera is that we still have results to be processed. Once where are no more records to output the loop will finish) copying the data into another variable; 'thenews'.
We then output the contents of this variable with formatting information. In this example the CSS class 'newsitem' contains code to put a box around all the content so each news item appears to be a seperate object.
The next interesting part is where you create a link to the whole article in the title of the news item (assuming that's how you want the site to work). In the link it is important that we insert the article's ID so when we click the link we can have some simple PHP code to read the info from the URL, query the database for the article with a corrisponding ID and display this article in a new page.

The way I have set up my table is to have a synopsis field which the article's author writes when they submit the article. You could have some clever code which extracts, say, 100 words from the article's main content and displays that but I couldn't be arsed when I wrote this.

Here is what it looks like when it's opened in a browser:

http://img.photobucket.com/albums/v37/176659.9/newsArticle.jpg


Now you need the following things:

1. Code to limit the number of articles per page/create new pages when the number of articles increases

2. A login system (for content contributors to use)

3. A webform which allows you to insert data to the database


I'm really new to PHP (I've only ever made this one site and never finished it as I had too much else on) so take all this info with a grain of salt. This may not be the best way of doing it but it seems to work well.


Oh, and I don't know about the web hosting company. I think there are probably web host review sites floating around the net. Check those out.

whoreable
Dec 31st, 2006, 11:50 PM
i have had bluehost like a year now, its pretty ok. they do have phpmyadmin

and you could code that shit like metal milita showed, or just look for an already made script to change from sourceforge.

sadie
Jan 1st, 2007, 11:56 PM
i don't know crap about this stuff, but hello to whoreable!

FartinMowler
Jan 1st, 2007, 11:59 PM
I'm completely shitfaced :|

Chojin
Jan 6th, 2007, 02:24 PM
Thanks metal, I'll look into that when i have more time.

Whoreable, how does their speed compare with other hosters? Do they monitor content at all? Could I just host a shitfuckton of videos there and link remotely to them?

Chojin
Jan 17th, 2007, 06:01 PM
Metal, how do I set up the database's values for "authname", "datesub", etc.?

As in, how do I add those categories and then put entries under them?

MetalMilitia
Jan 17th, 2007, 07:25 PM
You need to open PHPMyAdmin ('servername/phpmyadmin' should work if it's installed). It should look like this:

http://img.photobucket.com/albums/v37/176659.9/phpmyadmin.jpg

Then you can just put a database name into one of the places I circled and click create.

You'll then see this screen:

http://img.photobucket.com/albums/v37/176659.9/phpmyadmin2.jpg

Where you can add a table with however many fields (columns) you want.

The rest is pretty self explanitory.

Phpmyadmin takes a bit of getting used to but you should be able to pick it up quickly.

If it's not installed on your server you should have something similar which will do the same thing.

Chojin
Jan 18th, 2007, 12:04 PM
Yeah, I've got cpanel, so I'll try that when I get home today.

Also, is it possible to do a php include on a txt file, but only have it return a certain number of characters instead of the whole document?

MetalMilitia
Jan 18th, 2007, 07:48 PM
Yeah should be.

Take a look at this: http://www.tizag.com/phpT/fileread.php

AChimp
Jan 18th, 2007, 11:36 PM
You can do that, but file I/O on webservers can be dangerous. :(

Chojin
Jan 20th, 2007, 04:06 PM
Okay I'm starting to get a better hang of PHP and MySQL.

I now have a lil form that I made where I fill out information:

http://www.i-mockery.com/chojin/wksubform.jpg

And it outputs to an archive file:

http://www.i-mockery.com/chojin/wkresform.jpg

Most of these don't have 'description' information, so that's why that's missing. But the error there is from when I try to output the 'Favorite' information. On the input form, the favorite is defined like so:

<label for="favorite">Favorite Kitty?</label></td><td><input type="checkbox" value="favorite" name="favorite[]" id="favorite" />

and previous to that in the same file, (excerpted)

$favorite = htmlspecialchars(strip_tags($_POST['favorite']));
...
$sql = "INSERT INTO wiikitty_archive (timestamp,catname,location,catfilename,favorite,d escription) VALUES ('$timestamp','$catname','$location','$catfilename ','$favorite','$description')";

and finally in the result file:

<?php foreach ($favorite as $f) {echo $f;} ?>

and that produces the above error. When I change that last bit of code to:

<?php echo $favorite; ?>

then I get this:

http://www.i-mockery.com/chojin/wkresform2.jpg

Where it just says 'Array' on the favorited WiiKitties. ("First submitted WiiKitty" is the description info)

So, how do I make it show the checkbox information?

Also, due to an oversight on my part, it wasn't adding the favorite information until that cat in the upper left. How would I go into the database manually to add that? Or to fix anything, really? I have phpMyadmin.

FartinMowler
Jan 20th, 2007, 04:30 PM
I never got a thanks for promoting your Wiikitty site :/

Chojin
Jan 20th, 2007, 04:46 PM
i wasn't aware you did that.

Chojin
Jan 20th, 2007, 04:54 PM
also thanks to metal and chimp for helping me THUS FAR!

Chojin
Jan 20th, 2007, 07:11 PM
oaky a friend of mine helped me out already. at the top of the entry page I had to change it to:

if(isset($_POST['favorite'])) $favorite = 'y'; else $favorite = 'n';

and i had to take out the []s in the name variable so that it would no longer be an array.

Now, how do I password-protect a file or folder? I don't want other people to use my wiikitty submitter app.

AChimp
Jan 21st, 2007, 10:20 AM
I think that if you assign a value attribute to the checkbox, it will return that value rather than the name of the checkbox. Either way, just outputting the checkbox won't really display what you want.

Your friend is correct. You need to check for the checkbox value, then do something based on that value (or no value) with an if-statement.

Password protecting a folder can probably be done through your host. It's safest to do it at the server level rather than making a complicated login system. You should check out what kinds of things they offer in their control panel thing.

Chojin
Jan 21st, 2007, 12:44 PM
Cool! All right! Cool cool! All right!

I think I'm out of questions! Thanks, everybody!

MetalMilitia
Jan 22nd, 2007, 04:51 AM
also thanks to metal and chimp for helping me THUS FAR!

Anything to get more pictures of cats onto the Internet! :love :p

Chojin
Jan 22nd, 2007, 07:21 AM
BTW you can see the fruits of these labors on http://www.wiikitty.com/wiikitties.php ;>