Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can someone help me with this code??Please 1

Status
Not open for further replies.

Herminio

Technical User
May 10, 2002
189
0
0
PT
Code:
<%
Dim id
set id = opin(&quot;idopiniao&quot;)
Dim lastarticle
lastarticle = &quot;&quot;

do while not opin.EOF 
If opin(&quot;idopiniao&quot;) <> lastarticle Then %>
<table width=450 border=1>
	<tr>
		<td bgcolor=#3399cc width=400>
			<font color=&quot;#dbf1ff&quot;><b><%=opin(&quot;titulo&quot;)%></b></font>
		</td>
		<td bgcolor=#3399cc>
			<font size=2><a href=&quot;comt.asp?ID=<%=id%>&quot; class=&quot;link&quot;>Comentar</a></font>
		</td>
		<br>
	</tr>	
	<tr>	
		<td bgcolor=#dbf1ff colspan=2>		
			<font color=&quot;#3399cc&quot;><!--#include file=&quot;splitopin.asp&quot; --></font>
		</td>
	</tr>
</table>
<%  End If %>
<table border=1>   
<%  If opin(&quot;idcoment&quot;) <> &quot;&quot; Then %>
	<tr>
		<td width=440>
			<font color=#3399cc>     <i><!--#include file=&quot;splitcom.asp&quot; --></i></font>
		</td>
	</tr>
<%  Else %>

	<tr>
		<td bgcolor=#3399cc width=383>  
			<font color=&quot;#dbf1ff&quot;><b><%=opin(&quot;titulo&quot;)%></b></font>
		</td>
		<td bgcolor=#3399cc>
			<font size=2><a href=&quot;comt.asp?ID=<%=id%>&quot; class=&quot;link&quot;>Comentar</a></font>
		</td>
		<br>
	</tr>	
	<tr>
		<td colspan=2 bgcolor=#dbf1ff>	
			<font color=&quot;#3399cc&quot;><%=opin(&quot;opiniao&quot;)%></font>
		</td>
	</tr>
	<tr>
		<td colspan=2>
		<font color=&quot;red&quot;>     <i>Sem comentários</i><br></font>

		</td>
	</tr>
<%  End If %>
</table>
<%  lastarticle = opin(&quot;idopiniao&quot;)
  opin.MoveNext
loop
%>

I'm asking people to send opinions on some issues to my site, and then other users can comment those opinions, the code above is from the page were i display all the opinions and comments, it's all working fine, but there's one thing that i just can't understand, on these 2 lines here
Code:
<font size=2><a href=&quot;comt.asp?ID=<%=id%>&quot; class=&quot;link&quot;>Comentar</a></font>
i'm passing the values to the comments page with the ID field of the record, all the records that already have a comment work fine, but the records that don't have any comments yet just don't pass the ID value, can someone help me with this?

view the problem online in
Thanks in advance

Herminio, Portugal
 
It depends on how you load your recordset and which table you use. If you have a table of opinions and a table of comments (many to one relationship with opinions). Then make sure to left join the comments to the opinions so that everything in the opinion table is returned (whether or not there is a comment associated with it) Get the Best Answers! faq333-2924
Is this an asp FAQ? faq333-3048
Tek-Tips Best Practices: FAQ183-3179
mikewolf@tst-us.com (Do not email regarding this thread unless requested - I don't check this account regularly)
 
i did exactly that i have a left join on the query

heres is the sql

SELECT *
FROM Opiniao LEFT JOIN Coments ON [Opiniao].[IdOpiniao]=[Coments].[IdOpiniao];

is there anything wrong with the SQL?

Herminio, Portugal
 
Is the whole loop not firing? Or, are you just not getting a value in the line:
<a href=&quot;comt.asp?ID=<%=id%>&quot; class=&quot;link&quot;>

meaning is <%=id%> returning nothing so your HTML looks like:

<a href=&quot;comt.asp?ID=&quot; class=&quot;link&quot;> Get the Best Answers! faq333-2924
Is this an asp FAQ? faq333-3048
Tek-Tips Best Practices: FAQ183-3179
mikewolf@tst-us.com (Do not email regarding this thread unless requested - I don't check this account regularly)
 
yes, that's exactly what's happening, what's the problem?
 
When you say &quot;yes, that's exactly what's happening&quot;, I'm guessing that you meant my second suggestion. If <%=id%> is returning nothing then the problem is where you are getting the value for ID.

set id = opin(&quot;idopiniao&quot;)

Make sure that your query is returning a value. Since you are using an outer join, make sure that you are getting the value for ID from the main (left) table. Since ID is probably you PK/FK for the join, make sure to look for the value from the primary table...

For instance, lets say that you have 2 tables...

Table1
pkID Name
1 Bill
2 Mary

Table2
fkID comment
1 Good Job
1 Looks alright


Query1
SELECT t2.pkID, t2.comment
FROM table1 t1
LEFT JOIN table2 t2 ON t1.pkID = t2.fkID

Returns
1 Good Job
1 Looks alright

and no record for Mary...


Query2
SELECT t1.pkID, t2.comment
FROM table1 t1
LEFT JOIN table2 t2 ON t1.pkID = t2.fkID

Returns
1 Good Job
1 Looks alright
2 null

Get the Best Answers! faq333-2924
Is this an asp FAQ? faq333-3048
Tek-Tips Best Practices: FAQ183-3179
mikewolf@tst-us.com (Do not email regarding this thread unless requested - I don't check this account regularly)
 
looking at the SQL instruction that i have on one of my last posts can you tell me if there's anything wrong with it?

Opiniao is the &quot;main&quot; table and Coments is the one that is related with the first by the Id.Opiniao field.

Herminio, Portugal
 
Your query seems fine, but you should run try to execute your query against the database directly (no asp) to see what the resulting recordset looks like.

Rather than say:
SELECT *
FROM Opiniao LEFT JOIN Coments ON [Opiniao].[IdOpiniao]=[Coments].[IdOpiniao];

Try:
SELECT o.IdOpiniao, c.comments
FROM Opiniao o LEFT JOIN Coments c ON o.IdOpiniao = c.IdOpiniao



My best guess is that when you say:
set id = opin(&quot;idopiniao&quot;)

without specifying which table to get &quot;idopiniao&quot; (which exists in both tables) you are getting it from the coments table (where it may be null) Get the Best Answers! faq333-2924
Is this an asp FAQ? faq333-3048
Tek-Tips Best Practices: FAQ183-3179
mikewolf@tst-us.com (Do not email regarding this thread unless requested - I don't check this account regularly)
 
Thanks a lot mwolf00, based on your last suggestion i've changed set id = opin(&quot;idopiniao&quot;) to set id = opin(&quot;opiniao.idopiniao&quot;) and voilá, it works just fine, you are great, unfortunatelly i just can give one star for all of your atention, thanks one more time.

Herminio, Portugal
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top