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; Quote 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? Link to comment https://forums.phpfreaks.com/topic/277878-mysql_fetch_assoc/ Share on other sites More sharing options...
Barand Posted May 10, 2013 Share Posted May 10, 2013 Use backtick ` and not single quotes around the tablename Check your queries have worked and use mysql_error() to find out why it failed Link to comment https://forums.phpfreaks.com/topic/277878-mysql_fetch_assoc/#findComment-1429495 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? Link to comment https://forums.phpfreaks.com/topic/277878-mysql_fetch_assoc/#findComment-1429498 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) Link to comment https://forums.phpfreaks.com/topic/277878-mysql_fetch_assoc/#findComment-1429499 Share on other sites More sharing options...
litebearer Posted May 10, 2013 Share Posted May 10, 2013 Try echoing your query Link to comment https://forums.phpfreaks.com/topic/277878-mysql_fetch_assoc/#findComment-1429501 Share on other sites More sharing options...
Barand Posted May 10, 2013 Share Posted May 10, 2013 On 5/10/2013 at 12:29 PM, managerstats said: Not sure how to implement the mysql_error() (newb) mysql_query - see examples on this page Link to comment https://forums.phpfreaks.com/topic/277878-mysql_fetch_assoc/#findComment-1429503 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) Link to comment https://forums.phpfreaks.com/topic/277878-mysql_fetch_assoc/#findComment-1429504 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? Link to comment https://forums.phpfreaks.com/topic/277878-mysql_fetch_assoc/#findComment-1429505 Share on other sites More sharing options...
managerstats Posted May 10, 2013 Author Share Posted May 10, 2013 On 5/10/2013 at 1:02 PM, litebearer said: Did you echo your query to see if it contains what you expect it to contain? Not sure how to do that either? Link to comment https://forums.phpfreaks.com/topic/277878-mysql_fetch_assoc/#findComment-1429506 Share on other sites More sharing options...
mac_gyver Posted May 10, 2013 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'"; Link to comment https://forums.phpfreaks.com/topic/277878-mysql_fetch_assoc/#findComment-1429507 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(); Link to comment https://forums.phpfreaks.com/topic/277878-mysql_fetch_assoc/#findComment-1429509 Share on other sites More sharing options...
managerstats Posted May 10, 2013 Author Share Posted May 10, 2013 On 5/10/2013 at 1:12 PM, mac_gyver said: 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. Link to comment https://forums.phpfreaks.com/topic/277878-mysql_fetch_assoc/#findComment-1429512 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.