Parse errors bouncing from line to line?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
shylock
Forum Newbie
Posts: 20
Joined: Mon Mar 24, 2003 11:50 pm

Parse errors bouncing from line to line?

Post by shylock »

Desperately trying to debug this block but the Parse errors keep referencing line numbers backwards and forwards. The block looks fairly sound to me (although I'm still green). another set of eyes, mine are starting to go blind from staring at it.

Code: Select all

<?php
			//pull fields with values assigned using passed id
			$query_rsSpecs = "SELECT * FROM specs_".$category." WHERE prod_id = $products_id";
			$rsSpecs = mysql_query($query_rsSpecs, $cateye2);
			$row_rsSpecs = mysql_fetch_assoc($rsSpecs);
			$totalFields = mysql_num_fields($rsSpecs);
											
			//echo $row_rsSpecs['prod_id']; //making sure the query works! it does
			
			//put field names into array to use for building simple array:					
			for ($i=0;$i< $totalFields;$i++){
			$Fields[] = mysql_field_name($rsSpecs, $i);
			}
			
			//put recordset values into a simple array for printing							
			foreach ($Fields as $value){
			$SpecArray[] = $row_rsSpecs['$value'];
			} 
			
			//define the number of Table rows to make
			$totalSpecs = (count($SpecArray);							
			$Rows = round($totalSpecs/8);
			
			//make the table with the results						
			echo "<table width=90% border=0 cellpadding=3 cellspacing=3 bgcolor=#CC9999>";
			$counter = 8;
			$specset = 0;
			for ($row = 1; $row< $Rows; $row++){
				echo "<tr>";
				for ($cells = $specset; $cells< $counter; $cells++){
					if ($SpecArray[$cells] != ""){
						echo "<td bgcolor=FFFFFF>".$SpecArray[$cells]."</td>";
					} else if ($SpecArray[$cells] == "1"){
						echo "<td align=center bgcolor=FFFFFF>&#149;</td>";
					}
				}
			echo "</tr>";
			$specset = $specset+8;
			$counter = $counter+8;
			}
?>
Thanks again for all pointers.
[]InTeR[]
Forum Regular
Posts: 416
Joined: Thu Apr 24, 2003 6:51 am
Location: The Netherlands

Post by []InTeR[] »

Why don't use this solution:

Code: Select all

<?
  //pull fields with values assigned using passed id 
  $query_rsSpecs = "SELECT * FROM specs_".$category." WHERE prod_id = $products_id"; 
  $rsSpecs = mysql_query($query_rsSpecs, $cateye2); 
  while($row = mysql_fetch_array($rsSpecs)){
    foreach($row as $key=>$value){
      echo $key." has ".$value."<BR>";
    }
  }
  
?>
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

This would most definitely cause problems:

Code: Select all

$row_rsSpecs['$value']
the single quotes would mean that you are creating a key called $value not a key containing the value of $value, this would work more as you would expect it to:

Code: Select all

$row_rsSpecs[$value]
basically, a single variable does not need quotes of any kind around it.

There was also a closing parenthesis missing on this line:

Code: Select all

$totalSpecs = (count($SpecArray);
it should have been

Code: Select all

$totalSpecs = (count($SpecArray));
Aside from those obvious errors, what type of output are you trying to achieve as I couldn't work it out - and it may be that you can simplify things somewhat.

Mac
shylock
Forum Newbie
Posts: 20
Joined: Mon Mar 24, 2003 11:50 pm

Post by shylock »

Excellent.
I actually figured out my errors after a decent night's sleep.

The example for iterating assoc array is great (much simpler) and I finally got that too after looking deeper into dim arrays.

I am still having some issues with the syntax of them though. The above examples worked in this context because the array was simple enough to display with a while loop, but the below code is using a multi-dim db result set to diplay. If I'm reading the man right, I should be able to reference the key to a row, then the associative column header for each row as a key=>value pair, right?
thing is, I'm not getting any values. pointer anyone?

Code: Select all

<?php
for ($row = 1; $row< $Rows; $row++){
				echo "<tr>";
				for ($setpointer = 0;$setpointer < 3;$setpointer++){
					echo "<td align=center bgcolor=#FFFFFF>";
					echo "<table width=100 border=0 cellpadding=3 cellspacing=2 bgcolor=#993333>";
					echo "<tr><td bgcolor=#CC9999>".$row_rsCat[$setpointer]['products_name']."</td></tr>";
					echo "<tr><td bgcolor=#FFFFFF class=body_text>".$row_rsCat[$setpointer]['products_teaser']."<img src="images/products/".$row_rsCat[$setpointer]['products_icon']."" width=75 height=75>";
					echo "<br>MSRP (USD): ".$row_rsCat[$setpointer]['products_price']."</td></tr>";
					echo "</table";
					echo "</td>";
					
				}
			echo "</tr>";
			$counter = $counter+3;
			if ($counter <= ($numRecs -3)){
			mysql_data_seek($rsCat, $counter);
			} else {
			mysql_data_seek($rsCat, floor($counter / $Rows));
			$row_rsCat = mysql_fetch_assoc($rsCat);
			}
			}
?>
to clarify: I am printing three html tables per table row from an unknown length of result values. I am using mysql_data_seek after I print 3 results to move the pointer 3 results and then fetch my array again. Seems to work if I don't add the key ($setpointer) in the echo statement, it just doesn't advance the output. With the key in there I don't get anything.
thanks
Post Reply