|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
using a variable as the path in a <img> tag?
Hi,
Got a path in my database for translated button graphics. Want to stick the variable that points to the path into an <img> tag but it's not working. Here is what i'm using: Code:
<img src="#lang.trans[200]#" hspace="10" border="0"> My path in SQL reads: butns/eng_back.gif and when i right click on the missing image icon that appears intead of my chosen button image, the path doesn't read "such and such.gif" but "#lang.trans[200]#". Ideas?? |
|
#2
|
|||
|
|||
|
Wrap it in <cfoutput>.
__________________
Ask if you have a question, but also help answer questions that you have knowledge of! Thanks, Brian. How to Post a Question in the Forums |
|
#3
|
|||
|
|||
|
nah, that's not it. I tried to basically output the string to error check and i got this:
The element at position 201 in dimension 1 of object "lang.trans" cannot be found. The object has elements in positions 1 through 199. Please, modify the index expression. The error occurred while processing an element with a general identifier of (#lang.trans[201]#), occupying document position (237:5) to (237:21). I'm outputting from a table where the rows are starting to exceed 200. Surely this must be straightforward? The variable lang.trans is taken from a query generated by application.cfm if that means anything? thanks |
|
#4
|
|||
|
|||
|
What is lang.trans? Is it an array? Use cfdump to display the variable and confirm that it has the number of elements you think it does. My guess is that array only has 200 elements in it, so when you get to 201 it throws an error. The other question to ask yourself is, is an array the appropriate type of variable to hold the data in question?
|
|
#5
|
|||
|
|||
|
not overly familiar with arrays so i don't think it is.
basically there is a query called 'lang' which selects a row like so: "Select Italian as trans" ergo lang.trans[] (with the row number you want to output in the brackets). Depending on what language id you have in the database, there are several queries in application.cfm, one of which will be used. The one above used Italian as an example, but there are a few others. I didn't realise that it had a limit of 200 rows though?? that's not an array though is it? So, what does "modify the index expression" mean? please help, i've created an entire system around this and it could all fall apart horribly ![]() |
|
#6
|
|||
|
|||
|
I think you've jumped ahead of yourself in a couple of places. First, if the variable is a query, is there any reason why you aren't using the normal query syntax ie "myquery.mycolumn"? Why are you using the array syntax to reference the query elements?
Can't you just do (assumign the query is called lang): <cfoutput query="lang"> <img src="#lang.trans#" hspace="10" border="0"> </cfoutput> ? And second, when you cfdump the query, how many elements are in it? How are you deciding what row value you are using for each of the elements? Are you looping? No there is no limit on the size or an array or query (aside from the RAM on your server). It's blowing up because you're referencing it incorrectly. |
|
#7
|
|||
|
|||
|
right,tried cfdump and got this:
Code:
ColdFusion cannot determine how to process the tag <CFDUMP>. The tag name may be misspelled. Running 4.5 so maybe that's it. That output you gave wouldn't work, i'll explain in full how the system works as clearly and as simply as i can. 1. Users select a language from a menu before logging on, but as they do it gets added as a number to a database. So the DB remembers their choice. 2. This gets sent to application.cfm as a session variable (session.lang) There you'll see something like this: Code:
<cfif isdefined("session.lang") and #session.lang# EQ 1>
<cfquery name="lang" datasource="db">
SELECT English as trans
FROM trans_admin
</cfquery>
<cfelseif isdefined("session.lang") and #session.lang# EQ 4>
<cfquery name="lang" datasource="db">
SELECT Italian as trans
FROM trans_admin
</cfquery>
and so on... THE DATABASE ----------------------- The database has several collumns, one for each language. The first collumn is an auto increment. So I have about 200 entries (rows) with text in. e.g. transID | English | Italian | -------------------------- 112 | one | Uno so when i want to output text, i'll just put: <cfoutput> #lang.trans[rownumber]# </cfoutput> Does that make sense? Just can't see why it's cutting me off after 200... |
|
#8
|
|||
|
|||
|
wait wait wait
I got it!!! I thought, because (due to the odd deletion) I was outputting row number 201 (because that's what the autoID reads) when in actuality, the ammout of rows only went up to 199. But this aint good, because now i don't have an accurate idea of what row number i'm outputting. Off the top of your head, is there a way I could have: #query.collumn# and somehow specify the auto-increment number? shortness of text is key because every bit of text on the site will be dynamic in this way and i don't want blocks of code for every tiny bit of text i need to fetch. thanks! |
|
#9
|
|||
|
|||
|
That's the thing, if you use
<cfoutput query="myquery"> #myquery.column1# #myquery.column2# etc... <br> </cfoutput> You don't need to know how many rows there are in the query and you don't need to reference each row by number....cfoutput loops over each row in the query automatically. I think before you go further you might want to stop and spend some time playing with queries and different ways to reference and manipulate them. Otherwise you're going to build the system without fully understanding the implications of the decisions you are making. |
|
#10
|
|||
|
|||
|
Also, I should note that all of this is fully described in the documentation . Also, if you can possibly upgrade your server, you should. ColdFusion 4.5 is over seven years old and has been vastly improved upon.
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ColdFusion Development > using a variable as the path in a <img> tag? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|