cragllo 0 Report post Posted January 3, 2005 (edited) 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 December 20, 2016 by OpaQue (see edit history) Share this post Link to post Share on other sites
FaLgoR 0 Report post Posted January 4, 2005 <?$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". Share this post Link to post Share on other sites
cragllo 0 Report post Posted January 4, 2005 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
FaLgoR 0 Report post Posted January 4, 2005 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
cragllo 0 Report post Posted January 4, 2005 (edited) 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... Edited January 4, 2005 by cragllo (see edit history) Share this post Link to post Share on other sites
FaLgoR 0 Report post Posted January 6, 2005 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
cragllo 0 Report post Posted January 6, 2005 (edited) 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 January 7, 2005 by cragllo (see edit history) Share this post Link to post Share on other sites
FaLgoR 0 Report post Posted January 7, 2005 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
cragllo 0 Report post Posted January 7, 2005 (edited) 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://forums.xisto.com/no_longer_exists/ Edited January 7, 2005 by cragllo (see edit history) Share this post Link to post Share on other sites
FaLgoR 0 Report post Posted January 7, 2005 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
cragllo 0 Report post Posted January 7, 2005 See, im learning now, you forgot the " here: (mysql_error());I added it: (mysql_error()");It was not working, 'Im not as think as you confused I am'lol Share this post Link to post Share on other sites
FaLgoR 0 Report post Posted January 8, 2005 ?????? 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 Share this post Link to post Share on other sites
cragllo 0 Report post Posted January 8, 2005 You have helped me loads! I have learned alot from this...Thank you... I may need you help some time in the near furure...In fact, I have another thread that maybe you can help me with:http://forums.xisto.com/topic/5379-website-made-with-php-help/ Share this post Link to post Share on other sites
cragllo 0 Report post Posted January 13, 2005 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
cragllo 0 Report post Posted January 23, 2005 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