Jump to content

Need help


Recommended Posts

I need help with 2 things, I have no idea how to do the first is not as important as the second.I have a database display herehttp://www.betterchoiceloans.com/todaysrates.phpHere is my problem, I HAVE to get those things to display all my 0's in the database when I put them in as 3.000, or 2.520 or whatever it always cuts off my zero's, then when I call the data it's still cut, I need the 0's in there, and is there any way to put percentages in there too. THis question isn't as important but I can't finish the project like this, I have to have it display the information and including the final zero's even if it's make zero's appear whenever there are less than 2, for instance if the entry was small, they could throw on the extra zeros to get it the size it needs to be any help would be greatly appreciated.This is the main thing I need to ask this is very important if someone can help I would be forever indebted. I have been at this for almost a month, I have asked but not in a way that could not be understood by me.I have a url here Funny Email ForwardsThat form on that page, I deal with all my file working on that page, here is my current script.

<?php$management = true;$errorhandler = "";$filemanager = true;$dateinfo = strtotime("now");$dateformatted = date("n-d-y", $dateinfo);if ($_POST['name'] == "") {	$errorhandler .= "The Name field has been left blank<br />";	}if ($_POST['keywords'] == "") {	$errorhandler .= "The Keywords were left blank<br />";	}if(!is_uploaded_file($_FILES['file']['tmp_name'])){	$errorhandler .= "No file has been uploaded<br />";	$filemanager = false;	}  if ($filemanager === true) {$_accepted_extensions = array('.mpeg', '.mpg', '.wav', '.avi', '.mid', '.jpg', '.jpeg', '.pdf', '.txt', '.gif', '.mp3');   if ($filemanager == true) {  $tmp = pathinfo($_FILES['file']['name']);  if (in_array('.' . $tmp['extension'],$_accepted_extensions)) {  	$filemanager = true;  	$management = true;  	}else {  	$filemanager = false;  	$management = false;  	$errorhandler .= "You have attempted to upload the wrong file type<br />";  	$errorhandler .= "We only accept mpeg, mpg, wav, avi, mid, jpg<br />";  	$errorhandler .= "jpeg, pdf, txt, gif, and mp3 formats<br />";  	$errorhandler .= "To request new file types email<br />";  	$errorhandler .= "information@theyellowpagesnetwork.com";  	}  }	}    // Relative URL with desired folder name and the name of the file on the user's machineif ($management === true && $filemanager === true) {	$newfile = "uploads/".basename($_FILES['file']['name']);	$newfiletemp = "{$_FILES[file][tmp_name]}";	if (file_exists($newfile)) {  $errorhandler .= "The file already exists";  $filemanager = false;	}	if($filemanager === true) {  if (!move_uploaded_file($newfiletemp, $newfile)) {  	$errorhandler .= "The file was not moved properly";  	$filemanager = false;  	$manager = false;  }	} }if ($filemanager === true || $manager === true) {	$connect = mysql_connect("localhost", "funnyemail", "8Ua^1jv");	$select = mysql_select_db("funnyemailforwards"); if (!$connect && !$select) {  $errorhandler .= "The database could not connect, or selected";  $management = false;  $filemanager = false;	}  }if ($filemanager === true && $management === true) {$query = "SELECT * from fileinfo WHERE type = '" . implode("", $_POST['type']) . "' AND nameoffunny = '" . mysql_real_escape_string($_POST['name']) . "' AND keywords = '" . mysql_real_escape_string($_POST['keywords']) . "' AND funnyurl = '" . mysql_real_escape_string($newfile) . "' AND entrydate = '" . mysql_real_escape_string($dateinfo) . "'";$result = mysql_query($query);$matches = mysql_num_rows($result); 	if ($matches == 0) {$inserter = "INSERT INTO fileinfo (type, nameoffunny, keywords, funnyurl, entrydate) VALUES ('" . implode("", $_POST['type']) . "', '" . mysql_real_escape_string($_POST['name']) . "', '" . mysql_real_escape_string($_POST['keywords']) . "', '" . mysql_real_escape_string($newfile) . "', '" . mysql_real_escape_string($dateinfo) . "')";	if(mysql_query($inserter)){   	$management = true;  	$filemanager = true;  	}else {  	$management = false;  	$filemanager = false;  	$errorhandler .= "The information was not inserted into the database properly";  	echo mysql_error();  	}	} else {  $filemanager = false;  $managment = false;  $errorhandler .= "The information was already in the database, could not complete";	}	}if ($management === false || $filemanager === false) {	echo "{$errorhandler}";	}		?>

