Anzeo Posted April 9, 2007 Share Posted April 9, 2007 Hya, I was wandering: whenever I want data from a query I use this code to eventually get the value in a php var $qry = mysql_query("SELECT * FROM MEMBER WHERE ID='$ID'"); $profile = mysql_fetch_array($qry); $Nick = $profile["Nick"]; The problem is, I use the same way of coding to select only one specific field of my table. So for example when I only need the Nickname, I use this code, but I also use it for generating my profile. My question is: is their an easier way to select only one field and put it in a variable? TIA Link to comment https://forums.phpfreaks.com/topic/46270-solved-how-to-easily-output-mysql-in-php/ Share on other sites More sharing options...
trq Posted April 9, 2007 Share Posted April 9, 2007 My question is: is their an easier way to select only one field and put it in a variable? Not really. In fact there should be more to your code to prevent errors. <?php $sql = "SELECT Nick FROM MEMBER WHERE ID='$ID'"; if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { $row = mysql_fetch_array($result); $Nick = $row["Nick"]; } else { echo "No results found"; } } else { echo "Query failed<br />$sql<br />" . mysql_error(); } ?> Notice however that I only selected Nick in the query instead of the wildcard *. Link to comment https://forums.phpfreaks.com/topic/46270-solved-how-to-easily-output-mysql-in-php/#findComment-225075 Share on other sites More sharing options...
Anzeo Posted April 9, 2007 Author Share Posted April 9, 2007 Thanks! Now I can get on with coding ^^ I appreciate the tip! Link to comment https://forums.phpfreaks.com/topic/46270-solved-how-to-easily-output-mysql-in-php/#findComment-225084 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.