Jump to content

Archived

This topic is now archived and is closed to further replies.

jwwceo

problem with databse query maybe???-SOLVED. PLEASE IGNORE!THANKS!

Recommended Posts

Hello,

I am trying to fix a bug on this page:  www.liquidcotton.com

For some reason it only displays 6 items when there are 7 in the database....

cannot figure out why.... On my local computer there is a different set of sample data and the same thing happens....been working on this for a few days...

[b]I JUST FIGURED OUT THAT THE DATABSE IS SKIPPING EVERY 6th ITEM. THAT IS, IT IS OUTPUTTING 5, THEN SKIPPING ONE, OUTPUTTING 5, THEN SKIPPING ONE...THEN, LOOKING AT THE CODE..I THINK IT IS USING ONE OF THE ROW LOOPS IN MY MAIN WHILE STATEMENT TO JUST RESET MY COLUMN TO ONE...THAT IS, FOR EVERY 6TH ROW RETURNED IT SKIPS THE OUTPUT AND  JUST CLOSES THE <TR> AND RESETS THE COUNTER TO 1....ANY TIPS ON HOW TO NOT DO THIS.????[/b]

I've pasted the relevant code here...

[code]
$data = mysql_query("SELECT * FROM shirts") or die(mysql_error());

$column = 1;

echo

"<table>
  <tr><td width='680' height='95'><a href='liquid.php'><img src='images/logo.gif' width='271' height='67' border='0'></a></td></tr>
  <tr><td width='680' bgcolor='#CCCCCC' height='25'><div align='center'>
        <table border='0' cellspacing='0' style='border-collapse: collapse' bordercolor='#111111' width='650' cellpadding='0'>
          <tr>
            <td width='24%' align='left'><form method='get' action ='index.html'>
            <p valign='middle'><select name='sort' class='cartForm'>
<option>Thumbnail Sort Options:</option>
<option>-------------------------</option>
<option  value='index.php'>Alphabetical</option>
<option  value='index/name'>Highest Ranked</option>
<option  value='/male/newest'>Newest first</option>
<option  value='/male/oldest'>Oldest first</option>
</select></form></p></td>
            <td width='10%'><input type='submit' class ='cartForm' value='Go!'></td>
            <form method ='get' action ='shirtresults.php'>
            <td width='66%'><p valign='middle' align='right'>
            <input type='text' size='25' name='keyword' class='cartForm'>
            <input type='submit' class ='cartForm' value='Search'>
            </form></p></td>
            </tr>
        </table></div>
        </td></tr>
  <tr><td width='680'>
        <img border='0' src='images/spacer.gif' width='15' height='15'></td></tr>
    <tr>


  <td width='680'><div align='center'>
<table border='0' cellspacing='0' style='border-collapse: collapse' bordercolor='#111111' width='680' cellpadding='0'>
  <tr>";


while($info = mysql_fetch_array( $data )) {  // while statement that repeats for every time a row is returned

$selectedshirtid = $info['shirt_id'];


if ($column <= 5) {    //if statment to see if the column is less than 5

echo "<td width='136' align='center' valign='top'>
<table border='0' cellspacing='0' style='border-collapse: collapse' width='128' cellpadding='0'>
  <tr> <td colspan='5' >
  <p align='center'><a href='".$info['link']."'><b>".$info['name']."</b></a></td>
  </tr>
  <tr>
<td colspan='5' height='128'>
<p align='center'><a href='".$info['link']."'>
<img border='0' src='".$info['image']."' width='121' height='121'></a></td>
  </tr>
  <tr>
<td width='30'>
<p align='center'><a href='".$info['link']."'>$10</a></td>
<td width='21'>
<p align='center'>
<img border='0' src='images/thumbup.gif' width='19' height='19'></td>
<td width='21'>5</td>
<td width='21'>
<p align='center'>
<img border='0' src='images/thumbdown.gif' width='19' height='19'></td>
<td width='21'>6</td>
  </tr>
  <tr><td colspan='5' height ='5'  align = 'center'><font size='1'><a href='wasup'>Show me more like this.</a></font> </td></tr>
  <tr>
<td width='100%' colspan='5' align='center'>
<table border='0'  height ='5' cellspacing='0' style ='border-collapse: collapse' width ='110' cellpadding ='0' align='center'>

<tr>
<td width='45' align='left' valign='middle' ><font size='1'>

<A class=\"bodylink\" onmouseover=\"ypSlideOutMenu.showMenu('menu{$selectedshirtid}C');\" onmouseout=\"ypSlideOutMenu.hideMenu('menu{$selectedshirtid}C');\" href=\"wasup\"><font size='1'>Colors[+]</font></a></td>

<td background ='images/dividerbg.gif' width='65' align='right' valign='middle' background ='images/dividerbg.gif'>


<A class=\"bodylink\" onmouseover=\"ypSlideOutMenu.showMenu('menu{$selectedshirtid}');\" onmouseout=\"ypSlideOutMenu.hideMenu('menu{$selectedshirtid}');\" href=\"wasup\"><font size='1'>Keywords[+]</font></a>
</td>
</tr>
</table>
</td>

</tr>
<tr><td colspan='5'><img src='images/line.gif'></td></tr>
</table>
</td>";

$column ++;

}                  //end of if statement that checks to see the row is up to 5 iimages

else {
echo "</tr><tr>";  //this ends the row

$column = 1;

//resets the column to 1
}             //end bracket for the else statement that sets the column back to 1

}//ends big while loop

echo "</table>";
?>
[/code][font=Verdana][/font]

Share this post


Link to post
Share on other sites
nope..only 6 items...but there are clearly 7 in the databse....I jsut double checked with phpMyAdmin...

this is really wierd... as the code looks fine to me.....

Share this post


Link to post
Share on other sites
Okay, bit of a stab in the dark but

while($info = mysql_fetch_array( $data ))

try something like

[code]$info = mysql_fetch_array( $data );

while($info['link'] > 0){

//all that other stuff

$info = mysql_fetch_array( $data );
}
[/code]

so you set $info once before the loop starts to make sure you have somehting, then re-sets it at the end of the while loop rather than the beggining.

Share this post


Link to post
Share on other sites
Huh, i'm suprised i didn't notice that, well it was 2AM.

Well anyway, all the code in

[code]if ($column <= 5) {[/code]
copy below this

[code]else {
echo "</tr><tr>";  //this ends the row

$column = 1;[/code]


Then after ending the row, it will add the next item. There might be an easyer way but, y'know.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.