Jump to content


Photo

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


  • Please log in to reply
8 replies to this topic

#1 jwwceo

jwwceo
  • Members
  • PipPipPip
  • Advanced Member
  • 212 posts

Posted 04 September 2006 - 11:19 PM

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...

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.????

I've pasted the relevant code here...

$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>";
?>


#2 switchdoc

switchdoc
  • Members
  • PipPip
  • Member
  • 22 posts
  • LocationColorado

Posted 05 September 2006 - 12:04 AM

What if $column is 0 instead of 1?

#3 jwwceo

jwwceo
  • Members
  • PipPipPip
  • Advanced Member
  • 212 posts

Posted 05 September 2006 - 12:25 AM

That just makes the items display in 6 columns across....instead of 5.


#4 Unknown User

Unknown User
  • Members
  • PipPip
  • Member
  • 16 posts

Posted 05 September 2006 - 12:30 AM

but you still don't get the last item? ...

#5 jwwceo

jwwceo
  • Members
  • PipPipPip
  • Advanced Member
  • 212 posts

Posted 05 September 2006 - 12:33 AM

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.....

#6 Unknown User

Unknown User
  • Members
  • PipPip
  • Member
  • 16 posts

Posted 05 September 2006 - 12:44 AM

Okay, bit of a stab in the dark but

while($info = mysql_fetch_array( $data ))

try something like

$info = mysql_fetch_array( $data );

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

//all that other stuff

$info = mysql_fetch_array( $data );
}

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.

#7 jwwceo

jwwceo
  • Members
  • PipPipPip
  • Advanced Member
  • 212 posts

Posted 05 September 2006 - 01:36 AM

That actually makes one less  item show up......

#8 Unknown User

Unknown User
  • Members
  • PipPip
  • Member
  • 16 posts

Posted 05 September 2006 - 11:50 AM

Aww. :(

#9 Unknown User

Unknown User
  • Members
  • PipPip
  • Member
  • 16 posts

Posted 05 September 2006 - 11:56 AM

Huh, i'm suprised i didn't notice that, well it was 2AM.

Well anyway, all the code in

if ($column <= 5) {
copy below this

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

$column = 1;


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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users