Jump to content

marcus

Members
  • Posts

    1,842
  • Joined

  • Last visited

Posts posted by marcus

  1. try this

     

    <?php
    
    mysql_connect($sqlhost, $sqluser, $sqlpass) or die(mysql_error());
    mysql_select_db($sqldb);
    
    $client = mysql_real_escape_string($_POST['username']);
    $pass = mysql_real_escape_string($_POST['password']);
    
    if ($client && $pass) {
        $sql = "SELECT * FROM `users` WHERE `user`='" . $client . "'";
        $res = mysql_query($sql) or die(mysql_error());
        if (mysql_num_rows($res) == 0) {
            echo "Username does not exist!\n";
        } else {
            $sql2 = "SELECT * FROM `users` WHERE `user`='" . $client . "' AND `pass`='" .
                md5($pass) . "'";
            $res2 = mysql_query($sql2) or die(mysql_error());
            if (mysql_num_rows($res2) == 0) {
                echo "Invalid username and password combination!\n";
            } else {
                // log them in
            }
        }
    } else {
        echo "You must supply both username and password!\n";
    }
    
    ?>
    

  2. Why don't you just limit the query?

     

    <?php
    
    $result = mysql_query("
    SELECT t.topic_id, t.forum_id, t.topic_title, t.topic_first_post_id, t.topic_time, p.post_text, p.topic_id
    FROM phpbb_topics AS t, phpbb_posts AS p
    WHERE t.forum_id='$newsID' AND t.topic_first_post_id=p.topic_id
    ORDER BY t.topic_time DESC LIMIT 5
    ") or exit(mysql_error());
    
    
    $i = 0;
    while ($data = mysql_fetch_array($result)) {
        $date = $data['topic_time'];
        $title = $data['topic_title'];
        $id = $data['topic_id'];
        $post = $data['post_text'];
        echo '<div class="body_news">' .
            '<a href="http://syncproductions.exofire.net/viewtopic.php?f=' . $newsID . '&t=' .
            $id . '"/>' . $title . '</a><br />' . 'Posted on: ' . $date . '<br />' .
            '<hr />' . $post . '</div>';
            
        $i++;
    }
    
    ?>
    

  3. <?php
    $query = "SELECT * FROM `firms` ORDER BY firmid DESC";
    $result = mysql_query($query) or die(mysql_error());
    
    if(mysql_num_rows($result) > 0){
    while($row = mysql_fetch_assoc($result)){
    	$text = (strlen($row['field']) > 0) ? "{$row['field']}<br>" : "";
    	echo $text;
    }
    }else {
    echo "There are no firms available";
    }
    ?>
    

  4. $string = "teststring";
    
    for($i=0;$i<strlen($string);$i++){
    echo "<div class=\"".$string[$i]."\"></div>\n";
    }
    

     

    Worked for me.

     

    Function wise could be:

     

    function convert2div($string){
    for($i=0;$i<strlen($string);$i++){
    	$text .= "<div class=\"".$string[$i]."\"></div>\n";
    }
    
    return $text;
    }
    
    echo convert2div('monkeys');
    

  5. When adding, each item has it's own row. So right after adding them, select the duplicates, update the duplicates and add the amount to ONE row that is the same item, then delete all but one row of the duplicates.

     

    So say:

     

    itemid 23 has a 4 quantity of item 6

    itemid 24 has a 1 quantity of item 6

     

    So select duplicates, the last duplicate would be itemid 24, so take that quantity, add it to itemid 23, you'll have 5 quantity for itemid 23, then delete itemid 24

  6. Forget that code. I've replaced it with a new code.

     

    			$items = $_POST['items'];
    
    			if(count($items) > 0){
    				foreach($items AS $item){
    					$item = protect($item);
    					$sql = "SELECT * FROM `user_items` WHERE `place`='inventory' AND `id`='".$item."'";
    					$res = mysql_query($sql) or die(mysql_error());
    					$error = (mysql_num_rows($res) == 0) ? "1" : "0";
    				}
    
    				if($error == '1'){
    					echo "There was an error processing your request!\n";
    				}else {
    					foreach($items AS $item1){
    						$sql2 = "SELECT * FROM `user_items` WHERE `id`='".$item1."' AND `place`='inventory'";
    						$res2 = mysql_query($sql2) or die(mysql_error());
    						$row = mysql_fetch_assoc($res2);
    						$item_id = $row['item_id'];
    						$sql3 = "INSERT INTO `user_shop_items` (`uid`,`item_id`,`quantity`,`price`) VALUES('".$_COOKIE['uid']."','".$item_id."','1','0')";
    						$res3 = mysql_query($sql3) or die(mysql_error());
    						$sql4 = "DELETE FROM `user_items` WHERE `id`='".$item1."' AND `place`='inventory' AND `uid`='".$_COOKIE['uid']."'";
    						$res4 = mysql_query($sql4) or die(mysql_error());
    					}
    
    					$sql5 = "SELECT * FROM `user_shop_items` WHERE `uid`='".$_COOKIE['uid']."'";
    					$res5 = mysql_query($sql5) or die(mysql_error());
    						while($row2 = mysql_fetch_assoc($res5)){
    
    						}
    				echo count($items) . " items have been added to your shop! <a href=\"/users/shop.php?act=stock\">Click here</a> to edit your stock, or <a href=\"/users/shops.php?act=add\">click here</a> to add more items.\n";
    				}
    			}
    

     

    Inside that while statement, how could I go about checking for multiple items in the table, and if there are, group them together, and delete one of them.

     

    id     uid   item_id  quantity  price
    24 	1 	88 	1 	0
    23 	1 	87 	1 	0
    25 	1 	88 	1 	0
    

     

    How to group 24 and 25?

  7. I am creating a "market," and the problem I have now is that, if the user has more than one of the same item in their inventory, all of them will be added, instead of the ones selected.

     

    <?php
    if($act == 'add'){
    		if(!$_POST['submit']){
    			$sql = "SELECT * FROM `user_items` WHERE `uid`='".$_COOKIE['uid']."' AND `place`='inventory'";
    			$res = mysql_query($sql) or die(mysql_error());
    
    			if(mysql_num_rows($res) == 0){
    				echo "<br>You do not have any items in your inventory!";
    			}else {
    				echo "<table border=\"0\" cellspacing=\"3\" cellpadding=\"3\" class=\"forum\">\n";
    				echo "<form method=\"post\" action=\"/users/shops.php?act=add\">\n";
    				echo "<tr><td colspan=\"5\" align=\"center\" class=\"forum_title\">Add Items to Your Shop</td></tr>\n";
    				echo "<tr>\n";
    					$x=1;
    					while($row = mysql_fetch_assoc($res)){
    						$item_name = itemInfo($row['item_id'],'name');
    						$trade = itemInfo($row['item_id'],'trade');
    						$image = "/images/items/" . itemInfo($row['item_id'],'folder') . "/" . itemInfo($row['item_id'],'image');
    						echo "<td align=\"center\" valign=\"top\"><img src=\"".$image."\" alt=\"".$item_name."\" title=\"".$item_name."\"><br><b>".$item_name."</b>";
    							if($trade > 0){
    								echo "<br><input type=\"checkbox\" name=\"items[]\" value=\"".$row['id']."\">\n";
    							}
    						echo "</td>\n";
    
    							if($x == '5'){
    								echo "</tr><tr>\n";
    								$x=0;
    							}
    					$x++;
    					}
    				echo "</tr>\n";
    				echo "<tr><td colspan=\"5\" align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Add the Selected Items\" class=\"forum_submit\"></td></tr>\n";
    				echo "</form></table>\n";
    			}
    		}else {
    			$items = $_POST['items'];
    
    			if(count($items) > 0){
    				foreach($items AS $item){
    					$item = protect($item);
    					$sql = "SELECT * FROM `user_items` WHERE `place`='inventory' AND `id`='".$item."'";
    					$res = mysql_query($sql) or die(mysql_error());
    					$error = (mysql_num_rows($res) == 0) ? "1" : "0";
    				}
    
    				if($error == '1'){
    					echo "There was an error processing your request!\n";
    				}else {
    					foreach($items AS $items1){
    						$item1 = protect($item1);
    						$sql2 = "SELECT * FROM `user_items` WHERE `place`='inventory' AND `id`='".$items1."'";
    						$res2 = mysql_query($sql2) or die(mysql_error());
    						$row = mysql_fetch_assoc($res2);
    						$sql3 = "SELECT * FROM `user_items` WHERE `item_id`='".$row['item_id']."' AND `uid`='".$_COOKIE['uid']."' AND `place`='inventory'";
    						$res3 = mysql_query($sql3) or die(mysql_error());
    						$row2 = mysql_fetch_assoc($res3);
    						$itema = array();
    						echo mysql_num_rows($res3);
    							if(mysql_num_rows($res3) > 1){
    								$itema[$items1]['quantity'] = mysql_num_rows($res3);
    								$itema[$items1]['item_id'] = $row['item_id'];
    							}else {
    								$itema[$items1]['quantity'] = '1';
    								$itema[$items1]['item_id'] = $row['item_id'];
    							}
    					}
    
    					echo "<pre>\n";
    					print_r($itema);
    					echo "</pre>\n";
    					/*
    					foreach($itema AS $item2){
    						$sql4 = "INSERT INTO `user_shop_items` (`uid`,`item_id`,`quantity`,`price`) VALUES('".$_COOKIE['uid']."','".$itema[$item2]['item_id']."','".$itema[$item2]['quantity']."','0');";
    						$res4 = mysql_query($sql4) or die(mysql_error());
    						$sql5 = "DELETE FROM `user_items` WHERE `id`='".$item2."' AND `place`='inventory' AND `uid`='".$_COOKIE['uid']."'";
    						$res5 = mysql_query($sql5) or die(mysql_error());
    					}
    					*/
    				echo count($items) . " have been added to your shop! <a href=\"/users/shop.php?act=stock\">Click here</a> to edit your stock, or <a href=\"/users/shops.php?act=add\">click here</a> to add more items.\n";
    				}
    			}
    		}
    	}
    ?>
    

  8. That's one messy code.

     

    You're better off listing the ranks in a table.

     

    $sql = "SELECT * FROM `ranks`";
    $res = mysql_query($sql) or die(mysql_error());
    
    while($row = mysql_fetch_assoc($res)){
    $check = ($row['id'] == $position) ? " CHECKED" : "";
    
    echo "<option value=\"{$row['id']}\"$check>{$row['name']}</option>\n";
    }
    

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