blackwolf23 Posted June 6, 2007 Share Posted June 6, 2007 Hello, I'm having some difficulty formulating query that will allow me to retrieve the details of a specific user in the database. The user's information is stored in one table called Users and another called UserProfile. Both tables are linked by the UserID field. My current query returns a Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource and my knowledge of Mysql is not great(Still learnng) Here is my code: function view_profile($Username) { $conn = connect(); $query ="SELECT Users.Firstname,Users.Surname,Users.Email,Profile.Age FROM Users,UserProfile WHERE Username = '".$Username."' AND Users.UserID = UserProfile.UserID"; $result = mysql_query($query); $num = mysql_numrows($result); mysql_close(); echo "<b><center>Your profile</center></b><br>"; $i=0; while ($i < $num) { $Firstname =mysql_result($result,$i,"Firstname"); $Surname=mysql_result($result,$i,"Surname"); $Email=mysql_result($result,$i,"Email"); $Age=mysql_result($result,$i,"Age"); //echo "<<br>Firstname: $Firstname<br>Surname: $Surname<br>Email: $Email<br>Password: $Password<br> <br>Age: $Age<br>"; $i++; } } Quote Link to comment https://forums.phpfreaks.com/topic/54412-solved-mysql-query-help/ Share on other sites More sharing options...
chocopi Posted June 6, 2007 Share Posted June 6, 2007 I think you are missing as underscore try replacing mysql_numrows with mysql_num_rows Hope that helps ~ Chocopi Quote Link to comment https://forums.phpfreaks.com/topic/54412-solved-mysql-query-help/#findComment-269046 Share on other sites More sharing options...
blackwolf23 Posted June 6, 2007 Author Share Posted June 6, 2007 I did some error checking and fixed a mistake where Profile.Age should be UserProfile.Age which removed the error message from appearing but my View_Profile function displays nothing when I test it by going to the View Profile page. This query works and allows me to display the user's profile $query = "SELECT * FROM Users WHERE Username = '".$Username."'"; but I need to display the User's profile from both the users able and the UserProfile table. $query ="SELECT Users.Firstname,Users.Surname,Users.Email,UserProfile.Age FROM Users,UserProfile WHERE Username = '".$Username."' AND Users.UserID = UserProfile.UserID"; $result = mysql_query($query); $num = mysql_numrows($result); I'm guessing my query is wrong so I will try and work it out. Quote Link to comment https://forums.phpfreaks.com/topic/54412-solved-mysql-query-help/#findComment-269051 Share on other sites More sharing options...
blackwolf23 Posted June 6, 2007 Author Share Posted June 6, 2007 Silly me,I commented out echo "<<br>Firstname: $Firstname<br>Surname: $Surname<br>Email: $Email<br>Password: $Password<br> <br>Age: $Age<br>"; Quote Link to comment https://forums.phpfreaks.com/topic/54412-solved-mysql-query-help/#findComment-269053 Share on other sites More sharing options...
chocopi Posted June 6, 2007 Share Posted June 6, 2007 Well done for fixing it Quote Link to comment https://forums.phpfreaks.com/topic/54412-solved-mysql-query-help/#findComment-269060 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.