Jump to content

[SOLVED] Table rows etc..


Kerotan

Recommended Posts

Ive just started working on php/MySQL and have been messing around with it.

Atm im having trouble with pulling certain stuff out of the MySQL tables and was wondering if someone could help me..

 

Im trying to get it so that it pulls a certain bit of information from a certain row and displays it, at the minute ive only figured out how to pull ALL the data for each row and display it and i couldn't find anywhere on how to pull only certain rows.

 

My current code is..

Money: <?php

$result = @mysql_query('SELECT money FROM users');
if (!$result) {
exit('<p>Error performing query: ' . mysql_error() . '</p>');
}

while ($row = mysql_fetch_array($result)) {
echo $row['money'] ;
}

?>
<br>
<br>
Bullets: <?php

$result = @mysql_query('SELECT bullets FROM users');
if (!$result) {
exit('<p>Error performing query: ' . mysql_error() . '</p>');
}

while ($row = mysql_fetch_array($result)) {
echo $row['bullets'];
}

?>

 

Anyone able to help?

Link to comment
Share on other sites

Erm, you already are retrieving one field from the row - you are definingwhich field you want (in the first case money, in the second bullets) rather than selecting everything (*).

 

I assume you mean you only want to retrieve one particular row, rather than all of them? In which case, you probably want to add a WHERE clause to your query. You probably want to only select a particular user based on an id:

$result = @mysql_query("SELECT money FROM users WHERE id = '$userid'");

 

In which case, you'd have no need for the while loop and can simply use:

 

$row = mysql_fetch_array($result); 
echo $row['money'];

 

There were a lot of 'probably's in that, but since i dont actually know what you're trying to do, i can't offer anything more specific.

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.