Copy link to clipboard
Copied
I am helping a woman out with a small website that is set up with coldfusion. She adds photos with a coldfusion application that was written by someone. I am not too experienced with coldfusion, but have used it, so I was wondering if someone could help me out!
First - She wants her list of photos to be arranged by date added. So the most recent ones at the top. I assume this is done in the <cfoutput> tag but I am not quite sure on the syntax?
Second - She wants to be able to hide some from showing on her website in case people aren't paying her then they will not show up on the website. But if people pay her to show images of their work, then she doesn't want to have to keep adding and deleted them. If you need to see the code to help me out, I can definitely add post it.
Thank you!
Copy link to clipboard
Copied
I am helping a woman out with a small website that is set up with coldfusion. She adds photos with a coldfusion application that was written by someone. I am not too experienced with coldfusion, but have used it, so I was wondering if someone could help me out!
Help with problems yuo are having writing your own code: yes. Writing your code for you: no.
It helps when posting here if you post the code you have tried, and tell us where you're having problems.
First - She wants her list of photos to be arranged by date added. So the most recent ones at the top. I assume this is done in the <cfoutput> tag but I am not quite sure on the syntax?
Well: yes and no. CFOUTPUT can be used for iterating over a record set, yes. Although in most situations, CFLOOP is a better fit for that job.
But anyway, before you loop over a record set, you need to GET the record set, so you have to ask the database for it (I'm assuming this stuff is in a database, although you don't say).
So you need to use CFQUERY or CFSTOREDPROC to pass instructions to the DB telling it what and how you want it.
Second - She wants to be able to hide some from showing on her website in case people aren't paying her then they will not show up on the website. But if people pay her to show images of their work, then she doesn't want to have to keep adding and deleted them.
This is a DB design question (or "issue"). The record set you want to fetch from the DB needs to be queried in such a way that you only select the image records which have a corresponding "person" who has an account that is flagged as being "paid".
Without knowing your DB schema, it's impossible to say how to effect this.
I think you probably need to find some CF and DB/SQL tutorials or books or whatever and work your way through those before you start working on someone's website, to be honest.
However if you've got some CF code and it's not doing what you want it to, post the code, and post a description of how it's not working: what it's doing wrong, and what your expectations are.
--
Adam
Copy link to clipboard
Copied
For arranging the photos by the date, use an order by clause in your query. Cfoutput is not the best way to approach this.
For only displaying paid for images, if you have the data, use it in the where clause of your query. If you don't, you have to create a spot in the database to put it, and come up with a way to maintain that data.
In short, the solution to both problems lie with your data, not Coldfusion code.
Copy link to clipboard
Copied
The following is the page for the image listings that she wants ordered. If I just use a simple ORDER BY clause under the SELECT statement, I thought this would solve my problem, but I get an error message. I tried "ORDER BY date desc".
As I stated I am very new to the use of coldfusion and felt I wasn't taught well in the first place, so I am just trying to figure it out on my own via books and internet. I appreciate your help and your patience with me as I am new to this!
Secondly. what I highlighted in red is where I get confused as to why it does not work with the photos being "active". If no is marked, the photo is still visible on the website.
<cfquery name="getIdeas" datasource="#datasource#" username="#username#" password="#password#">
SELECT *
FROM dbo.ideas
</cfquery>
<cfparam name="url.status" default="none">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/utilities.dwt.cfm" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>LakesAreaCelebrations.com - Utilities - Edit / Delete an Idea Listing</title>
<script type="text/javascript" src="../scripts/sortable.js"></script>
<!-- InstanceEndEditable -->
<link href="../styles/main.css" rel="stylesheet" type="text/css" />
<!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable -->
</head>
<body>
<p class="greylargebold">LakesAreaCelebrations.com Utilities</p>
<p><a href="../index.cfm">Return to Utilities Home Page</a><br />
<a href="../../index.cfm">View LakesAreaCelebrations.com Home Page</a></p>
<!-- InstanceBeginEditable name="pageBody" -->
<cfif url.status is "Deleted">
<script>
alert('Listing Deleted');
</script>
</cfif>
<div align="center"><span class="greylargebold">Select the Idea Listing to Edit or Delete</span><br />
<br />
<a href="index.cfm">add another listing</a><br />
<br />
<table width="100%" id="sortableTable" class="sortable">
<tr>
<th width="15%" class="heading noBorder">Image Name</th>
<th width="16%" class="heading noBorder">Title</th>
<th width="14%" class="heading noBorder">Contributor</th>
<th width="9%" class="heading noBorder">Is Active?</th>
<th width="8%" class="heading noBorder"> </th>
<th width="5%" class="heading noBorder"> </th>
</tr>
<cfoutput query="getIdeas">
<tr>
<td align="left"><cfif getIdeas.I_Image is not "">#getIdeas.I_Image#<cfelse><span style="color:##FF0000;">No Image</span></cfif></td>
<td align="left">#getIdeas.I_Title#</td>
<td align="left">#getIdeas.I_ContributedBy#</td>
<td align="left"><cfif getIdeas.I_IsActive is "1">
Yes
<cfelse>
No
</cfif></td>
<td align="left"><a href="index.cfm?I_UId=#getIdeas.I_UId#">edit</a></td>
<td align="left"><a href="ideaDelete.cfm?I_UId=#getIdeas.I_UId#">delete</a></td>
</tr>
</cfoutput>
</table>
</div>
<!-- InstanceEndEditable -->
</body>
Copy link to clipboard
Copied
What did the error message say?
Copy link to clipboard
Copied
Error Executing Database Query
Invalid column name 'date'
So I am wondering if I have to add a field as to where she has to enter the
current date when the photo is added. Also, I read in my coldfusion book
that CF will automatically arrange the table as to what is most recently
added, like she wanted, but it is not doing that it is arranging by
alphabetical order. So I am trying to find where that statement is and maybe
delete that order by?
Copy link to clipboard
Copied
The first thing you need to do is find out what columns are in that table. The easiest way to do that is
<cfquery name="x">
select * from yourtable where 1=2
</cfquery>
<cfdump var="#x.columnlist#" abort>
Copy link to clipboard
Copied
You need to inspect the table and see if there is a field for date_entered or something like that. It should not be "date" like you just tried as "date" is a reserve word in every database I've ever seen...
I suggest you not try and use the 'natural order" as you read about. Who knows how the records are being appended and/or edited.
If there is date field in the table then your were close witht the cfquery modification it's just that "date" is not the field name....
If there is no date field in the table then search the code for a <cfquery> that is the update and/org insert type for the table. You can then edit that location to insert the system date using #now()# to put the date added/edited in the table without having to enter the data manually.
Copy link to clipboard
Copied
If there is no date field in the table then search the code for a <cfquery> that is the update and/org insert type for the table. You can then edit that location to insert the system date using #now()# to put the date added/edited in the table without having to enter the data manually.
This seems like an easier route than for me to add a date field. If I do this, will it automatically update the fields already added to the table or just the ones that I will have added after I update the code?
Copy link to clipboard
Copied
Actually, you can't follow that suggestion unless you add a field in which to store that date. So far there is an element of doubt as to whether that is necessary because you have given no indication that you know what fields are already there.
If you do want to add a date field, the most efficient way is to give it a default value of the current date and time. Then all your existing records will be updated and new records will look after themselves. The details of how to get the current date and time depend on your database software.
Copy link to clipboard
Copied
I really appreciate all of your help. I am wondering if this task is going
to be more complicated than I think because I do not know the framework of
this application for I did not write it, someone else did.
I have gotten to the point where I figured out how to add the date field,
but now I am getting an error message where this date field I added is
"undefined in GetIdeas", but I can't seem to find that, so I am searching
code and files..
Copy link to clipboard
Copied
Have you considered downloading the database from the website in question and looking at it's structure?
Copy link to clipboard
Copied
jAlso, I read in my coldfusion book
that CF will automatically arrange the table as to what is most recently
added
This is absolutely not true. The DB is in control of the data, not CF, for one thing. The DB will return records in the order it finds them, which has no guaranteed sequence unless one uses an order by statement.
What book did you read that in, and what precisely did it say?
--
Adam
Copy link to clipboard
Copied
It is my Adobe Coldfusion 8 Getting Started Volume 1, on page 84 it says:
"When you use the SELECT statement, the results are returned to you in the
order in which they appear in the table. *This is usually the order in which
the rows were added to the table.*"
Copy link to clipboard
Copied
jodifay12 wrote:
It is my Adobe Coldfusion 8 Getting Started Volume 1, on page 84 it says:
"When you use the SELECT statement, the results are returned to you in the
order in which they appear in the table. *This is usually the order in which
the rows were added to the table.*"
That is an extremely misleading statement I'm afraid, I'm surprised they put it in. There is absolutely no guarantee what order the database will return rows in, it depends on things you cannot possibly control.
Very odd.
Copy link to clipboard
Copied
It is very misleading. However, I can see where they don't 100% state that
it will happen, but new ColdFusion students like me can get very mislead!
Copy link to clipboard
Copied
To see your table field names do this:
<cfquery name="colList" datasource="yourDatasource">
Select *
From yourTableName
Where 0=1
</cfquery>
This will return zero records.
<br />
<cfdump var="colList" />
While this won't give you data type or length you should be able to determine the name of the date field you are trying to order the set by.
Copy link to clipboard
Copied
To see your table field names do this: <cfquery name="colList" datasource="yourDatasource">
Select *
From yourTableName
Where 0=1
</cfquery>
This will return zero records.
<br />
<cfdump var="colList" />
While this won't give you data type or length you should be able to determine the name of the date field you are trying to order the set by.
There's also CFDBINFO which would probably be a better and more comprehensive solution to this requirement. That said, the OP doesn't say one way or the other, but I don't think CFDBINFO works on Access DBs (but who cares?), and obviously only works on CF8+. But all DBs have things like SP_HELP or DESCRIBE which do a better job of fetching this info that the SELECT * route.
--
Adam