PHP - Retrieving File Location From Database
Hey all,
I've written a php search feature for a mysql database. The search returns a file name like sample.gif, how would I go about displaying the actual image instead? Since the images all have the same location could I have the search return the string into a variable then make the whole thing a link? Thanks. Similar TutorialsHi guys, I have a file location stored in mysql. when i populate the table i need this file location to be a hyperlink to the file itself, so the visitors can click like a normal link and open the file in word and pdf (both formats stored). example of file location as in db "_private/Incident_Reports/Incident%20-%20Applecross%20-%2017%20December%202010%20-%20Website.doc" example of php code Code: [Select] echo $row['word_document']; any ideas would be really appreciated. Code: [Select] $query = mysql_query("SELECT a.*, b.* FROM friendlist a INNER JOIN friendlist b ON (a.friendemail=b.friendemail) INNER JOIN users c ON (b.friendemail = c.EmailAddress) WHERE a.email = 'asdf@gmail.com' AND c.Username LIKE '%carol%' GROUP BY a.id ORDER BY count(*) DESC"); Code: [Select] while ($showfriends = mysql_fetch_array($query)) { echo $showfriends['Username']; } and I would get nothing. It produces the correct number of <div> so i know it's getting through, but it's having trouble displaying the entries? I have my database set to insert the current time stamp when an entry is made into the table, I am then trying to retrieve via the following code: $select_view_idea="SELECT * FROM $tbl_name5 WHERE message_number='$message_number'"; $result_view_idea=mysql_query($select_view_idea); while($row_view_idea=mysql_fetch_assoc($result_view_idea)){ extract($row_view_idea); } date_default_timezone_set('US/Eastern'); $date=date('l, F jS Y h:i:s A T', $date); echo $date; The above is outputting: Wednesday, December 31st 1969 07:33:31 PM EST the database contains: 2011-11-18 00:47:56 Hi, I have managed to get the code working to store a .jpg file in the database under the longblob type. Now all i have left to do is to retrieve that image and display it. So far i have this: list.php Code: [Select] while($r = mysql_fetch_array($sql)) { //for each record ... echo " <img src= getoutside.php?id='".$r[apartmentId]. " '> "; getoutside.php Code: [Select] <?php header("Content-type: image/jpg"); // act as a jpg file to browser $nId = $_GET['id']; include 'dbase.php'; //connect to database $sqlo = "SELECT outside FROM apartment WHERE apartmentId = $nId"; $oResult = mysql_query($sqlo); $oRow = mysql_fetch_array($oResult); $sJpg = $oRow["outside"]; echo $sJpg; ?> The result from this is a box with a red cross in it. Can anyone find a problem with this code please? Thanks I am working on a kind of CMS for my own website which no one else will be using but me as a way of improving my php skills, and am having problems with retrieving data from the database that holds both text and php code. I have searched the web and found that i should be using eval() for the code to be executed before it is send to the browser but cannot get it to work and can't find my mistake(s). the php code will always be the same, and is supposed to retrieve the id number of a page to use in a link (and works fine when tested by loading the code directly without retrieving it from the database) this is an example of data stored in the database Code: [Select] The <a href="page_builder.php?id=<?php echo $page->id('mines_DwarvenMines') ?>">Dwarven Mines</a> have a great selection of Ores,... Of course when I leave it like this, hovering over the link in my page will show exactly that and lead to nowhere Code: [Select] localhost/page_builder.php?id=<?php echo $page->id('mines_DwarvenMines') ?> Most of these links appear in tips given at the end of the page and are processed as followed Code: [Select] $questtips = $quest->getQuestTips(); $tips = ""; if ($questtips == "none") { $tips = "/"; } else { foreach($questtips as $tip) { $tips .= "<li>"; $tips .= $tip->getTip(); $tips .= "</li>"; } } and finally put on screen by the presentation layer as followed Code: [Select] <h2>Tips & Extra Info</h2> <div class="tipsList"> <ul> <?php echo $tips ?> </ul> </div> I have tried all sorts to get the code to be executed when retrieved from the database before being send to the browser so that this particular link would say "localhost/page_builder.php?id=57" but I cannot get it to work, though I suspect it is fairly easy. I suspect I would have to store the data in a different format in the database? And how exactly do I use the eval() function in my case? Could someone please adjust my code so that it does work? Thanks Hello people, currently i ran into some problem. Currently, i have a database called responses which have the fields of ID, Student_id, question_id, Answer. I had stored my results into the database which appeared to be 1 1 1 Agree 2 1 2 Disagree 3 3 4 Unsatisfied. So any recommendation on how should i do about in generating the result into a graph whereby the graph will show how many students choose "AGree" on that particular question THANKS I have two tables. Table Name:Users Fields: User_name user_email user_level pwd 2.Reference Fields: refid username origin destination user_name in the users table and the username field in reference fields are common fields. There is user order form.whenever an user places an order, refid field in reference table will be updated.So the user will be provided with an refid Steps: 1.User needs to log in with a valid user id and pwd 2.Once logged in, there will be search, where the user will input the refid which has been provided to him during the time of order placement. 3.Now User is able to view all the details for any refid 3.Up to this we have completed. Query: Now we need to retrieve the details based on the user logged in. For eg: user 'USER A' has been provided with the referenceid '1234' during the time of order placement user 'USER B' has been provided with the referenceid '2468' during the time of order placement When the userA login and enter the refid as '2468' he should not get any details.He should get details only for the reference ids which is assigned to him. This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=309239.0 Basically i have a folder with 100+ images they are NOT all the same extension, what im wanting to do is use PHP to find all the images and put them all in a database. how would i go about doing this? thanks This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=318312.0 I have two tables. Table Name:Users Fields: User_name user_email user_level pwd 2.Reference Fields: refid username origin destination user_name in the users table and the username field in reference fields are common fields. There is user order form.whenever an user places an order, refid field in reference table will be updated.So the user will be provided with an refid Steps: 1.User needs to log in with a valid user id and pwd 2.Once logged in, there will be search, where the user will input the refid which has been provided to him during the time of order placement. 3.Now User is able to view all the details for any refid 3.Up to this we have completed. Query: Now we need to retrieve the details based on the user logged in. For eg: user 'USER A' has been provided with the referenceid '1234' during the time of order placement user 'USER B' has been provided with the referenceid '2468' during the time of order placement When the userA login and enter the refid as '2468' he should not get any details.He should get details only for the reference ids which is assigned to him. Hi There all, having an issue with simple xml... hopefully someone will be able to shed some light on this. I have this data in an xml feed from an API: <ID>job no 1 </ID> <Name>job name</Name> <State>job status</State> <Tasks> <Task> <Name>task name 1</Name> </Task> <Task> <Name>task name 2</Name> </Task> <ID>job no 2</ID> <Name>job name</Name> <State>job status</State> <Tasks> <Task> <Name>task name 1</Name> </Task> <Task> <Name>task name 2</Name> </Task> I would like to display these in a table pretty much as it is shown above. Job no 1 job name job status job 1 task name 1 job 1 task name 2 Job no 2 job name job status job 2 task name 1 job 2 task name 2 etc my code looks like this : $required is narrowing down specific states not shown for clarity $xml_current=simplexml_load_string($jobs_task_response) or die("Error: Cannot create object"); foreach($xml_current->Jobs->Job as $item_current) { if (in_array((string)$item_current->State, $required)) { $projects_current[] = array( 'job_no' => (string)$item_current->ID, 'job_name' => (string)$item_current->Name, 'job_status' => (string)$item_current->State, ); foreach($item_current->Tasks->Task as $current_tasks){ $projects_task[] = array( 'job_tasks' => (string)$current_tasks->Name, ); } } } foreach ($projects_current as $proj_current) { $job_no =$proj_current['job_no']; $job_name =$proj_current['job_name']; $job_status =$proj_current['job_status']; $clr_current = $colors[$job_status]; $project_id = $job_no; $tdata_1 .= "<tr id='current' class='card-body collapse-show'>"; $tdata_1 .= "<td class='th-sm-1 bg-white '><a href='../details/index.php?pid=$job_no' class='text-left ml-1'>$job_no</a></td>"; $tdata_1 .= "<td data-target='#" . $job_no . "' data-toggle='collapse' class='th-sm-2 bg-white text-left ml-1'>$job_name</td>"; $tdata_1 .= "<td class='th-sm-2 " . $clr_current . " text-left ml-1 '>$job_status</td>"; foreach ($projects_task as $proj_tasks){ $job_tasks =$proj_tasks['job_tasks']; $tdata_1 .= "</tr>"; $tdata_1 .= "<tr id='" . $job_no . "' class='card-body collapse'> "; $tdata_1 .= "<td class='th-sm bg-white text-left ml-1'></td>"; $tdata_1 .= "<td class='th-sm bg-white text-left ml-1'></td>"; $tdata_1 .= "<td class='th-sm " . $clr_current . " text-left ml-1'>$job_tasks</td>"; $tdata_1 .= "</tr>"; } } what I get with this code however is; Job no 1 job name job status job 1 task name 1 job 1 task name 2 job 2 task name 1 job 2 task name 2
Job no 2 job name job status job 1 task name 1 job 1 task name 2 job 2 task name 1 job 2 task name 2
I'm sure there is a simple answer to this, I just can't seem to put my finger on it. Can anyone help please? Much appreciated thanks in advance! The subject could be a bit vague, but my problem is simple. (I think so) So I made a php test site that is quite similar to a forum. Where you see a title or a subject and when you click on it you will see more details about that subject. I made my database and script for inserting data into my mySQL database. I also did my output aswell, so every topic is posted on a webpage "archive" where you can see all the subjects. But now I want to see the full details of that type of subject by clicking on it. I have no idea how to make that happen googled it but didn't find any results...just wondering if it's even possible to do that. I'm a new guy here! PLEASE HELP! I need help I am a new php user, and am trying to understand how to read a .txt file into an array then to retrieve the index of the array at will. Code: [Select] <?php //echo $myfile = fopen("ArrayTestFile.txt", "r") . "File exists: " or die("File does not exist or you lack permission to open it! "); //echo "The contents of the file is " . file_get_contents("ArrayTestFile.txt") . "<br />"; $fh = fopen("ArrayTestFile.txt", 'r+') or die("Failure"); $array = array(); //creation of array $num = fgets($fh);// recursive call variable $num fgets(.txt line) for ($i = 0; $i <= 5; $i++) //for loop loads first 5 of .txt { $array["i"] = $num; //loads each line of .txt into the array at the loops index. echo "Line " . $i . " of the array is " . $array["i"]; // displays the contents of the array in a print message } ?> Thank you. MOD EDIT: code tags added. Hi, just a very simple question: I have an array as follows: $langList = array('English', 'French', 'German', 'Dutch'); What's the easiest way to store this array in an external file, so that multiple php scripts can access its contents? And what is then the php line I need to retrieve the array from the external file? Thanks! I have a very simple system (few files) having simple articles (only title and a paragraph description) stored in single text files. I catch the data by Code: [Select] $data=file('article1.txt'); $title=$data[0]; $description=$data[1]; This simple system works perfectly, but the problem appears when increasing the number of files (e.g. more than 10,000 articles). This is a problem connected with the OS behavior for handling huge number of files. My first question: Is there theoretically a faster system (e.g. database-based) for retrieving data, comparing with retrieving from plain text file? Second question: what can be an alternative for this very simple system (no search query or additional field)? 1. XML: It has the same problem if storing in different files. 2. Mysql: It is very advanced for this system. 3. SQLite:I am thinking of this, but it still have advanced structure of SQL. 4. DB Berkeley: I am not familiar with Oracle at all, and I need to install something new on my server. Is it really worth of trying? 5. Anything else? In general, I just need fast reading the data. I have no idea how much the speed of these systems are different to determine which is worth of consideration. Thanks for sharing your idea. I'm going to be blunt, I've been working on a website for quite some time now and I never really stopped to think about the effects that an over abundant amount of queries could actually slow things down. I'm quite new to the whole PHP / MySQL thing so I am still learning. While reading through some things about optimization of queries I've learned some valuable information, such as working with Indexes, and not running unnecessary queries which the data doesn't seem to change that often. So for a few aspects of my site which don't really change in particular periods of time, I've decided to write the contents of them into a text file then retrieve and display them as normal through my site. Things that last an hour, or a day, will no longer be queries on each page load; tremendously reducing the amount of queries which my database would take. Currently I have the following code: if($database->numrows($query) > 0) { $myFile = 'testFile.txt'; if($fh = fopen($myFile, 'w')) { $i = 0; while($row = $database->fetchassoc($query)) { ++$i; $stringData = '' . $row['id'] . '--' . $row['name'] . '--' . $row['color'] . '--' . $row['bdaytest'] . '--' . $row['gmtoffset'] . "\n"; fwrite($fh, $stringData); } fclose($fh); } } Which Prints Out Quote 32--User3--0--1939-10-03--+0.0 27--User7--0--1979-10-04--+17.0 28--User65--150--1969-10-05--+17.0 30--User1--0--1959-10-06--+6.0 31--User9--0--1949-10-07--+3.0 29--User5--0--1989-10-08--+17.0 The problem stems from pulling the information from the file and exploding it. That file would be for yesterday's up to 7 days from now's birthdays. The amount of lines could change, possibly messing up the possibility of an array. I was thinking about pulling the information into an array, than exploding it from within that array, posting it to variables.. and then have it display all in a while. Am I on the right track, or is there some other alternative I can use? Only data that will always be visible on the website, will be held in these text files. Any suggestions on how I pull the information from the text file and explode it to display exactly how I need it to be displayed? Hi everyone, This is driving me crazy. I need to reference different files located in different folder structure. For example, I have the following file structure. /my_project/ /my_project/database/database_script.php /my_project/index.php 1. If I want to reference /my_project/index.php from /my_project/database/database_script.php, how can I reference it ? 2. From /my_project/index.php to /my_project/database/database_script.php , it's obvious all I gotta do it include("/database/database_script.php"). I use $_SERVER('DOCUMENT_ROOT"), to solve the 1. problem. It works on my XAMPP local machine but when I uplode it onto the server, there's a problem. The path becomes '/my_project/my_project/database/database_script.php". Is there a universal way (more like a standard way) to reference files in php so that I won't need to change every file path once I upload those onto the server ? Regards, I am using a script found off the web to upload file and show a ajaxy waiting image. In the code for the actual upload is this code $destination_path = getcwd().DIRECTORY_SEPARATOR; $result = 0; $target_path = $destination_path . basename( $_FILES['myfile']['name']); if(@move_uploaded_file($_FILES['myfile']['tmp_name'], $target_path)) { $result = 1; } I am running it from domain.com/label/manage/add-file/upload.php and it uploads the file to domain.com/label/manage/add-file/ How can I upload the file to domain.com/files/123/432/ Do I need to modify the destination path? Also do i need to start it from /home/user/......... Thanks |