Jump to content

[PHP]Loop


Minase

Recommended Posts

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
Share on other sites

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
Share on other sites

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