Forum Moderators: coopster

Message Too Old, No Replies

MYSQL Database and PHP help

I need to pull out information from a database

         

lem72

9:54 pm on Feb 13, 2006 (gmt 0)

10+ Year Member



Hi,

Im not the ebst when it comes to explaining thngs so if you need any information mroe i'd be happy to give you it.

I have a database (That i did not create, Im just using it), that is laid out like this:

ID - itemno - elementname - elementdescription
-----------------------------------------------
1 - 998 - title - Brand new house!
2 - 998 - sqft - 807
3 - 998 - address - 1234 one lane
4 - 998 - features - Pool, sauna, backyard, basement

Now what I want to do is write a simple way of storing all of that info so that I can recall it by using something like:

echo $items['sqft']; and it will return 807.

I hope this makes sense.

Thanks!
Greg

lem72

10:54 pm on Feb 13, 2006 (gmt 0)

10+ Year Member



HERE is the answer to the problem incase anyone else ahs the same problem.

---------------------------------------

If your pulling it from mysql just use it like you said...

CODE

$query = "SELECT elementname,elementdescription FROM table WHERE itemno = '998'";
$result = mysql_query($query);

while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo $row['elementname'] . " = " . $row['elementdescription'];
}

If your familiar with multidimensional arrays:

CODE

$query = "SELECT * FROM table";
$result = mysql_query($query);

while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$id = $row['itemno'];
$elementname = $row['elementname'];

$items[$id][$elementname] = $row['elementdescription'];
}

Then you can address it as:

echo $items['998']['sqft'];

jatar_k

4:44 pm on Feb 14, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld lem72,

glad you got it sorted, hopefully we can actually be of help next time. ;)