Kerotan Posted October 14, 2007 Share Posted October 14, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/73187-solved-table-rows-etc/ Share on other sites More sharing options...
GingerRobot Posted October 14, 2007 Share Posted October 14, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/73187-solved-table-rows-etc/#findComment-369223 Share on other sites More sharing options...
Kerotan Posted October 14, 2007 Author Share Posted October 14, 2007 Yay! That worked, thanks! Now just gotta figure out a way to set it so it changes depending on the user who logs in (If you get what i mean) Quote Link to comment https://forums.phpfreaks.com/topic/73187-solved-table-rows-etc/#findComment-369264 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.