Web Hosting Talk







View Full Version : use it again...


ti_nhatrang
08-06-2007, 01:53 AM
hi guys,

I ran a few sql queries for a top portion of my page... however, I want to use the same fecth of arrays again at the bottom of the page:

Here's what I got:


<div class="interval">
<img src="images/red.gif" alt="*" width="407" height="53" />
<p id="breadcrumb">Entertainment &raquo; <? echo "$title &raquo; $ettitle"; ?> <br />
<form name="etselect">
<select name="et_select" onchange="self.location.href=this.value"><option value="#">See More</option>
<? $et_sel_db = mysql_query("select title,firstpostid from localhost_vbnews.thread where forumid=$ch AND open=1 AND title !='$ettitle2' ORDER BY dateline DESC LIMIT 30") or die(mysql_error());
while($et_sel = mysql_fetch_array($et_sel_db)) {
$et_sel_att_db = mysql_query("select attachmentid from localhost_vbnews.attachment where postid=$et_sel[firstpostid] limit 1") or die(mysql_error());
while($et_sel_att = mysql_fetch_array($et_sel_att_db)) {
echo "<option value=\"page.php?et=$et_sel[firstpostid]&ch=$ch&desc=$et_sel_att[attachmentid]\">$et_sel[title]</option>;" }}?></select></p>
</div>


That's what I have, and I want to use the same outputs from the sql statement for the follwing html code:


<li><img src="/<? echo "$et_sel_att[attachmentid]"; ?>.pic" width="58" height="38" alt="red" /><a href="#"><? echo "$et_sel[title];" ?></a> <? echo "$et_se[description]"; ?></li>

That is what i want to use with the queries above... the above spit out 30 into a option select form, I want it to also spit out 30 at the bottom in a LI form...

please help, and thank you in advance.

Kohrar
08-06-2007, 02:13 AM
I would suggest putting:


$li_list .= '<li><img src="/'.$et_sel_att[attachmentid].'.pic" width="58" height="38" alt="red" /><a href="#">'.$et_sel[title].'</a>'.$et_se[description].'</li>';


right after the echo function, inside the while loop like this:


<?php
$et_sel_db = mysql_query("select title,firstpostid from localhost_vbnews.thread where forumid=$ch AND open=1 AND title !='$ettitle2' ORDER BY dateline DESC LIMIT 30") or die(mysql_error());

while($et_sel = mysql_fetch_array($et_sel_db)) {
$et_sel_att_db = mysql_query("select attachmentid from localhost_vbnews.attachment where postid=$et_sel[firstpostid] limit 1") or die(mysql_error());

while($et_sel_att = mysql_fetch_array($et_sel_att_db)) {
echo "<option value=\"page.php?et=$et_sel[firstpostid]&ch=$ch&desc=$et_sel_att[attachmentid]\">$et_sel[title]</option>;"

$li_list .= '<li><img src="/'.$et_sel_att[attachmentid].'.pic" width="58" height="38" alt="red" /><a href="#">'.$et_sel[title].'</a>'.$et_se[description].'</li>';

}
}

?>


All you have to do now is to echo out $li_list at the bottom of the page.

ti_nhatrang
08-06-2007, 03:39 AM
i did, it it only return 1 output? what happened to 29 of them? Thanks once again for your help thus far.

Kohrar
08-06-2007, 04:06 AM
Hmm, are you sure you have "$li_list .= '<li><img src... "?

The operator needs to be ' .= ' (dot equal), not just ' = '

The dot infront of the equal sign just means that the contents are to be added to the variable, instead of replacing its value.

ti_nhatrang
08-06-2007, 04:12 AM
this is how i have it:


$li_list .= "<li><img src=\"/$et_sel_att[attachmentid].pic\" width=\"58\" height=\"38\" alt=\"red\" /><a href=\"#\">$et_sel[title]</a>$et_se[description]</li>";

Kohrar
08-06-2007, 04:17 AM
That looks fine... Are you sure you placed it in the same loop as the echo?
Might help if you can re-post the entire code.

ti_nhatrang
08-06-2007, 04:18 AM
oh no, i end the loop so i can move on with my php/html codes and then i call $li_list once again at the very bottom of the page...

Kohrar
08-06-2007, 04:24 AM
Woops, what I meant was:


while($et_sel_att = mysql_fetch_array($et_sel_att_db)) {
echo "<option value=\"page.php?et=$et_sel[firstpostid]&ch=$ch&desc=$et_sel_att[attachmentid]\">$et_sel[title]</option>;"

$li_list .= "<li><img src=\"/$et_sel_att[attachmentid].pic\" width=\"58\" height=\"38\" alt=\"red\" /><a href=\"#\">$et_sel[title]</a>$et_se[description]</li>";

} // While loop ends. Is $li_list within this loop?


Are you sure that the $li_list is within the while loop that prints out the <option> values?

If not, then that'll explain why you have only one result at the end.

ti_nhatrang
08-06-2007, 04:25 AM
nope, it's not in there because that portion is ontop of the page... and the LI is at the bottom.

Kohrar
08-06-2007, 04:33 AM
Hmm, if I'm not mistaken at what you want to do, you will need to have $li_list within the while loop at the top, like the way I have it. What happens is this: when the loop runs, it will print the 30 entries within the <option></option> values, while at the same time, storing the <li> entries in a variable ($li_list) so it can be printed out at the end.

If you leave $li_list out of the while loop, it will only be ran once, which leaves you with only one entry.

ti_nhatrang
08-06-2007, 07:50 AM
yeah, i could've figured that... i was just hoping that there's some other trick out there that i didn't know about... :(

ti_nhatrang
08-07-2007, 08:21 PM
I'm giving everyone one last chance to help me or I shall move on with my life hahaha :)