Jump to content


Photo

I'm going to commit sue.....


  • Please log in to reply
3 replies to this topic

#1 jwwceo

jwwceo
  • Members
  • PipPipPip
  • Advanced Member
  • 212 posts

Posted 29 August 2006 - 05:26 AM

I  am trying to make a product page that will create custom javascript menus for each item on the page. There will be a little icon that once rolled over will make a pop up menu with the keywords for that shirt.

The javascript menu I'm using has a block of HTML in the body for each menu. The following code is what I've came up with to build these HTML tables for each menu. I only posted the relevant code...I think....

I think once I get his part done I can get the rest....

I get major parse errors... any ideas....is the logic even right???

//CREATES A LOOP THAT OUTPUTS THE FOLLOWING HTML FOR EACH ROW IN THE DATABASE
while($info = mysql_fetch_array($data)){ 

//PULLS THE KEYWORD DATA FOR EACH ITEM(ROW)
$data1 = mysql_query("SELECT * FROM shirtkeywords WHERE shirt_id ='".$info['shirt_id']."') or die(mysql_error());
$keywords = mysql_fetch_array( $data1 ));


//BUILD THE JAVASCRIPT HEADER  FOR EACH MENU
"<DIV class=menuContainer id=menu$info[shirt_id]Container>
<DIV class=menu id=menu$info[shirt_id]Content>
<DIV class=menuInsert style='HEIGHT: 180px'>
<TABLE class=menuTable cellSpacing=0 cellPadding=0 border=0>
<TBODY>";

//BUILD THE TABLE ROWS FOR EACH KEYWORD ASSOCIATED WITH A PRODUCT
foreach ($keywords[] as $keyword_id) {

echo
"<TR>
    <TD><IMG height=4 src='menu_script/spacer.gif' width=1></TD></TD>
  <TR>
    <TD><A class=menuLink href='link'>".keywords['keyword']."</A></TD></TR>
    </TBODY>
</TABLE></DIV></DIV></DIV>";

}


#2 448191

448191
  • Staff Alumni
  • Advanced Member
  • 3,545 posts
  • LocationNetherlands

Posted 29 August 2006 - 05:46 AM

<?php
//CREATES A LOOP THAT OUTPUTS THE FOLLOWING HTML FOR EACH ROW IN THE DATABASE
while($info = mysql_fetch_array($data)){ 

//PULLS THE KEYWORD DATA FOR EACH ITEM(ROW)
$data1 = mysql_query('SELECT * FROM shirtkeywords WHERE shirt_id ="'.$info['shirt_id'].'"') or die(mysql_error());
$keywords = mysql_fetch_array( $data1 );


//BUILD THE JAVASCRIPT HEADER  FOR EACH MENU
echo "<DIV class=menuContainer id=menu$info[shirt_id]Container>
<DIV class=menu id=menu$info[shirt_id]Content>
<DIV class=menuInsert style='HEIGHT: 180px'>
<TABLE class=menuTable cellSpacing=0 cellPadding=0 border=0>
<TBODY>";

//BUILD THE TABLE ROWS FOR EACH KEYWORD ASSOCIATED WITH A PRODUCT
foreach ($keywords[] as $keyword_id) {
	echo
	'<TR><TD><IMG height="4" src=\'menu_script/spacer.gif\' width="1"></TD></TD>
	  <TR><TD><A class="menuLink" href=\'link>'.$keywords['keyword'].'</A></TD></TR>
	    </TBODY>
	</TABLE></DIV></DIV></DIV>';
}
?>

I fixed the parse errors for you.

I don't quite see what you're trying to do here:
foreach ($keywords[] as $keyword_id) {
	echo
	'<TR><TD><IMG height="4" src=\'menu_script/spacer.gif\' width="1"></TD></TD>
	  <TR><TD><A class="menuLink" href=\'link>'.$keywords['keyword'].'</A></TD></TR>
	    </TBODY>
	</TABLE></DIV></DIV></DIV>';
}


#3 jwwceo

jwwceo
  • Members
  • PipPipPip
  • Advanced Member
  • 212 posts

Posted 29 August 2006 - 05:51 AM

I may not be using that foreach right.

The idea is that I store all the keywords and their keyword id's that apply to a shirt in an array called $keywords.

Then for each item in the array I output another row in the table...

would a while loop be better????

#4 448191

448191
  • Staff Alumni
  • Advanced Member
  • 3,545 posts
  • LocationNetherlands

Posted 29 August 2006 - 05:58 AM

This is VERY basic stuff, so you might wanna take a look in the manual.

foreach($array as $array_key => $array_value)
{
  //Array key and array value are now local variables, wich you may use.

}

OR

foreach($array as $array_value)
{
  //Array value is now a local var.
}

Also read up on arrays.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users