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
https://forums.phpfreaks.com/topic/73187-solved-table-rows-etc/
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
https://forums.phpfreaks.com/topic/73187-solved-table-rows-etc/#findComment-369223
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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