Welcome Guest ( Log In | Register)



2 Pages V   1 2 >  
Reply to this topicStart new topic
> Urgent: Need Script Made...
cragllo
post Jan 3 2005, 11:14 PM
Post #1


Sorry for not being active, Uni :(
*********

Group: Members
Posts: 933
Joined: 24-August 04
From: South Wales, UK
Member No.: 892



I need a sort of simple content managment script...

So, I need a mySQL database with the following fields:

Field : example of use

ID : 1
Name : Orange Distster
Description : The best
Image : http://sponk......file.png
Location : http://sponk......file.zip

And I need to be able to display this in a tabel
CODE
<table border="1" cellpadding="0" cellspacing="0">
               <tr>
                 <td align="center" valign="top">
<img src="(IMAGE)">
                 </td>
                 <td width="397" align="left" valign="top">
<font size="2" face="Arial"><strong>(NEME)</strong><br>
(DESCRIPTION)<br>
<a href="(LOCATION)">DOWNLOAD</a></font>
                 </td>
               </tr>
</table>

And will display these in order, newest to olders, 5,4,3,2,1...


That sort of thing, you get me? if someone could do this for me, I would be that happiers person in the world...

Thank you,
Craig.

This post has been edited by cragllo: Jan 3 2005, 11:15 PM
Go to the top of the page
 
+Quote Post
FaLgoR
post Jan 4 2005, 12:07 AM
Post #2


Super Member
*********

Group: Members
Posts: 217
Joined: 2-January 05
Member No.: 3,084



<?
$query = mysql_query("SELECT * FROM table ORDER BY id DESC");
?>
<table border="1" cellpadding="0" cellspacing="0">
<?
while($var = mysql_fetch_array($query)){
?>
<tr>
<td align="center" valign="top">
<img src="<?=$var[image]?>">
</td>
<td width="397" align="left" valign="top">
<font size="2" face="Arial"><strong><?=$var[name]?></strong><br>
<?=$var[description]?><br>
<a href="<?=$var[location]?>">DOWNLOAD</a></font>
</td>
</tr>
<?
}
?>
</table>


Try to do it, if its not in the order u want, try to change "DESC" for "ASC".

smile.gif
Go to the top of the page
 
+Quote Post
cragllo
post Jan 4 2005, 04:12 PM
Post #3


Sorry for not being active, Uni :(
*********

Group: Members
Posts: 933
Joined: 24-August 04
From: South Wales, UK
Member No.: 892



ok, im kind of new to mySQL, how does it connect to the database? and what fields do I need to put in?


Also, how can I sho how many times it has been downloaded or how many times the link has been clicked?
Go to the top of the page
 
+Quote Post
FaLgoR
post Jan 4 2005, 05:25 PM
Post #4


Super Member
*********

Group: Members
Posts: 217
Joined: 2-January 05
Member No.: 3,084



Connecting to database:
$dbhost = 'localhost';
$dbuser = 'user';
$dbpass = 'password';
$dbname = 'name';

mysql_connect($dbhost,$dbuser,$dbpass);
mysql_select_db($dbname);

You will have to add the fields name, image, description... just like we have used above.

Note: I have user vars to define the database info, but its not needed.

If you have any other question, post again and I'll try to help you :)
Go to the top of the page
 
+Quote Post
cragllo
post Jan 4 2005, 07:28 PM
Post #5


Sorry for not being active, Uni :(
*********

Group: Members
Posts: 933
Joined: 24-August 04
From: South Wales, UK
Member No.: 892



Ive put it all in and it works fine, other things i wish to know is,

How to dhow how many times the file had been downloaded or the dwnload link clicked... and hoe to display 10 per page...

This post has been edited by cragllo: Jan 4 2005, 08:41 PM
Go to the top of the page
 
+Quote Post
FaLgoR
post Jan 6 2005, 06:24 PM
Post #6


Super Member
*********

Group: Members
Posts: 217
Joined: 2-January 05
Member No.: 3,084



OK, put this code on your page:

<?
$query = mysql_query("SELECT * FROM table ORDER BY id DESC");
?>
<table border="1" cellpadding="0" cellspacing="0">
<?
while($var = mysql_fetch_array($query)){
?>
<tr>
<td align="center" valign="top">
<img src="<?=$var[image]?>">
</td>
<td width="397" align="left" valign="top">
<font size="2" face="Arial"><strong><?=$var[name]?></strong><br>
<?=$var[description]?><br>
<a href="download.php?id=<?=$var[id]?>">DOWNLOAD</a></font>
</td>
</tr>
<?
}
?>
</table>

And now, lets do download.php:

<?
if(!$id)
return;

$query = mysql_query("SELECT * FROM table WHERE id=$id;");
$download = mysql_fetch_array($query);

if(!file_exists($download[location])){
print "Download file not found.";
exit;
}

mysql_query("UPDATE table SET clicks=(clicks+1) WHERE id=$id;");

header("Location: $download[location]");
?>

Don't forget to connect with database and add the column "id" to your database (with auto_increment). If it doesn't work, please post again and i'll look for the problem.
Go to the top of the page
 
+Quote Post
cragllo
post Jan 6 2005, 09:03 PM
Post #7


Sorry for not being active, Uni :(
*********

Group: Members
Posts: 933
Joined: 24-August 04
From: South Wales, UK
Member No.: 892



When I click the link to download it shows the error:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/cragllo/public_html/download.php on line 15
File not found.


Also Ive added two more fields:
Preview: for large image preview
creator: to show the author

Does that make a difference?

Also I need a page with a form to add new data...

This post has been edited by cragllo: Jan 7 2005, 08:33 PM
Go to the top of the page
 
+Quote Post
FaLgoR
post Jan 7 2005, 08:56 PM
Post #8


Super Member
*********

Group: Members
Posts: 217
Joined: 2-January 05
Member No.: 3,084



QUOTE(cragllo @ Jan 6 2005, 06:03 PM)
When I click the link to download it shows the error:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/cragllo/public_html/download.php on line 15
File not found.
Also Ive added two more fields:
Preview: for large image preview
creator: to show the author

Does that make a difference?

Also I need a page with a form to add new data...
*



Are you sure you have conected to the database on download.php?
Go to the top of the page
 
+Quote Post
cragllo
post Jan 7 2005, 09:02 PM
Post #9


Sorry for not being active, Uni :(
*********

Group: Members
Posts: 933
Joined: 24-August 04
From: South Wales, UK
Member No.: 892



My mistake, I fogot to change:

$query = mysql_query("SELECT * FROM templates WHERE id=$id;");


How can I make a form to ad records to the database?



You can see what im doing here: http://sponkindustries.co.uk/templatesfree2.php

This post has been edited by cragllo: Jan 7 2005, 09:03 PM