Please login or register.

Login with username, password and session length
Advanced search  

News:

Latest sNews - sNews 1.7 - with its own forums - for discussion and user mods.

Author Topic: Making a table set in DB  (Read 2022 times)

Patric Ahlqvist

  • Nobodys perfect, but Im pretty effing close
  • ULTIMATE member
  • ******
  • Karma: 65
  • Posts: 4867
  • I'm a self-made man and worships my creator.
    • p-ahlqvist.com
Making a table set in DB
« on: November 19, 2009, 12:21:13 PM »

1. Ok, trying to... pick up on something that was there sometime ago, but now has vanished. I have this piece of code to pick up data from a download table and present it, but I've managed to delete the table itself. Is there anyone who understands PHP enough to see how this table was built ?

Code: [Select]
<div id="thumb_con">
<?
$query = "SELECT * FROM download ORDER BY downloads DESC LIMIT 8";
$result = mysql_query($query);
while ($r = mysql_fetch_array($result)) {
echo "<div class='thumbs'><a href=\"download.php?file=".$r['filename']."\">".$r['title']."
(".$r['downloads'].")<br />
<img src=\"../" . $r['thumb'] ."\" alt=\"\" /></a> </div>";
}
?>

<?
$query = "SELECT SUM(downloads) as bloody_hell FROM download";
$result = mysql_query($query);
while ($r = mysql_fetch_array($result)) {
echo " <div class='thumbs_tot'><a href='#' title=''>Of total (".$r['bloody_hell'].") downloads</a></div> ";
}
?></div>

Or am I shitting in the fan ;)

2. I have a download folder which contains olden goldies. I would like to be able to dl from it using download.php:
Code: [Select]
<?
$file = $_GET['file'];
/* specify path containing files */
$download_path = '/download/';

/* set up mysql connection */
include("inc.mysql.php");

if (!empty($file)) {
  /* query database */
  $result = mysql_query('SELECT filename FROM download');

  /* check each row for filename and send file via http header */
  while ($row = mysql_fetch_assoc($result)) {
    if ($row["filename"] == $file) {
      $result = mysql_query("UPDATE download SET downloads=downloads+1 WHERE filename='" . $file . "'");
      header('Location: ' . $download_path . basename($file));
    }
  }
}
?>

and inc.mysql.php:
Code: [Select]
<?
/* mysql data */
$db_host = "localhost";
$db_user = "user";
$db_pass = "pass";
$db_name = "db_name";

/* connect to mysql */
$link = @mysql_connect($db_host, $db_user, $db_pass);

/* select database */
mysql_select_db($db_name, $link);
?>

But I can't get it to work... Please anyone :(
« Last Edit: November 19, 2009, 12:40:40 PM by Patric Ahlqvist »
Logged
"It's only dead fish that goes with the flow... "
Updated

centered

  • Guest
Re: Making a table set in DB
« Reply #1 on: November 19, 2009, 12:49:51 PM »

Just a guess:

create table download (
title varchar(200) NOT NULL,
filename varchar(255) NOT NULL,
downloads integer(8) DEFAULT NULL,
thumb text,
);
Logged

Patric Ahlqvist

  • Nobodys perfect, but Im pretty effing close
  • ULTIMATE member
  • ******
  • Karma: 65
  • Posts: 4867
  • I'm a self-made man and worships my creator.
    • p-ahlqvist.com
Re: Making a table set in DB
« Reply #2 on: November 19, 2009, 12:55:36 PM »

Thanks, Jase will have a looksie and play some... D'ya have a guess on the other question aswell ? It should really have been number one ;)
Logged
"It's only dead fish that goes with the flow... "
Updated

Patric Ahlqvist

  • Nobodys perfect, but Im pretty effing close
  • ULTIMATE member
  • ******
  • Karma: 65
  • Posts: 4867
  • I'm a self-made man and worships my creator.
    • p-ahlqvist.com
Re: Making a table set in DB
« Reply #3 on: November 19, 2009, 01:11:50 PM »

Nope, MySQL code had errors in it... Trying some more, hehe... Fun, this, but oh, so slow learner I am... AND I needed answers to both questions of course... One can't work without the other... silly me.
Logged
"It's only dead fish that goes with the flow... "
Updated

centered

  • Guest
Re: Making a table set in DB
« Reply #4 on: November 19, 2009, 01:27:17 PM »

Well it was a guess. You can enter the column in phpmyadmin asnd do the rest
Logged

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6019
  • Semantically Challenged
    • snews.ca
Re: Making a table set in DB
« Reply #5 on: November 19, 2009, 06:31:43 PM »

Well it was a guess. You can enter the column in phpmyadmin asnd do the rest

Patric... replace the smilie with 8) so that it looks like this - downloads integer( 8 ) DEFAULT NULL, but with no spaces between the brackets and the 8. (in case you didn't catch that)  ;)
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

centered

  • Guest
Re: Making a table set in DB
« Reply #6 on: November 19, 2009, 06:42:36 PM »

Code: (From PHPMYADMIN) [Select]
CREATE TABLE `download` (
`id` INT( 8 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`title` VARCHAR( 200 ) NOT NULL ,
`filename` VARCHAR( 255 ) NOT NULL ,
`downloads` INT( 8 ) DEFAULT NULL ,
`thumb` MEDIUMTEXT NOT NULL
);
Logged

Patric Ahlqvist

  • Nobodys perfect, but Im pretty effing close
  • ULTIMATE member
  • ******
  • Karma: 65
  • Posts: 4867
  • I'm a self-made man and worships my creator.
    • p-ahlqvist.com
Re: Making a table set in DB
« Reply #7 on: November 19, 2009, 09:01:01 PM »

Thanks, jase... Try that I will...

did catch that, btw, hehe... The last line, though, I did wrong.
Logged
"It's only dead fish that goes with the flow... "
Updated

Patric Ahlqvist

  • Nobodys perfect, but Im pretty effing close
  • ULTIMATE member
  • ******
  • Karma: 65
  • Posts: 4867
  • I'm a self-made man and worships my creator.
    • p-ahlqvist.com
Re: Making a table set in DB
« Reply #8 on: November 20, 2009, 09:05:11 AM »

Thanks Jase... That did the trick... Now I have succeeded in adding content to that table. So far so good.

Oupsie.... Now I'm able to download via a link looking like this:

Code: [Select]
<img src="img/patric_7.jpg" title="patric_7 - A ver 1.4 design" alt="" /><br />
<a href="http://p-ahlqvist.com/download.php?file=patric_7.zip">get it....</a>

Goodie, Jase... Thanks a bunch.
Logged
"It's only dead fish that goes with the flow... "
Updated