Jump to content

need help with while loop


jakebur01

Recommended Posts

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

Link to comment
Share on other sites

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'];
}

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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