Jump to content


Photo

Help Please Warning: mysql_num_rows()....


  • Please log in to reply
6 replies to this topic

#1 cefalufr

cefalufr
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 03 May 2006 - 08:48 PM

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.

<?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> 
<?php

while($i < $num_rows)
{
  $firstname = mysql_result("fname");
  $lastname = mysql_result("lname");
  echo $firstname . $lastname;
}


?>


</OPTION></SELECT></FORM>


#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 03 May 2006 - 08:55 PM

Modify the "or die" clause on the mysql_query statement to output the mysql_error() and the query.
<?php
$connect = 'SELECT fname lname FROM shipping_multiple';
mysql_query($connect) or die('failed query: ' . $connect . '<br>' . mysql_error());
?>

I believe you're missing a comma between the field names in your query.

Ken

#3 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 03 May 2006 - 08:56 PM

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 FROM shipping_multiple [!--sql2--][/div][!--sql3--]

#4 cefalufr

cefalufr
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 03 May 2006 - 08:58 PM



[!--quoteo(post=371069:date=May 3 2006, 04:55 PM:name=kenrbnsn)--][div class=\'quotetop\']QUOTE(kenrbnsn @ May 3 2006, 04:55 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Modify the "or die" clause on the mysql_query statement to output the mysql_error() and the query.
<?php
$connect = 'SELECT fname lname FROM shipping_multiple';
mysql_query($connect) or die('failed query: ' . $connect . '<br>' . mysql_error());
?>

I believe you're missing a comma between the field names in your query.

Ken
[/quote]


Still Same Error, This is so annoying.

<?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'
?>


#5 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 03 May 2006 - 09:11 PM

Do you have "or die" clauses on the db connection functions. Can you post that code?

Ken

#6 cefalufr

cefalufr
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 03 May 2006 - 09:12 PM

<?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> 
<?php

while($i < $num_rows)
{
  $firstname = mysql_result("fname");
  $lastname = mysql_result("lname");
  echo $firstname . $lastname;
}


?>


#7 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 03 May 2006 - 09:42 PM

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:
<?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>';
?>

Ken




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users