Jump to content

Multiple Looping help - I need a fresh pair of eyes


spires

Recommended Posts

Hi Guys

Thanks for reading this post.

 

I'm just creating a category list page, that is pulling all of the info out of a database.

 

I want it to be displayed like this:

<item1><item2>

<item3><item4>

<item5><item6>

 

However, the best I can get is this:

<item1><item1>

<item2><item2>

<item3><item3>

 

It's displaying the same item twice.

 

Could some one please take a look at my code

an see where I'm going wrong.

 

It could be to do with the way the items are being pulled out

of the database, or the loops them selves.

 

URL: http://reviews4mobilephones.com/handset_list/mobile_phone_reviews_list.html

 

CODE:

<?PHP			

// Select only 1 make of mobile phone
$distinct_sql = "SELECT DISTINCT make FROM phones";
$distinct_query = mysql_query($distinct_sql) or die ("navi query failed".mysql_error());
$distinct_count = mysql_num_rows($distinct_query);

// Select only 1 make of mobile phone LOOP
while ($distinct_row = mysql_fetch_assoc($distinct_query))
{
$distinct_make = $distinct_row['make'];

// Create the Master Table to be looped
echo '
<table width="500px" border="0" cellspacing="0" cellpadding="0">
<tr>
<td background="http://reviews4mobilephones.com/images/products/review_header.jpg" height="22px" class="boxTitle" align="left">   '.ucwords($distinct_make).' Handset List</td>
</tr>
<tr>
<td align="center" background="http://reviews4mobilephones.com/images/products/review_bg.jpg"><br />
<br />';

$phone_loop_sql = "SELECT * FROM phones WHERE make='$distinct_make' ORDER by Pdate DESC";
$phone_loop_result = mysql_query($phone_loop_sql) or die ("Phones Loop failed".mysql_error());
$phone_loop_count = mysql_num_rows($phone_loop_result);

for ($q = 0; $q<$phone_loop_count; $q++)
{
// Phone Loop
$phone_loop_row = mysql_fetch_assoc($phone_loop_result);
$phone_loop_id = $phone_loop_row['phones_id'];
$phone_loop_make = $phone_loop_row['make'];
$phone_loop_model = ucwords($phone_loop_row['model']);


// Creat the inner table
echo '<table width="480px" cellpadding="10" cellspacing="0" border="0">';

// Loop the <TR>
for ($i = 0; $i<1; $i++)
{
echo '<tr>';

// Loop the <TD> - Only 2 columns
for ($j = 0; $j<2; $j++)
{


// Select from the remaining database tables
$key_sql2 = "SELECT * FROM body LEFT JOIN images on body.Bphone_id = images.Iphone_id WHERE Bphone_id='$phone_loop_id'";
$key_result2 = mysql_query($key_sql2) or die ("Multi Select failed".mysql_error());
$key_count2 = mysql_num_rows($key_result2);
$key_row2 = mysql_fetch_assoc($key_result2);
// Body
$body_synopsis = $key_row2['synopsis'];
// Images
$images_Iphone_id = $key_row2['Iphone_id'];
$images_Itype = $key_row2['Itype'];



if ($key_row2) {
// Creat the display tables
echo '<td>
<table width="210px" cellpadding="0" cellspacing="5" border="0">
<tr>
<td valign="top" align="left">
'.$phone_loop_model.'
</td>
</tr>

<tr>
<td valign="top" align="left">
<div class="thumb1"><img src="http://www.reviews4mobilephones.com/images/mobile_phones/thumbs/'.$images_Iphone_id.'.'.$images_Itype.'" width="80px" height="90px" border="0"></div>
<div class="thumb2">'.$body_synopsis.'</div><br>
</td>
</tr>

<tr>
<td valign="top" align="left">
Read Review
</td>
</tr>
</table></td>';
}else{
break;
}

}
echo '</tr>';
}
echo '</table>';		
}
echo '
<br />
<br />
</td>
</tr>
<tr>
<td height="3px" background="http://reviews4mobilephones.com/images/products/review_bottom.jpg"></td>
</tr>
</table>';
}

?>


Hi FIREBALL5

If you go to: http://reviews4mobilephones.com/handset_list/mobile_phone_reviews_list.html

You will see what i'm trying to do.

 

 

Hi Cosizzle:

No I have not tried that yet.

I could give it a go to see if it make a difference.

 

 

Thanks for both your help

Archived

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

×
×
  • Create New...

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.