cefalufr Posted May 3, 2006 Share Posted May 3, 2006 I keep recieving this Error = [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource ....[/quote]Help? Also My DB Connection is above this code. The query returns no errors, I has to do with the num_rows.[code]<?php$connect = 'SELECT fname lname FROM shipping_multiple';mysql_query($connect) or die('failed query');$num_rows = mysql_num_rows($connect);$i = '0'?><SELECT name="product" size="5" multiple><OPTION SELECTED> <?phpwhile($i < $num_rows){ $firstname = mysql_result("fname"); $lastname = mysql_result("lname"); echo $firstname . $lastname;}?></OPTION></SELECT></FORM>[/code] Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted May 3, 2006 Share Posted May 3, 2006 Modify the "or die" clause on the mysql_query statement to output the mysql_error() and the query.[code]<?php$connect = 'SELECT fname lname FROM shipping_multiple';mysql_query($connect) or die('failed query: ' . $connect . '<br>' . mysql_error());?>[/code]I believe you're missing a comma between the field names in your query.Ken Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted May 3, 2006 Share Posted May 3, 2006 You have an error is your SQL query and I can see the problem straight away! You didn't seperate your coulumn names with comma so change your SQL query to the following:[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']SELECT[/span] fname, lname [color=green]FROM[/color] [color=orange]shipping_multiple[/color] [!--sql2--][/div][!--sql3--] Quote Link to comment Share on other sites More sharing options...
cefalufr Posted May 3, 2006 Author Share Posted May 3, 2006 [!--quoteo(post=371069:date=May 3 2006, 04:55 PM:name=kenrbnsn)--][div class=\'quotetop\']QUOTE(kenrbnsn @ May 3 2006, 04:55 PM) [snapback]371069[/snapback][/div][div class=\'quotemain\'][!--quotec--]Modify the "or die" clause on the mysql_query statement to output the mysql_error() and the query.[code]<?php$connect = 'SELECT fname lname FROM shipping_multiple';mysql_query($connect) or die('failed query: ' . $connect . '<br>' . mysql_error());?>[/code]I believe you're missing a comma between the field names in your query.Ken[/quote]Still Same Error, This is so annoying.[code]<?php$connect = 'SELECT `fname` ,`lname` FROM shipping_multiple';mysql_query($connect) or die('failed query: ' . $connect . '<br>' . mysql_error());$num_rows = mysql_num_rows($connect);$i = '0'?>[/code] Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted May 3, 2006 Share Posted May 3, 2006 Do you have "or die" clauses on the db connection functions. Can you post that code?Ken Quote Link to comment Share on other sites More sharing options...
cefalufr Posted May 3, 2006 Author Share Posted May 3, 2006 [code]<?php$dbhost = 'localhost';$dbuser = 'root';$dbpass = 'this';$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');$dbname = 'oscommerce_feedyoursoul';mysql_select_db($dbname) or die('Failed to Select database');?><?php$connect = 'SELECT * FROM `shipping_multiple`';mysql_query($connect) or die('failed query: ' . $connect . '<br>' . mysql_error());$num_rows = mysql_num_rows($connect);$i = '0'?><SELECT name="product" size="5" multiple><OPTION SELECTED> <?phpwhile($i < $num_rows){ $firstname = mysql_result("fname"); $lastname = mysql_result("lname"); echo $firstname . $lastname;}?>[/code] Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted May 3, 2006 Share Posted May 3, 2006 You're getting that error because you're parameter is incorrect. You need to take the return status from the mysql_query statement and use it as the paremeter to mysql_num_rows(). But we can re-write your code so we don't need that function at all:[code]<?php$q = 'SELECT * FROM shipping_multiple';$rs = mysql_query($q) or die('failed query: ' . $q . '<br>' . mysql_error());echo '<SELECT name="product" size="5" multiple>' . "\n";echo '<OPTION SELECTED>' . "\n";while ($rw = mysql_fetch_assoc($rw)) echo $rw['fname'] . ' ' . $rw['lname'] . '<br>';?>[/code]Ken 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.