At 5:11 PM -0700 10-24-2000, Jim Rota wrote:
>Does anyone know why this works:
>
><? $db = mysql_connect("localhost","jrota");
>$sql = "UPDATE banners SET impressions=impressions+1,rank=1 where id='4'";
>$result=@mysql("mydb",$sql);
>>
>
>
>And this doesn't:
>
><? $db = mysql_connect("localhost","jrota");
>$sql = "select max(rank) from banners";
>$result=@mysql("mydb",$sql);
>$sql = "UPDATE banners SET impressions=impressions+1,rank=1 where
>rank='$result'";
> >
It could be because you never bothered to actually execute the
UPDATE query in your second example. :-)
But it wouldn't work anyway. You never actually fetched
the result of the SELECT query. The mysql() function returns a result set
identifier that you can use (e.g., with mysql_fetch_row() to get
the result set. It does not return the result set directly.
$result=@mysql("mydb",$sql);
$row = mysql_fetch_row ($result);
$sql = "UPDATE banners SET impressions=impressions+1,rank=1 where
rank='$row[0]'";
$result=@mysql("mydb",$sql);
Note, I'm not putting in any error checking. You really should do
that, too. It might have saved you having to post a FAQ to the list.
--
Paul DuBois, paul@stripped