开发者

display single values from mysql database with php

i know this is a noob question but please bear with me,

i am trying to display a single cell value from a table.

the table is named game-ships and contains fields populated with users info such as;

ship_id , ship_name, login_id , login_name , clan_id , location

stuff like that.

i need to find out where a given users ships are, i cant do this with an array i need to display single values on boxes.

something in the lines of

display a particular user's ships and locations in a way that would be....

display user's ships || display user's ships location,

preferably with a link but its fine without.

This i开发者_Go百科nformation is to be displayed in small boxes on top of the user's screen thats why i need separate boxes.

Thank you for reading this message and helping.


can u provide the explanation with sample data.Below is the way according to my understanding :

select ship_name,location from game-ships where login_id = 'login_user_id' // this will give you the name,location of the ship of the login user


After the execution of the query add this,

foreach($mysql_result as $ship_info) { echo$ship_info->ship_name . ' || ' . $ship_info->location; } since u need to display the ship name and respective location separate,u would not have to make a conection to the database for the above query will help u & & later u have to iterate thru the array as mentioned


So what's the problem with arrays? First you select the data ('ship_id, ship_name, location'), then fetch it into the $ships array. Then you just iterate over it and display in a way you want.

foreach($ships as $ship)
{
 echo $ship['ship_name'] . ' || ' . $ship['location'];
}

One more thing. Maybe I just got it wrong, but to allow user to have several ships, you need to modify your database structure. You need a one-to-many relation. It means, that you should split your table. So you'll have a user table with id, login, clan_id and a ship table with id, user_id, name, location which refers to the user

edited

Array is array. It's just data and does not show up by itself. Sending it to the browser is your job. You need to iterate over it and print the rows->fields that you want.

For example, you got 3 user's ships from the database. To print only the last ship's name, you would

echo ships[2]['ship_name']; 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