return problem

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
mrpaulfrank
Forum Commoner
Posts: 33
Joined: Sun Jun 23, 2002 3:39 am

return problem

Post by mrpaulfrank »

while($row_Recordset1 = mysql_fetch_assoc($Recordset1))
{
$image = $row_Recordset1['image'];
if($genre = "comedy")
{
echo "<A href=backs/$image.jpg><IMG SRC=images/$image.jpg></A>"."<br>\n".
"Title: ".$row_Recordset1['title']."<br>\n".
"Format: ".$row_Recordset1['format']."<br>\n".
"Price: ".$row_Recordset1['make']."<br>\n\n";
}
}

how can i get the results (one result being a whole loop existing of an image, title, format, and make) to be placed horizontally instead of vertically?
garymailer
Forum Newbie
Posts: 1
Joined: Mon Jul 01, 2002 1:59 am
Contact:

Post by garymailer »

Mrpaulfrank

Code: Select all

I've simply taken out all the <br> and the newline characters (\n) tags and included one at then end

while($row_Recordset1 = mysql_fetch_assoc($Recordset1)) 
&#123; 
$image = $row_Recordset1&#1111;'image']; 
if($genre = "comedy") 
&#123; 
echo "<A href=backs/$image.jpg><IMG SRC=images/$image.jpg></A>". 
"Title: ".$row_Recordset1&#1111;'title']." 
"Format: ".$row_Recordset1&#1111;'format']." 
"Price: ".$row_Recordset1&#1111;'make'].".
<br />"; 
&#125; 
&#125;
mrpaulfrank
Forum Commoner
Posts: 33
Joined: Sun Jun 23, 2002 3:39 am

Post by mrpaulfrank »

it doesnt work:( all that does is make the entire thing one long string of text. what i want is this:

image
title
format
make

then the next one displayed a little over horizontally, and so on...
is there some sort of a 'tab' tag i can use to do this?? im completely lost.
thanks
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

piece of cake

Code: Select all

echo "<table cellpadding="0" cellspacing="5"><tr>";
while($row_Recordset1 = mysql_fetch_assoc($Recordset1)) 
&#123; 
$image = $row_Recordset1&#1111;'image']; 
if($genre = "comedy") 
&#123; 
echo "<td><table cellpadding="0" cellspacing="2"><tr><td>"
."<A href=backs/$image.jpg><IMG SRC=images/$image.jpg></A></td></tr>". 
"<tr><td>Title: ".$row_Recordset1&#1111;'title']." 
"</td></tr><tr><td>Format: ".$row_Recordset1&#1111;'format']." 
"</td></tr><tr><td>Price: ".$row_Recordset1&#1111;'make']."</td></tr></table></td>"; 
&#125; 
&#125; 
echo "</tr></table>";
mrpaulfrank
Forum Commoner
Posts: 33
Joined: Sun Jun 23, 2002 3:39 am

Post by mrpaulfrank »

wow, im extremely lost. from what i see youre trying to echo a table before you echo the info from mysql which will be inserted into the table?? i still cant get it to work. maybe if someone can explain to me what i should be trying to do...i dunno. thanks
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

What the code should do is create a large table where on each iteration of the while loop a new cell is created and another table inserted into it containing a few rows with the information from the database, here's the code again, laid out differently and with a couple of parse errors removed:

Code: Select all

<?php
echo <<<END
<table cellpadding="0" cellspacing="5">
<tr>
END; 
while($row_Recordset1 = mysql_fetch_assoc($Recordset1)) &#123; 
	$image = $row_Recordset1&#1111;'image']; 
	if ($genre == 'comedy') &#123; 
		echo <<<END
	<td>
		<table cellpadding="0" cellspacing="2">
		<tr>
			<td><a href="backs/$image.jpg"><img src="images/$image.jpg"></a></td>
		</tr>
		<tr>
			<td>Title: &#123;$row_Recordset1&#1111;'title']&#125;</td>
		</tr>
		<tr>
			<td>Format: &#123;$row_Recordset1&#1111;'format']&#125;</td>
		</tr>
		<tr>
			<td>Price: &#123;$row_Recordset1&#1111;'make']&#125;</td>
		</tr>
		</table>
	</td>
END;
	&#125; 
&#125; 
echo <<<END
</tr>
</table>
END; 
?>
Mac
mrpaulfrank
Forum Commoner
Posts: 33
Joined: Sun Jun 23, 2002 3:39 am

Post by mrpaulfrank »

whats wrong with this code? im getting a parse error and its not creating the table within a table. im trying to make each loop a table (each table having 4 rows) in a larger table so that the results will be columns in one row of the larger table (make sense?):

Code: Select all

<table width="800" border="0" cellspacing="0">
<tr>
<?php  
$genre = "comedy";
$query_Recordset1 = "SELECT * FROM test WHERE genre = '$genre'";
$Recordset1 = mysql_query($query_Recordset1, $db) or die(mysql_error());
while($row_Recordset1 = mysql_fetch_assoc($Recordset1)) 
&#123;
	$image = $row_Recordset1&#1111;'image'];	
	if($genre = "comedy")
	&#123;
	echo	"<table width="200" border="0" cellspacing="0">"."<tr>".	
	"<td><A href=backs/$image.jpg><IMG SRC=images/$image.jpg></A>"."</td>".
	"<td>Title: ".$row_Recordset1&#1111;'title']."</td>". 
    "<td>Format: ".$row_Recordset1&#1111;'format']."</td>".
	"<td>Make: ".$row_Recordset1&#1111;'make']."</td></tr>";
	&#125;
&#125;
?>
  </tr>
</table>
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

The code I posted was the code that you are now using with the obvious parse errors in the original code removed...

Anyway,

Code: Select all

<table width="800" border="0" cellspacing="0"> 
<tr> 
<?php  
$genre = 'comedy'; 
$query_Recordset1 = "SELECT * FROM test WHERE genre = '$genre'"; 
$Recordset1 = mysql_query($query_Recordset1, $db) or die(mysql_error()); 
while($row_Recordset1 = mysql_fetch_assoc($Recordset1)) 
&#123; 
   $image = $row_Recordset1&#1111;'image'];    
   if ($genre == 'comedy') &#123; 
	   echo <<<END
   <td> 
      <table cellpadding="0" cellspacing="2"> 
      <tr> 
         <td><a href="backs/$image.jpg"><img src="images/$image.jpg"></a></td> 
      </tr> 
      <tr> 
         <td>Title: &#123;$row_Recordset1&#1111;'title']&#125;</td> 
      </tr> 
      <tr> 
         <td>Format: &#123;$row_Recordset1&#1111;'format']&#125;</td> 
      </tr> 
      <tr> 
         <td>Make: &#123;$row_Recordset1&#1111;'make']&#125;</td> 
      </tr> 
      </table> 
   </td> 
END;
   &#125; 
&#125; 
?> 
  </tr> 
</table>
Please also note that although it won't cause any parse errors it will cause you a headache,

Code: Select all

if ($genre = 'comedy') &#123;
has to be

Code: Select all

if ($genre == 'comedy') &#123;
in order to work.

Mac
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

sorry ;-) it was rather early in the morning, when parse errors seem to roam my mind
mrpaulfrank
Forum Commoner
Posts: 33
Joined: Sun Jun 23, 2002 3:39 am

Post by mrpaulfrank »

all thes problems were because i was not escaping the quotes! haha. thanks guys
Post Reply