managerstats Posted May 10, 2013 Share Posted May 10, 2013 <ol> <?php include '../globals.php'; $manager = $_GET['manager']; $query = "SELECT 'manager' FROM 'tablename' WHERE manager='.$manager.' "; $rs = mysql_query($query); while ($row = mysql_fetch_assoc($rs)) { echo '<li>' . $row['manager'] . '</strong> '; echo '<strong>' . $row['won'] . '</strong> '; echo '<strong>' . $row['drawn'] . '</strong> '; echo '<strong>' . $row['lost'] . '</strong> '; echo '<strong>' . $row['total'] . '</strong> '; echo '<strong>' . $row['club'] . '</strong></li> '; } mysql_close(); ?> </ol> I have been around in circles trying to solve this without success. Essentially I am trying to set up anchors such as; <a href="sitename.com/?manager=Micky Adams">Micky Adams</a> But I get; PHP Warning: mysql_fetch_assoc() expects parameter 1 to be resource Can someone please point me in the right direction or let me know where I have gone wrong in my code? Quote Link to comment Share on other sites More sharing options...
Barand Posted May 10, 2013 Share Posted May 10, 2013 (edited) Use backtick ` and not single quotes around the tablename Check your queries have worked and use mysql_error() to find out why it failed Edited May 10, 2013 by Barand Quote Link to comment Share on other sites More sharing options...
managerstats Posted May 10, 2013 Author Share Posted May 10, 2013 The backtick around the table name worked at removing the error notice but not fetching any results http://managerstats.co.uk/tests/?manager=Micky Adams Maybe something in the query itself? Quote Link to comment Share on other sites More sharing options...
managerstats Posted May 10, 2013 Author Share Posted May 10, 2013 Not sure how to implement the mysql_error() (newb) Quote Link to comment Share on other sites More sharing options...
litebearer Posted May 10, 2013 Share Posted May 10, 2013 Try echoing your query Quote Link to comment Share on other sites More sharing options...
Barand Posted May 10, 2013 Share Posted May 10, 2013 Not sure how to implement the mysql_error() (newb) mysql_query - see examples on this page Quote Link to comment Share on other sites More sharing options...
managerstats Posted May 10, 2013 Author Share Posted May 10, 2013 Added mysql_query() Just returning blank, but this time with the HTML and no results (see above link) Quote Link to comment Share on other sites More sharing options...
litebearer Posted May 10, 2013 Share Posted May 10, 2013 Did you echo your query to see if it contains what you expect it to contain? Quote Link to comment Share on other sites More sharing options...
managerstats Posted May 10, 2013 Author Share Posted May 10, 2013 Did you echo your query to see if it contains what you expect it to contain? Not sure how to do that either? Quote Link to comment Share on other sites More sharing options...
Solution mac_gyver Posted May 10, 2013 Solution Share Posted May 10, 2013 the syntax you are using for the $manager variable in the WHERE clause is adding dots . before and after the value, so your WHERE clause is false and is not matching anything. you can put a php variable inside of a double quoted string. you also had single quotes around the column name in the SELECT clause, which would have literally returned the string 'manager' - $query = "SELECT manager FROM tablename WHERE manager='$manager'"; Quote Link to comment Share on other sites More sharing options...
litebearer Posted May 10, 2013 Share Posted May 10, 2013 $query = "SELECT manager FROM tablename WHERE manager='$manager'"; echo $query; exit(); Quote Link to comment Share on other sites More sharing options...
managerstats Posted May 10, 2013 Author Share Posted May 10, 2013 the syntax you are using for the $manager variable in the WHERE clause is adding dots . before and after the value, so your WHERE clause is false and is not matching anything. you can put a php variable inside of a double quoted string. you also had single quotes around the column name in the SELECT clause, which would have literally returned the string 'manager' - $query = "SELECT manager FROM tablename WHERE manager='$manager'"; Thank you Mac_Gyver! you absolute beauty, this solved it. Thank you all for your help, this has had me going insane all day, happy Friday and have a good weekend all. Quote Link to comment 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.