Jump to content

Archived

This topic is now archived and is closed to further replies.

cefalufr

Help Please Warning: mysql_num_rows()....

Recommended Posts

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

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


?>


</OPTION></SELECT></FORM>[/code]

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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--]

Share this post


Link to post
Share on other sites


[!--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]

Share this post


Link to post
Share on other sites
Do you have "or die" clauses on the db connection functions. Can you post that code?

Ken

Share this post


Link to post
Share on other sites
[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>
<?php

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


?>[/code]

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.