adeang
Code Baboon
 
Karma: +1/-0
Posts: 102
I'm for about anything!
|
 |
« Reply #15 on: November 20, 2008, 07:15:11 AM » |
|
this should do it. <?php
/** * @author Adeang * @copyright 2008 */
$con = mysql_connect("localhost","dbusername","dbpassword"); if (!$con) { die('Could not connect: ' . mysql_error()); }
mysql_select_db("my_db", $con);
$result = mysql_query("SELECT * FROM inventory WHERE ItemQuantity >='1'");
while($row = mysql_fetch_array($result)) { echo $row['ItemName'] . " " . $row['ItemQuantity']; echo "<br />"; }
?>
|
|
|
|
|
Logged
|
I'm for about anything!
|
|
|
adeang
Code Baboon
 
Karma: +1/-0
Posts: 102
I'm for about anything!
|
 |
« Reply #16 on: November 20, 2008, 07:16:40 AM » |
|
The quantity is stored as the default. <?php
$result = mysql_query("SELECT * FROM Armor WHERE quantity > 1");
while($row = mysql_fetch_array($result)) { }
?>
Is what I have, and I get: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource which would be the While part. did you forget to connect to db?
|
|
|
|
|
Logged
|
I'm for about anything!
|
|
|
votter
Donkey Kong Jr.

Karma: +0/-0
Posts: 67
|
 |
« Reply #17 on: November 20, 2008, 03:09:52 PM » |
|
Nothing new came up with it. I make a table with userid as a field, itemid and itemname, right? Then add rows so I can put all itemnames and id's in?
|
|
|
|
|
Logged
|
Forum Spy
|
|
|
adeang
Code Baboon
 
Karma: +1/-0
Posts: 102
I'm for about anything!
|
 |
« Reply #18 on: November 20, 2008, 04:08:34 PM » |
|
and you tried this code? <?php
/** * @author Adeang * @copyright 2008 */
$con = mysql_connect("localhost","dbusername","dbpassword"); if (!$con) { die('Could not connect: ' . mysql_error()); }
mysql_select_db("my_db", $con);
$result = mysql_query("SELECT * FROM inventory WHERE ItemQuantity >='1'");
while($row = mysql_fetch_array($result)) { echo $row['ItemName'] . " " . $row['ItemQuantity']; echo "<br />"; }
?>
|
|
|
|
|
Logged
|
I'm for about anything!
|
|
|
votter
Donkey Kong Jr.

Karma: +0/-0
Posts: 67
|
 |
« Reply #19 on: November 20, 2008, 04:23:28 PM » |
|
If I do that, then everybody will get the same echo, and it only seems to echo out the wrong thing I think. Let me try it again.
|
|
|
|
|
Logged
|
Forum Spy
|
|
|
votter
Donkey Kong Jr.

Karma: +0/-0
Posts: 67
|
 |
« Reply #20 on: November 20, 2008, 04:36:39 PM » |
|
<?php include('stylesheet.php'); ?> <?php include('variables.php'); ?>
<?php
$items = mysql_query("SELECT * FROM Items WHERE ItemQuantity >= '1'");
while($items = mysql_fetch_array($items)) { echo $Items['itemname'] . " " . $Items['ItemQuantity']; echo "<br />"; } mysql_error(); ?>
Is what I have, and I get: Bronze Plate 0 Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in inventory.php on line 9 On the page.
|
|
|
|
|
Logged
|
Forum Spy
|
|
|
adeang
Code Baboon
 
Karma: +1/-0
Posts: 102
I'm for about anything!
|
 |
