By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,213 Members | 1,085 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,213 IT Pros & Developers. It's quick & easy.

why am I getting this error from this code?

P: n/a
this is the error that I'm getting:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result
resource in /**/**/**/content/bin/tests/price/searchHist.php on line 48

and here is my code: (I removed commented out lines for space saving)

echo "<table width='500' border='0' align='center' cellpadding='0'
cellspacing='0'>
<tr>
<td width='200'>Part No.</td>
<td width='20'>Price</td>
<td width='20'>Currency</td>
<td width='40'>Month</td>
<td width='40'>Year</td>
</tr> \n";
$connect = mysql_connect ("******", "******", "*****") or
die ("Error connecting to database");
$selected = mysql_select_db ("fishpricinghist", $connect) or
die ("Error connecting to database");

$part = $_GET["partno"];

$query = "SELECT * FROM pricehistory WHERE partno LIKE %".$part."%
ORDER BY year DESC";

$result = mysql_query($query, $connect);

$rows = mysql_num_rows($result); //this is line 48 (my error line)

for ($I = 0 ; $I < $rows ; $I++)
{
$partno = mysql_result($result, $I, "partno");
$price = mysql_result($result, $I, "price");
$currency = mysql_result($result, $I, "currency");
$month = mysql_result($result, $I, "month");
$year = mysql_result($result, $I, "year");

echo "<tr><td>".$partno."</td>
<td>".$price."</td>
<td>".$currency."</td>
<td>".$month."</td>
<td>".$year."</td></tr>\n";
}

echo "</tr>
</table>";

Jul 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
>this is the error that I'm getting:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result
resource in /**/**/**/content/bin/tests/price/searchHist.php on line 48

and here is my code: (I removed commented out lines for space saving)
You have a syntax error in your query. print mysql_error($connect)
is your friend.
$query = "SELECT * FROM pricehistory WHERE partno LIKE %".$part."%
ORDER BY year DESC";


$query might end up as:

SELECT * FROM pricehistory WHERE partno LIKE %widget% ORDER BY year DESC

See some quotes missing around %widget% ?

Gordon L. Burditt
Jul 17 '05 #2

P: n/a
thanks, I figured this out already though.. it needed to be:

$query = "SELECT * FROM pricehistory WHERE partno LIKE \"%".$part."%\"
ORDER BY year DESC"

Now the question, would be how to sort by "year" DESC and subsort by
"month" DESC, so january would be last and december would be first

any suggestions? thanks for the help on the original, it hadn't posted by
the time I had figured it out so I couldn't clarify that I had figured it
out before it posted

Jul 17 '05 #3

P: n/a
>thanks, I figured this out already though.. it needed to be:

$query = "SELECT * FROM pricehistory WHERE partno LIKE \"%".$part."%\"
ORDER BY year DESC"

Now the question, would be how to sort by "year" DESC and subsort by
"month" DESC, so january would be last and december would be first


Doesn't:
ORDER BY year DESC, month DESC
work?

Gordon L. Burditt
Jul 17 '05 #4

P: n/a
didn't try it, I'm kind of an idiot today... it's a Monday :(

thanks for the help again :)

Jul 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.