theone Posted April 9, 2006 Share Posted April 9, 2006 Hey guys.At the risk of sounding stupid, im still going to ask this...Why does this not work?...[code]<?mysql_connect($db_host, $db_user, $db_pass);mysql_select_db($db_name);$sql = "SELECT * FROM news_site WHERE show = '1'";$results = mysql_query($sql);while ($data = mysql_fetch_array($results)) { var_dump($data);}?>[/code]I usually use the mysql_db_query function however i read at w3schools.com that that function is bein depreciated an that mysql_select_db and mysql_query should be used instead. But i cant seem to figure out why it isnt working :(Please help me... im a dumbass ,lol.Thanks in advance guys,Dave Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted April 9, 2006 Share Posted April 9, 2006 Do you get any errors? The code looks ok. What are you expecting?Ken Quote Link to comment Share on other sites More sharing options...
theone Posted April 9, 2006 Author Share Posted April 9, 2006 [!--quoteo(post=362969:date=Apr 9 2006, 07:57 AM:name=kenrbnsn)--][div class=\'quotetop\']QUOTE(kenrbnsn @ Apr 9 2006, 07:57 AM) [snapback]362969[/snapback][/div][div class=\'quotemain\'][!--quotec--]Do you get any errors? The code looks ok. What are you expecting?Ken[/quote]Yeh. The error is:Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in X:\www\thebestunsigned\v4\index.php on line 23Thnx for the reply Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted April 9, 2006 Share Posted April 9, 2006 Add "or die" clauses to you mysql statements:[code]<?mysql_connect($db_host, $db_user, $db_pass) or die("Problem connecting to MySQL<br />" . mysql_error());mysql_select_db($db_name) or die("Problem selecting database $dbname<br />" . mysql_error());$sql = "SELECT * FROM news_site WHERE show = '1'";$results = mysql_query($sql) or die('Problem with query: ' . $sql . '<br />' . mysql_error());while ($data = mysql_fetch_assoc($results)) { // will return an associative array echo '<pre>' . print_r($data,true) . '</pre>'; // will display on the screen cleaner}?>[/code]Ken Quote Link to comment Share on other sites More sharing options...
theone Posted April 9, 2006 Author Share Posted April 9, 2006 Thanks for the reply.It turned out if i put the variable user in quotes it works :-/Thanks all the same. 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.