List:General Discussion« Previous MessageNext Message »
From:Paul DuBois Date:October 25 2000 4:13pm
Subject:Re: MySQL/PHP
View as plain text  
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
Thread
UpdateJim Rota25 Oct
  • Re: UpdateJoshua J. Kugler25 Oct
  • Re: UpdateJim Rota25 Oct
    • Re: UpdateStephen Johnson25 Oct
  • Re: UpdateFredrik Kristiansen25 Oct
  • Re: UpdateJoshua J. Kugler25 Oct
  • Looking for help in North VancouverJim Rota25 Oct
  • MySQL/PHPJim Rota25 Oct
  • MySQL/PHPJim Rota25 Oct
    • Re: MySQL/PHPPaul DuBois25 Oct
  • Can't seem to be able to load topicsTom Cruickshank25 Oct
RE: MySQL/PHPQuentin Bennett25 Oct