Minase Posted June 10, 2008 Share Posted June 10, 2008 hy there,i do have 2 tables and in one of them i do have defined some items (lets say power,vitality etc etc) and in another table i do have users items (if someone buy a item,then the item will be inserted into the users_items table.every item has an uniq ID and user ID i need a query and php code that select all items from users_items then echo them.the items will need to have descriptions that is resided in the first table called items. STRUCTURE: items -> Hold items info users_items -> what items users have first echo all users_items where ID=$id then in the same part with echo ,the items details defined in variable $details thank you Link to comment https://forums.phpfreaks.com/topic/109600-phploop/ Share on other sites More sharing options...
webent Posted June 10, 2008 Share Posted June 10, 2008 Without seeing more of your table structures, all I can tell you is that the best way would be to use a JOIN query... or you could embed the second query inside your while($row = mysql_fetch_array) of the first query... Link to comment https://forums.phpfreaks.com/topic/109600-phploop/#findComment-562200 Share on other sites More sharing options...
Minase Posted June 10, 2008 Author Share Posted June 10, 2008 still dont get it,i want the part with WHILE,i did use in the past,but i had a messy code then,now its a bit better,but i dont know how to make this to work,here is my code $query1 = "SELECT * FROM `" . DBPREFIX . "users` WHERE `ID` = " . $db->qstr($_SESSION['user_id']); $user = $db->getRow($query1); $query2 = "SELECT * FROM `" . DBPREFIX . "items` WHERE `ShowLvl` <= " . $db->qstr1($user->Level); $result = mysql_query($query2); while ($item = mysql_fetch_row($result)) { $iid = $item[0]; $iname = $item[1]; $istrenght = $item[2]; $ipstrenght = $item[3]; $iagility = $item[4]; $idefence = $item[5]; $ipdefence = $item[6]; $iendurance = $item[7]; $icharisma = $item[8]; $ibuy = $item[9]; $isell = $item[10]; $ilevel = $item[11]; $istone = $item[12]; $ishowlvl = $item[13]; $ikind = $item[14]; $iimg = $item[15]; $idescription = $item[16]; $cquery2 = "SELECT * FROM `" . DBPREFIX . "users_items` WHERE ID=" . $db->qstr($_SESSION['user_id']) . " AND IID = " . $db->qstr1($iid); $users_itemss = $db->getRow($cquery2); $ccount = $db->RecordCount($cquery2); if ($ccount > 0) { $query21 = "SELECT * FROM `" . DBPREFIX . "users_items` WHERE `ID` = " . $db->qstr($user->ID); $result21 = mysql_query( $query21 ); $aactive = mysql_fetch_row( $result21 ); $active = $aactive[3]; if ( $active == 1 ) { $ht = ' class="active"'; $activated = ' <span style="color:orangered">(activated)</span>'; $useit = ''; } else { $ht = ''; $activated = ''; $useit = '<br><a href="?act=1&actkey='.$iid.'" >Activate this item</a> '; } echo ' <td'.$ht.'><img src="img/i/'.$iimg.'.jpg" alt="'.$iname.'" ></td> <td'.$ht.'><strong>'.$iname.' '.$activated.'</strong><br> Number: '.$ccount.' '; if ($istrenght > 0) { echo '<br>Force +', $istrenght; } elseif ($istrenght == 0) { } elseif ($istrenght < 0) { echo '<br>Strenght ', $istrenght; } Link to comment https://forums.phpfreaks.com/topic/109600-phploop/#findComment-562205 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.