« Reply #21 on: November 21, 2008, 03:07:43 PM » |
|
okay so what you want to do is get the users game name and put and use it to grab their amount of items? <?php
include_once ('stylesheet.php'); include_once ('variables.php');
//----------------CONNECTS TO DATABASE------------------------// $con = mysql_connect("localhost","dbusername","dbpassword"); if (!$con) { die('Could not connect: ' . mysql_error()); }
mysql_select_db("my_db", $con); //------------------------------------------------------------//
$result = mysql_query("SELECT * FROM inventory WHERE username ='$username' AND WHERE ItemQuantity >='1'");
while($row = mysql_fetch_array($result)) { echo $row['ItemName'] . " " . $row['ItemQuantity']; echo "<br />"; }
?>
and also maybe share some more of the scripts you have made, because we have no idea what is in any of your files that you have included, because maybe in one of the included files you have included another file aka inventory.php
|
|
|
|
|
Logged
|
I'm for about anything!
|
|
|
votter
Donkey Kong Jr.

Karma: +0/-0
Posts: 67
|
 |
« Reply #22 on: November 22, 2008, 06:05:21 PM » |
|
<?php
$result = mysql_query("SELECT * FROM Items WHERE ItemQuantity > 0 AND userid = '$user[id]'"); while($row = mysql_fetch_array($result)) { echo $row['ItemQuantity'] . ": " . $row['ItemName']; echo "<br />"; }
?>
Works now, but I was just wondering how I should create the database or databases for this to work and not have the database/s so giant.
|
|
|
|
« Last Edit: November 22, 2008, 06:19:18 PM by votter »
|
Logged
|
Forum Spy
|
|
|
adeang
Code Baboon
 
Karma: +1/-0
Posts: 102
I'm for about anything!
|
 |
« Reply #23 on: November 23, 2008, 12:57:46 AM » |
|
well no matter what you going to have to have a db full of the items, etc, and have a place to store how much of that item a user has.
p.s. still working on it.
|
|
|
|
|
Logged
|
I'm for about anything!
|
|
|
votter
Donkey Kong Jr.

Karma: +0/-0
Posts: 67
|
 |
« Reply #24 on: November 23, 2008, 06:05:53 AM » |
|
Ya, I know that, just didn't know if I should use 2 or 1 database or what. I'm adding all the items to the table today.
Or I might wait and see what others suggest.
|
|
|
|
« Last Edit: November 23, 2008, 06:24:12 AM by votter »
|
Logged
|
Forum Spy
|
|
|
votter
Donkey Kong Jr.

Karma: +0/-0
Posts: 67
|
 |
« Reply #25 on: November 23, 2008, 10:09:01 AM » |
|
added itemid and itemname to one table, and filled that out.
|
|
|
|
|
Logged
|
Forum Spy
|
|
|
adeang
Code Baboon
 
Karma: +1/-0
Posts: 102
I'm for about anything!
|
 |
« Reply #26 on: November 23, 2008, 01:32:00 PM » |
|
im not an expert but I think you should use 1 db
|
|
|
|
|
Logged
|
I'm for about anything!
|
|
|
votter
Donkey Kong Jr.

Karma: +0/-0
Posts: 67
|
 |
« Reply #27 on: November 23, 2008, 04:41:16 PM » |
|
Ok, Just not sure then How when they register, it would add all those rows with there userid.
mysql_query("INSERT INTO `Inventory` (`userid`, `itemid`, `itemamount`) VALUES ('$user[id]', '1', '1'), ('2', '1')") or die(mysql_error());
I just don't know how you would do this part, so would the userid be VALUES be NULL, and would the database one not be auto increment? lol.
|
|
|
|
« Last Edit: November 23, 2008, 05:06:31 PM by votter »
|
Logged
|
Forum Spy
|
|
|
votter
Donkey Kong Jr.

Karma: +0/-0
Posts: 67
|
 |
« Reply #28 on: November 24, 2008, 04:35:56 PM » |
|
I got it, thanks all for the help.  .
|
|
|
|
|
Logged
|
Forum Spy
|
|
|
adeang
Code Baboon
 
Karma: +1/-0
Posts: 102
I'm for about anything!
|
 |
« Reply #29 on: November 24, 2008, 07:58:01 PM » |
|
awesome!!! can we see an example???
if dont know hot to setup server on comp so others can see it ask me!
|
|
|
|
|
Logged
|
I'm for about anything!
|
|
|
|