I will admit right now I have gone through all of the posts though I went through to 2008. My problem is that the if else statement is only receiving one row and calling all the others false off of both of the while loops or receives 2 when you use the form. I am trying to see if in all the rows if a item is bought using 2 different databases. Here is the code.
$id2 = $_SESSION['id'];
$naturesql = mysql_query("SELECT * FROM backgrounds WHERE type=2");
while($row = mysql_fetch_array($naturesql)) {
$id = $row['id'];
$name = $row['name'];
$background = $row['background'];
$pic = $row['image'];
$check = mysql_query("SELECT * FROM store_items WHERE userid='$id2'");
while($checkrow = mysql_fetch_array($check)) {
$types = $checkrow['type2'];
}
if($id == $types) {
$bought = 'This item has already been bought';
} else {
$bought = '<form>
</form>';
// this form works fine
}
$display .= '<table width="100%"><tr><td><center><font size="+1">' . $name . '</font></center></td></tr><tr><td><center><img src="' . $pic . '" width="80px"></img></center></td></tr><tr><td>' . $bought . ' </td></tr></table>';
}
...
<?php echo $display ?>
What shows up.
1st result
Name 1
Pic 1
form shows up here2nd result
Name 2
Pic 2
form also shows up here3rd and last result
Name 3
Pic 3
This item has already been bought
This is what I get when I look on the page. If I bought a item this is what I get lets say 1st item.
1st result
Name 1
Pic 1
This item has already been bought2nd result
Name 2
Pic 2
form also shows up here3rd and last result
Name 3
Pic 3
This item has already been bought
It pops this up. Though when I refresh turns back into the the 1st one I shown only showing 1 result. Any thoughts why not working with the others.
It should be like this if you bought all but is not
1st result
Name 1
Pic 1
This item has already been bought2nd result
Name 2
Pic 2
This item has already been bought3rd and last result
Name 3
Pic 3
This item has already been bought
My only other question is there an alternative to this so keeps the loop and checks if the statement is true or not like a if else statement. If I can’t do it with if else statement.
I can’t post everything on here though here should give some in site what I did to get this to work. Surprisingly it worked like a charm. Note to everyone putting in 2 tables in one mysql_query didn’t help at all it just made things worse. So I wouldn’t advise it for this.
Simple version I did
Like I promised I would post if I figured it out. Might of toke a little longer then I hoped but well there you go.