Page 1 of 1
Newbie with problem presenting data
Posted: Thu Sep 04, 2003 4:39 pm
by sauron98
Dear Friends
I have been sweating over this script for hours. Im extremely new to php. At the moment My script is presenting my data in 2 rows of a table. 2 rows of 3 consequetive entries. Im desperatley trying to make it present 3 rows of data in order. I think its to do with this part of the script!
Code: Select all
<?php
<?
if($rnum>0)
{
$sql="select * from tblcd order by cd_id desc limit $skip,$lmt";
//echo $sql;
$result=mysql_query($sql,$link);
$x=1;
$y=1;
$temp_i=8/4;
for($cnt_i=1;$cnt_i<=$temp_i;$cnt_i++)
{
?>
<tr>
<?
for($cnt_j=1;$cnt_j<=4;$cnt_j++)
{
while($row=mysql_fetch_array($result))
{
if($x<=3)
{
?>
?>
Can anyone please help me...my website is a disaster at the moment! Any pointers would be so gratefully received!
Kindest regards
Dan
Posted: Thu Sep 04, 2003 5:48 pm
by volka
a lot of the script is missing, isn't it?
Could you please post more?
More script
Posted: Thu Sep 04, 2003 6:15 pm
by sauron98
Thanks so much for looking wasnt sure if anyone wanted more:
heres the whole problem page...to see the problem you can goto
http://www.hiphopmusicsource.co.uk the first page is the problem...you will see the missing row of cds....
thank you so much any pointers would be helpful
Code: Select all
<?php
include "common.php";
$sql="select count(*) as rnum from tblcd" ;
$result=mysql_query($sql);
$row=mysql_fetch_array($result);
$rnum=$row[rnum];
if($rnum>0)
{
$mod=$rnum%8;
if($mod>0)
{
$tpage=($rnum-$mod)/8 +1;
}
else
{
$tpage=($rnum-$mod)/8;
}
if($cpage=="")
{
$cpage=1;
}
$skip=($cpage-1)*8;
if(($skip+8)>$rnum)
{
$lmt=$rnum-$skip;
}
else
{
$lmt=6;
}
$start=$skip +1;
$end=$skip + $lmt;
}
else
{
$val="No CD Found";
echo "sorry no CDs available...";
}
//echo "<br>skip=".$skip;
//echo "<br>lmt=".$lmt;
//$skip=1;
?>
<html>
<head>
<script>
function view(cd_id,cd_title,cd_image)
{
win1=window.open("view_cd_image.php?cd_id="+cd_id+"&cd_title="+cd_title+"&cd_image="+cd_image,"main","");
}
function search()
{
var cd_id=document.searchfrm.cd_id.value;
//alert(cd_id);
if(cd_id!="All")
{
win1=window.open("view_cd_details.php?cd_id="+cd_id,"","width=700,height=60000,top=10,bottom=100")
}
else
{
location.href="all_view.php"
//win1=window.open("all_view.php","","width=510,height=510,top=100,bottom=100")
}
}
</script>
<script language="JavaScript">
<!--
function MM_reloadPage(init) { //reloads the window if Nav4 resized
if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
// -->
</script>
</head>
<?
if($val!="No CD Found")
{
?>
<body bgcolor="#000000" link="#000000" topmargin="0" marginwidth="0" marginheight="0" leftmargin="0">
<div id="Layer4" style="position:absolute; width:200px; height:103px; z-index:19; left: 540px; top: 104px">
<table width="216" border="0" height="131" cellpadding="0" cellspacing="0" align="center" bgcolor="#000000">
<tr>
<td height="42" bgcolor="#000000">
<form name="test" method="post" action="http://www.hiphopmusicsource.co.uk/cgi-sys/FormMail.cgi">
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="200" height="35" align="middle">
<param name=movie value="../join.swf">
<param name=quality value=high>
<embed src="../join.swf" quality=high pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="200" height="35" align="middle">
</embed>
</object>
<input type="text" name="emailaddress" size="15">
<input type="image" border="0" name="imageField" src="../submit.jpg" align="top" width="32" height="24">
<br>
<input type="hidden" name="recipient" value="sales@hiphopmusicsource.co.uk">
<input type="hidden" name="title" value="RESULT FROM MAILING LIST SUBMISSION FORM">
<input type="hidden" name="redirect" value="http://www.hiphopmusicsource.co.uk/hiphopmu/email.php">
<input type="hidden" name="subject" value="DANS MAILING LIST SUBMISSION">
<input type="hidden" name="missing_fields_redirect" value="http://www.hiphopmusicsource.co.uk/hiphopmu/emailerror.php">
<input type="hidden" name="required" value="emailaddress">
<br>
</form>
</td>
</tr>
<tr>
<td width="74%" height="55"> </td>
</tr>
</table>
</div>
<div id="Layer1" style="position:absolute; width:525px; height:257px; z-index:100; left: 14px; top: 101px; background-color: #000099; layer-background-color: #000099; border: 1px none #000000">
<table border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#000099" width="525" height="195" bordercolor="#000000">
<tr>
<td align="center" height=20 colspan=9 bgcolor="#FF0000" valign="top" bordercolor="#000000">
<div align="left"> <img src="../images/newreleases.jpg" width="283" height="18" align="absmiddle"> </div>
</td>
</tr>
<tr>
<td align="center" height=13 colspan=9 bgcolor="#000099" valign="top" bordercolor="#000000"> </td>
</tr>
<?
if($rnum>0)
{
$sql="select * from tblcd order by cd_id desc limit $skip,$lmt";
//echo $sql;
$result=mysql_query($sql,$link);
$x=1;
$y=1;
$temp_i=8/4;
for($cnt_i=1;$cnt_i<=$temp_i;$cnt_i++)
{
?>
<tr>
<?
for($cnt_j=1;$cnt_j<=4;$cnt_j++)
{
while($row=mysql_fetch_array($result))
{
if($x<=3)
{
?>
<td height="83" valign=top align=center bgcolor="#000099">
<div align="center"><a href="" onClick="view('<?echo $row[cd_id];?>','<?echo $row[cd_title];?>','<?echo $row[cd_image];?>');return false;">
<?php print "<img src='cd_image/$row[cd_image]' border='0' width=120 height=120>";?>
</a> <br>
<font color="#FFFFFF" size="2" face="Tahoma"> <b>
<?echo $row[cd_title];?>
<b> </b></b></font><b><b> <br>
<a href="<?echo $row[cd_url];?>"><img src="../images/buy.gif" width="70" height="23" border="0"></a><a href="<?echo $row[audio_url];?>"><img src="../images/play.gif" width="70" height="23" border="0"></a><br>
</b></b></div>
</td>
<?
$x=$x+1;
}
else
{
if($y==1)
{?>
</tr>
<tr>
<?}?>
<?
if($y<=3)
{
?>
<td align=center height="38" valign="top">
<div align="center"><a href="" onClick="view('<?echo $row[cd_id];?>','<?echo $row[cd_title];?>','<?echo $row[cd_image];?>');return false;"><br>
<?php print "<img src='cd_image/$row[cd_image]' border='1' width=120 height=120>";?>
</a> <br>
<font color="#ffffff" size="2" face="Tahoma"> <b>
<?echo $row[cd_title];?>
<b> </b></b></font><b><b> <br>
<a href="<?echo $row[cd_url];?>" target="main" style=text-decoration:none>
<img src="../images/buy.gif" width="70" height="23" border="0"></a><a href="<?echo $row[audio_url];?>"><img src="../images/play.gif" width="70" height="23" border="0"></a><br>
<br>
</b></b></div>
</td>
<?
$y=$y+1;
}//end if
?>
<?if($y>3){?>
</tr>
<tr>
<td align=right height="19" valign="top">
<div align="right"></div>
</td>
</tr>
<?}?>
<?
}//end else
}//end while
}//end for j
}//end for i
?>
</table>
</div>
<?
}//end if $rnum
}//end if $val
?>
<div id="Layer2" style="position:absolute; width:213px; height:314px; z-index:101; left: 543px; top: 171px; background-color: #000099; layer-background-color: #000099; border: 1px none #000000"></div>
<div id="Layer3" style="position:absolute; width:212px; height:17px; z-index:102; left: 544px; top: 171px; background-color: #FF0000; layer-background-color: #FF0000; border: 1px none #000000">
<div align="center"><img src="../images/latestdvd.jpg" width="159" height="18"></div>
</div>
<div id="Layer5" style="position:absolute; width:141px; height:221px; z-index:103; left: 573px; top: 198px; background-color: #000099; layer-background-color: #000099; border: 1px none #000000">
<div align="center"><img src="../images/smack3.jpg" width="156" height="217"></div>
</div>
<div id="Layer6" style="position:absolute; width:200px; height:32px; z-index:104; left: 548px; top: 418px"><img src="../images/dvdtitlefrontpage.jpg" width="204" height="32"></div>
<div id="Layer7" style="position:absolute; width:198px; height:24px; z-index:105; left: 551px; top: 453px"><a href="http://www.hiphopmusicsource.co.uk/samples/smack356k.wmv"><img src="../images/56.gif" width="99" height="23" border="0"></a><a href="http://www.hiphopmusicsource.co.uk/samples/smack3broadband.wmv"><img src="../images/broadband.gif" width="99" height="23" border="0"></a></div>
<div id="Layer2" style="position:absolute; width:213px; height:268px; z-index:101; left: 543px; top: 490px; background-color: #000099; layer-background-color: #000099; border: 1px none #000000">
<div align="center"><br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
</div>
</div>
<div id="Layer3" style="position:absolute; width:212px; height:17px; z-index:102; left: 544px; top: 490px; background-color: #FF0000; layer-background-color: #FF0000; border: 1px none #000000">
<div align="center"><img src="../images/artistpromotion.jpg" width="159" height="18"></div>
</div>
<div id="Layer8" style="position:absolute; width:200px; height:35px; z-index:106; left: 547px; top: 512px"><img src="../images/artistdesc.jpg" width="203" height="30"></div>
<div id="Layer9" style="position:absolute; width:140px; height:115px; z-index:107; left: 580px; top: 545px"><img src="../images/babe.jpg" width="140" height="138"></div>
<div id="Layer10" style="position:absolute; width:200px; height:32px; z-index:108; left: 549px; top: 688px"><img src="../images/artistdesc2.jpg" width="202" height="59"></div>
<table border="4" align="center" bgcolor="#000099" bordercolor="#000000" cellpadding="0" cellspacing="0" width="750" height="100">
<tr>
<td height="22" width="12%"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="91" height="59" align="right">
<param name=movie value="../stereo.swf">
<param name=quality value=high>
<embed src="../stereo.swf" quality=high pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="91" height="59" align="right">
</embed>
</object></td>
<td bgcolor="#000099"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="260" height="50">
<param name=movie value="../title.swf">
<param name=quality value=high>
<embed src="../title.swf" quality=high pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="260" height="50">
</embed>
</object></td>
<td bgcolor="#FF9900"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="93" height="60">
<param name=movie value="../man.swf">
<param name=quality value=high>
<embed src="../man.swf" quality=high pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="93" height="60">
</embed>
</object></td>
<td><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="284" height="55">
<param name=movie value="../text.swf">
<param name=quality value=high>
<embed src="../text.swf" quality=high pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="284" height="55">
</embed>
</object></td>
</tr>
<tr>
<td colspan="4"> <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="715" height="25" align="middle">
<param name=movie value="../navbar3.swf">
<param name=quality value=high>
<embed src="../navbar3.swf" quality=high pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="715" height="25" align="middle">
</embed>
</object></td>
</tr>
</table>
?>
Posted: Thu Sep 04, 2003 6:49 pm
by volka
ok, had some difficulties to understand your code (maybe because it's abot 2am here) so I've extracted some of the code and reformated it
Code: Select all
<table border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#000099" width="525" height="195" bordercolor="#000000">
<!-- some static rows -->
<?php
if($rnum>0)
{
$sql="select * from tblcd order by cd_id desc limit $skip,$lmt";
$result=mysql_query($sql,$link);
$x=1;
$y=1;
$temp_i=8/4; // <- 8/4? 2!
for($cnt_i=1;$cnt_i<=$temp_i;$cnt_i++) // you want this loop to be executed twice? why?
{
?> <tr><?
for($cnt_j=1; $cnt_j<=4; $cnt_j++)
{
while($row=mysql_fetch_array($result))
{
if($x<=3)
{
?>
<td height="83" valign=top align=center bgcolor="#000099">
<div align="center">
<a href=""
onClick="view('<?echo $row[cd_id];?>','<?echo $row[cd_title];?>','<?echo $row[cd_image];?>');return false;">
<?php print "<img src='cd_image/$row[cd_image]' border='0' width=120 height=120>";?>
</a>
<br />
<font color="#FFFFFF" size="2" face="Tahoma">
<b><?echo $row[cd_title];?></b>
</font>
<br>
<a href="<?echo $row[cd_url];?>">
<img src="../images/buy.gif" width="70" height="23" border="0">
</a>
<a href="<?echo $row[audio_url];?>">
<img src="../images/play.gif" width="70" height="23" border="0">
</a>
<br />
</div>
</td>
<?php
$x=$x+1;
}
else // of: if($x<=3)
{
if($y==1)
{
?> </tr><tr> <?php
}
if($y<=3)
{
?>
<td align=center height="38" valign="top">
<div align="center">
<a href=""
onClick="view('<?echo $row[cd_id];?>','<?echo $row[cd_title];?>','<?echo $row[cd_image];?>');return false;">
<br />
<?php print "<img src='cd_image/$row[cd_image]' border='1' width=120 height=120>";?>
</a>
<br />
<font color="#ffffff" size="2" face="Tahoma">
<b><?php echo $row[cd_title]; ?></b>
</font>
<br />
<a href="<?echo $row[cd_url];?>" target="main" style="text-decoration:none">
<img src="../images/buy.gif" width="70" height="23" border="0">
</a>
<a href="<?echo $row[audio_url];?>">
<img src="../images/play.gif" width="70" height="23" border="0">
</a>
<br /><br />
</div>
</td>
<?php
$y=$y+1;
}//end if
if($y>3){
?>
</tr>
<tr>
<td align=right height="19" valign="top">
<div align="right"> </div>
</td>
</tr>
<?
}
}//end else
}//end while
}//end for j
}//end for i
?>
</table>
</div>
<?php
} //end if $rnum
?>
I also removd some empty tags like <b></b>.
Probably made some mistakes but I'd like you to explain some things to me.
- in outlines what this fragment is meant to do and it's structure
- those two larger <td>-cells containing the onClick=... anchor are identical or should be identical?
- the last part: you're closing the table and div element only if $rnum>0 but they were opened unconditionally outside the if-structure. Why?