jakebur01 Posted March 13, 2008 Share Posted March 13, 2008 This is only returning one row for some reason. It is supposed to be pulling and displaying two rows. Thanks, Jake $result = mysql_query("SELECT * FROM dog_listing WHERE `Breed` = '$breed' ORDER BY Date_created ASC ", $db) or die(mysql_error()); echo "<h3>$breed".' '."Puppies</h3>"; echo "<table cellpadding=2 cellspacing=3><tr><td>"; while($myrow = mysql_fetch_array ($result)) { $Link=$myrow['Link']; if($myrow['Link']==0) { echo "<img src=\"images/puppy_holder.jpg\">"; } else { echo "<img src=\"$Link\">"; } echo "</td><td>"; $Breed_id=$myrow['Breed_id']; $Breed=$myrow['Breed']; $Username=$myrow['Username']; $Zip=$myrow['Zip']; $Date_expired=$myrow['Date_expired']; $Expiration=$myrow['Expiration']; $Date_created=$myrow['Date_created']; $Type=$myrow['Type']; $Champion_bloodline=$myrow['Champion_bloodline']; $Champion_sired=$myrow['Champion_sired']; $Price=$myrow['Price']; $Shipping=$myrow['Shipping']; $Description=$myrow['Description']; $Birthdate=$myrow['Birthdate']; $result = mysql_query("SELECT Company, City, State, Phone FROM dog_account WHERE `username` = '$Username' ", $db) or die(mysql_error()); while($myrow = mysql_fetch_array ($result)) { $Company=$myrow['Company']; $City=$myrow['City']; $State=$myrow['State']; $Phone=$myrow['Phone']; } echo "<small><b>$Company</b> - $Date_created</small><hr />"; echo "<b>Type:</b> $Type<br />"; echo "<b>Description:</b> $Description<br />"; echo "<b>Price:</b> $Price<br />"; echo "<b>Birthdate:</b> $Birthdate<br />"; echo "<b>Shipping:</b> $Shipping<br />"; echo "<b>Champion Bloodline?</b> $Champion_bloodline<br />"; echo "<b>Champion Sired?</b> $Champion_sired<br />"; echo "$City, $State | $Phone"; echo "</td></tr>"; } echo"</table>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/95965-need-help-with-while-loop/ Share on other sites More sharing options...
trq Posted March 13, 2008 Share Posted March 13, 2008 Can you indent your code so we can read it? Quote Link to comment https://forums.phpfreaks.com/topic/95965-need-help-with-while-loop/#findComment-491278 Share on other sites More sharing options...
sasa Posted March 13, 2008 Share Posted March 13, 2008 you use same name for both query results ($result) change one of them $result1 = mysql_query("SELECT Company, City, State, Phone FROM dog_account WHERE `username` = '$Username' ", $db) or die(mysql_error()); while($myrow = mysql_fetch_array ($result1)) { $Company=$myrow['Company']; $City=$myrow['City']; $State=$myrow['State']; $Phone=$myrow['Phone']; } Quote Link to comment https://forums.phpfreaks.com/topic/95965-need-help-with-while-loop/#findComment-491349 Share on other sites More sharing options...
soycharliente Posted March 13, 2008 Share Posted March 13, 2008 I found a few errors in your code. Yes, you had your result resource named the name in both instances. Also, you have the row variable named the same. I was honestly trying to figure out if there was a way to JOIN the 2 tables to get all the information at the same time, but I couldn't see anything that related the two. I don't really know exactly what the page does (though I kind of have an idea). It looked like you have your tr and td opening tags in the wrong place as well. Am I mistaken? Maybe this will help as this is how I would have "fixed" it? <?php $result = mysql_query("SELECT * FROM `dog_listing` WHERE `Breed` = '$breed' ORDER BY `Date_created` ASC", $db) or die(mysql_error()); echo "<h3>$breed Puppies</h3>"; echo "<table cellpadding=\"2\" cellspacing=\"3\">"; while($myrow = mysql_fetch_array ($result)) { echo "<tr><td>"; $Link=$myrow['Link']; if($myrow['Link'] == 0) { echo "<img src=\"images/puppy_holder.jpg\" alt=\"\" />"; } else { echo "<img src=\"$Link\" alt=\"\" />"; } echo "</td><td>"; $Breed_id=$myrow['Breed_id']; $Breed=$myrow['Breed']; $Username=$myrow['Username']; $Zip=$myrow['Zip']; $Date_expired=$myrow['Date_expired']; $Expiration=$myrow['Expiration']; $Date_created=$myrow['Date_created']; $Type=$myrow['Type']; $Champion_bloodline=$myrow['Champion_bloodline']; $Champion_sired=$myrow['Champion_sired']; $Price=$myrow['Price']; $Shipping=$myrow['Shipping']; $Description=$myrow['Description']; $Birthdate=$myrow['Birthdate']; $result2 = mysql_query("SELECT Company, City, State, Phone FROM dog_account WHERE `username` = '$Username'", $db) or die(mysql_error()); $mysecondrow = mysql_fetch_assoc($result2); $Company=$mysecondrow['Company']; $City=$mysecondrow['City']; $State=$mysecondrow['State']; $Phone=$mysecondrow['Phone']; echo "<small><b>$Company</b> - $Date_created</small><hr />"; echo "<b>Type:</b> $Type<br />"; echo "<b>Description:</b> $Description<br />"; echo "<b>Price:</b> $Price<br />"; echo "<b>Birthdate:</b> $Birthdate<br />"; echo "<b>Shipping:</b> $Shipping<br />"; echo "<b>Champion Bloodline?</b> $Champion_bloodline<br />"; echo "<b>Champion Sired?</b> $Champion_sired<br />"; echo "$City, $State | $Phone"; echo "</td></tr>"; } echo"</table>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/95965-need-help-with-while-loop/#findComment-491401 Share on other sites More sharing options...
jakebur01 Posted March 13, 2008 Author Share Posted March 13, 2008 Thanks guys! I did some renaming and also moved around my table tags. It works great now! `Jake $result = mysql_query("SELECT * FROM dog_listing WHERE `Breed` = '$breed' ORDER BY Date_created ASC ", $db) or die(mysql_error()); echo "<h3>$breed".' '."Puppies</h3>"; echo "<table cellpadding=2 cellspacing=3>"; while($myrow = mysql_fetch_array ($result)) { echo "<tr><td>"; $Link=$myrow['Link']; if($myrow['Link']==0) { echo "<img src=\"images/puppy_holder.jpg\">"; } else { echo "<img src=\"$Link\">"; } echo "</td><td>"; $Breed_id=$myrow['Breed_id']; $Breed=$myrow['Breed']; $Username=$myrow['Username']; $Zip=$myrow['Zip']; $Date_expired=$myrow['Date_expired']; $Expiration=$myrow['Expiration']; $Date_created=$myrow['Date_created']; $Type=$myrow['Type']; $Champion_bloodline=$myrow['Champion_bloodline']; $Champion_sired=$myrow['Champion_sired']; $Price=$myrow['Price']; $Shipping=$myrow['Shipping']; $Description=$myrow['Description']; $Birthdate=$myrow['Birthdate']; $result1 = mysql_query("SELECT Company, City, State, Phone FROM dog_account WHERE `username` = '$Username' ", $db) or die(mysql_error()); while($myrow1 = mysql_fetch_array ($result1)) { $Company=$myrow1['Company']; $City=$myrow1['City']; $State=$myrow1['State']; $Phone=$myrow1['Phone']; } echo "<small><b>$Company</b> - $Date_created</small><hr />"; echo "<b>Type:</b> $Type<br />"; echo "<b>Description:</b> $Description<br />"; echo "<b>Price:</b> $Price<br />"; echo "<b>Birthdate:</b> $Birthdate<br />"; echo "<b>Shipping:</b> $Shipping<br />"; echo "<b>Champion Bloodline?</b> $Champion_bloodline<br />"; echo "<b>Champion Sired?</b> $Champion_sired<br />"; echo "$City, $State | $Phone"; echo "</td></tr><tr><td> </td></tr>"; } echo"</table>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/95965-need-help-with-while-loop/#findComment-491520 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.