Ok here is my problem, I don't understand how to do the followingI have to get every new file download to go intot he folder, all of that already happens, everything is working perfectly so far. I need to add some things, I already know now how to work with the admin page, next week I have to finish this project, the last thing I don't understand, when the files get downloaded, how do I make them accessible through the url's. I need to figure out how to do this, in a way I can understand, I have heard htaccess can do it, I have started going under study for htaccess but it'll still be a few months before I start learning it officially, because I have to finish learning php/mysql to a decent level and I have more mental resources to take on new categories of learning. What I need to do is get this to work, in a way I understand, I don't understand how the files are associated with the download, and how it will add the ability to reach the embedded pages. I also don't understand how to embed, I need to atleast get some help, pointed to some resources, anything, that can help me get this done, would be more than greatly appreciated.

Edited by businessman332211@hotmail.com
Link to comment
Share on other sites

This might help with your first question. I had a similar situation recently and found this function someone had written. I'm so new I don't even remember the details of getting it to work, but it solved my problem. I found it while working through a google search.

function format_number($str,$decimal_places='3',$decimal_padding="0"){       /* firstly format number and shorten any extra decimal places */       /* Note this will round off the number pre-format $str if you dont want this fucntionality */       $str          =  number_format($str,$decimal_places,'.','');    // will return 12345.67       $number      = explode('.',$str);       $number[1]    = (isset($number[1]))?$number[1]:''; // to fix the PHP Notice error if str does not contain a decimal placing.       $decimal    = str_pad($number[1],$decimal_places,$decimal_padding);       return (float) $number[0].'.'.$decimal;}

EDIT: Just located this again. It's in the comments for the number_format function at php.netHope that helps.ojc

Link to comment
Share on other sites

You can also use str_pad to add zeros to the end. You can look that up at php.net.I'm not sure what you mean by this:

when the files get downloaded, how do I make them accessible through the url's
Whem someone uploads a file, and you move it into whatever folder you want it in, you can refer to the filename in the URL. If /index.php moves a file into /files, then you would access it by www.domain.com/files/filename.extI'm not sure if that answers your question or not, but I don't think I understand what the problem is.
Link to comment
Share on other sites

the embedding is diffferent for each type of file. for images, you just use the standard <img> tag, and for movies you use the <object> or <embed> tags. (i'm not sure on the syntax of the object or embed tags, sorry. search for movies in the html section and maybe you will find something)

Link to comment
Share on other sites

You can use whatever file name you want. You can access the original file name in $_FILES[]['name']:http://www.php.net/manual/en/features.file...oad.post-methodOr you can randomly generate a file name or use a hash or something if you want to have a different name. Once you decide on a name, you store the name in the database. Then you get the name back out of the database later on when you need to display the file.If you are having a problem where you upload the file but get a permission denied error when you try to access it, then you probably need to use the chmod function to set the permissions.

Link to comment
Share on other sites

Ok here is specifically what I Don't understand about 2 things.The first is when you speak about imbed, I think I can figure out how to imbed, but I don't understand the concept I don't think. When someone uploads a file my script moves it to a directory, I can even understand having the file named as something specific, like whatever the person put the name as. BUT what I do not understand currently, is when the person comes back to the site to view a funny. There are multiple ways one can be seen, for one an email is sent out to everyone on the list, also there are new links added to the homepage everytime that someone adds a new entry and it is approved. THe thing I don't understand is, how to make specific files embed specifically. How do I make an image file appear as an image in another page, I can get into that other page, and make changes. Because the person isn't accessing the page. Crap this is hard to explain, for instance, a php script on a specific page DOES NOT start working until someone visits the site. If I have a script to display the time, the time is not displayed until someone visits the site, then the script runs at that time and displays the time. The same with my script, not only does it not run if noone visits but they have to actually submit a form to start the process. They fill out the fields on the form, then they upload the file, then they click submit, then the script starts to run, it runs through all validation, and then moves the file. I understand all of that, it can move the file from that script, because the person is on that script, but once the script moves the file to another page, how can that script that ran that specific file, still run when noone visited it. I am expecting I would guess for each music video, or song, or video when someone goes to view it, it's going to be embedded, but how did it get imbedded, this is really hard to explain. Like the script doesn't run unless someone visits it, so if I have a page I Create with the imbed tags and everything, and set it up to recieve the file, I can only set it to recieve one file, that means I have to create each one by hand right, if that is so it requires constant monitering, I think I am explaining it well enough to get across the points I do not fully understand. About the str_pad I think that will help I really appreciate the advice on that, I am doing that today. Thanks.

Link to comment
Share on other sites

You don't have to do anything manually, you have an automatic script that accepts the file and processes it, so why can't you have an automatic script that gets the file and puts it in the page? I think that's the point that people have been trying to make. You need a script that gets the file name, or ID number or whatever, and looks it up in the database, figures out what type of file it is, and puts it in the page however you need to. If it is an image:<img src="{$filename}">Or if it is a movie:<object classid="{$clsid}" type="{$type}" data="{$data}">I don't know the specifics, but hopefully you get the point. You need a view_file.php page that gets information about the file, looks it up, and displays what it needs to.

Link to comment
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...