id Posted August 10, 2012 Share Posted August 10, 2012 OK, so im working on a mini forum board, and i ran into some problems... On my view_topic.php file i want the user to be able to see his post_count... which is simple because all i have to do is do a mysql_query and a mysql_fetch_array. , which works fine. However i am getting a warning... "Warning: mysql_fetch_array() expects parameter 1 to be resource, string given in C:\wamp\www\EmporaTech_Site\forum\view_topic.php on line 40".. <?php $id = isset($_GET['id']) ? $_GET['id']: ''; $result = mysql_query("SELECT * FROM forum_question WHERE id='$id'"); while($row = mysql_fetch_array($result)) { $username = isset($row['username']) ? $row['username'] : ''; $post_count = mysql_query("SELECT * FROM members WHERE username='$username'"); while($row_1 = mysql_fetch_array($post_count)) { $post_count = $row_1['post_count']; $topic = isset($row['topic']) ? $row['topic'] : ''; $detail = isset($row['detail']) ? $row['detail'] : ''; $view = isset($row['view']) ? $row['view'] : ''; $reply = isset($row['replies']) ? $row['replies'] : ''; $date = isset($row['date_time']) ? $row['date_time'] : ''; ?> PS... I have a curly brace for the while statement further down in my script, so that's not the issue. Link to comment https://forums.phpfreaks.com/topic/266917-trouble-with-getting-a-variable-from-database/ Share on other sites More sharing options...
ManiacDan Posted August 10, 2012 Share Posted August 10, 2012 That error comes from a failed query. Mysql_query returns false when the query fails. False, as you may know, is not a mysql result set resource. That's where the error comes from. If your mysql_query returns false, echo mysql_error(). That will show you why it's failing. Link to comment https://forums.phpfreaks.com/topic/266917-trouble-with-getting-a-variable-from-database/#findComment-1368434 Share on other sites More sharing options...
id Posted August 10, 2012 Author Share Posted August 10, 2012 The error that i was overwriting the variable $post_count.. so i just changed the name. Thanks tho Link to comment https://forums.phpfreaks.com/topic/266917-trouble-with-getting-a-variable-from-database/#findComment-1368440 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.