Jump to content
xisto Community
cragllo

Urgent: Need Script Made...

Recommended Posts

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://forums.xisto.com/no_longer_exists/Location : http://forums.xisto.com/no_longer_exists/ And I need to be able to display this in a tabel


<table border="1" cellpadding="0" cellspacing="0">[/br]                <tr>[br]                  <td align="center" valign="top">[/br]<img src="(IMAGE)">[br]                  </td>[/br]                  <td width="397" align="left" valign="top">[br]<font size="2" face="Arial"><strong>(NEME)</strong><br>[/br](DESCRIPTION)<br>[br]<a href="(LOCATION)">DOWNLOAD</a></font>[br]                  </td>[/br]                </tr>[/br]</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.


Edited by OpaQue (see edit history)

Share this post


Link to post
Share on other sites

<?$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".:rolleyes:

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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 :)

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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 15File not found.Also Ive added two more fields:Preview: for large image previewcreator: to show the authorDoes that make a difference?Also I need a page with a form to add new data...

Edited by cragllo (see edit history)

Share this post


Link to post
Share on other sites

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...

<{POST_SNAPBACK}>


Are you sure you have conected to the database on download.php?

Share this post


Link to post
Share on other sites

let's make insert.php (or something else):<?if($go){ // if var $go is setmysql_query("INSERT INTO table(name,description,image,location) VALUES ('$name','$desc','$image','$location') or die (mysql_error());print "Done!";exit;} else { // not really required at this case but...?><form action="insert.php" method="post">Name: <input type="text" name="name"><br>Description: <input type="text" name="desc"><br>Image: <input type="text" name="image"><br>Location: <input type="text" name="location"><br><input type="submit" name="go" value="Submit"></form><?}?>But don't forget to connect this page with the database. I suggest that you make a new page called conection.php with all the details and connections, and put: include("conection.php"); at the top of the pages which requires an connection.

Share this post


Link to post
Share on other sites

?????? I did never put this " on mysql_error() function o.O and its not really needed, its only to show the errors (if there are error). Put this function or not, the script must work, because the really needed code is before "or die". But now are your script working well or there is any other problem? I hope I've helped you :rolleyes:

Share this post


Link to post
Share on other sites

I am using this code for another of my sites, (Toxic Sims), I have added a new field to the table in the database calles 'type'.

How do I display only the ones with a certain entry in that field? So, say I had 10 records, and 7 of them had the word misc in the 'type' field, how will I display only those 7?
I hope you get what I mean?

Share this post


Link to post
Share on other sites

the download page is not working on my sims website...

global vars is turned off, does that effect the download page?

here it is, download.php

<?$dbhost = 'localhost';$dbuser = ''; // removed for this$dbpass = ''; // removed for this$dbname = 'toxicsims';mysql_connect($dbhost,$dbuser,$dbpass);mysql_select_db($dbname);?><?if(!$id)return;$query = mysql_query("SELECT * FROM objects WHERE id=$id;");$download = mysql_fetch_array($query);if(!file_exists($download[location])){print "File not found.";exit;}mysql_query("UPDATE templates SET clicks=(clicks+1) WHERE id=$id;");header("Location: $download[location]");?>

Would anything need to be added, I had some help off my bros m8 to do the insert page. he added the $_POST bits in for me...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.