Jump to content

Help Please Warning: mysql_num_rows()....


cefalufr

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.