General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old August 8th, 2002, 02:09 PM
Decoy Decoy is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 28 Decoy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
while loop woes

Hi there,

I am having a small problem with a script I'm writing. I am generating a list of links dynamically from a database whereby when they are clicked they pass a 'picid' that matches to a corresponding 'homeid' and displays the photo for that link (picture of the house).

The problem arises when the possibility of NO 'homeid' matches the passed 'picid'. This is what I have...

Code:
DbConnect();
global $picid;

if($picid)
{
  $result = @mysql_query("SELECT * FROM pictures where picid = homeid");
  if(!$result)
  {
    echo("ERROR: " . mysql_error() . "\n$sql\n");
    exit();
  }
  while($myrow = mysql_fetch_array($result))
  {
    if(($picid == $myrow["homeid"]) && (!$myrow["url"]))
    {
      echo "<center>Sorry, no additional photos available for this home</center>";
    }
    if($picid == $myrow["homeid"])
    {
      echo "<center><table border=1>\n";          
      echo "<tr><td>$myrow[url]</td></tr></table></center>";
    }
  }
}
else
{
  echo "No ID passed";
}


If I put in a conditional like this in the while statement...
Code:
if($picid != $myrow["homeid"])
{
  echo "Error";
}

it will almost always come back true because it will most likely loop through several times before it finds the right 'homeid', and as a result, print out "Error" numerous times.

I was populating a variable with a certain value if the condition was true, loading the results in an array, and just printing out the first element of the array to prevent it from printing out multiple times, but even if 'picid' matches 'homeid', it will most likely loop through at least once before finding it which results in the printing of the error message.

Any ideas how I can prevent the message from being displayed when there is actually a match even though ($picid != $myrow["homeid"]) will come back true 99.9% of the time in the loop?

Thanks for any help

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > while loop woes


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway