Jump to content
php.lv forumi

mysql update


werd

Recommended Posts

No DB nolasa vertibu 1 tad to nomaina uz 2 un izvada bet talak pec reresha neka!Kur kluda???

<?php
$server="****";
$username="***";
$password="***";
$db="****";


$dbh = mysql_connect($server, $username, $password)

or die("Unable to connect to MySQL");


mysql_select_db($db) or die(mysql_error());

$result = mysql_query("SELECT * FROM counter");
while($row = mysql_fetch_array($result))
 {
 echo "<span>" . $row['vertiba'] . "</span></br>";
 }

$row=$row +1;
$row++;

mysql_query("UPDATE counter SET vertiba='$row'") or die("kkas nav");
echo "nomainits";

$result = mysql_query("SELECT * FROM counter");
while($row = mysql_fetch_array($result))
 {
 echo "<span>" . $row['vertiba'] . "</span></br>";
 }
?>

Edited by phpjanis
Link to comment
Share on other sites

nomaini

mysql_query("UPDATE counter SET vertiba='$row'") or die("kkas nav");

uz

mysql_query("UPDATE counter SET vertiba='$row'") or die (mysql_error());

un skaties kas par kljuudu

Edited by Klez
Link to comment
Share on other sites

<?php
$server="****";
$username="***";
$password="***";
$db="****";


$dbh = mysql_connect($server, $username, $password)

or die("Unable to connect to MySQL");


mysql_select_db($db) or die(mysql_error());

$result = mysql_query("SELECT * FROM counter");
while($row = mysql_fetch_array($result))
 {
 echo "<span>" . $row['vertiba'] . "</span></br>";
 }

$row=$row +1;
$row++;

mysql_query("UPDATE counter SET vertiba='$row'") or die (mysql_error());

$result = mysql_query("SELECT * FROM counter");
while($row = mysql_fetch_array($result))
 {
 echo "<span>" . $row['vertiba'] . "</span></br>";
 }
?>

Edited by phpjanis
Link to comment
Share on other sites

Tu tak tikai mysql_error() esi pielicis. Šo izlasīji, ko iepriekš teicu ?

Neiekeru ka editoji savu postu!

Sank ka man janomaina

$row=$row +1;
$row++;
uz 
$row['vertiba']=$row['vertiba'] +1;
$row['vertiba']++;

un ("UPDATE counter SET vertiba='$row['vertiba']'"

????

 

nedarbojas(mosh var kka savadak nolasito vertibu palielinat??)

Edited by phpjanis
Link to comment
Share on other sites

$result = mysql_query("SELECT * FROM counter");

while($row = mysql_fetch_array($result))

{

echo "<span>" . $row['vertiba'] . "</span></br>";

}

kāda jēga no while, ja tabulā visdrīzāk ir viens ieraksts tikai.

Un pareizi andrisp raksta ka mēģini palielināt masīvu ne countera vērtību tieši.

Tavā gadijumā $row = mysql_fetch_array($result) -> $row[] būs ( $row['id'],$row['vertiba'],$row['time'] ) array ar vērtībām.

Ja gribi palielināt tieši kolonnas `vertiba` vērtību, UPDATE `counter` SET vertiba='".($row['vertiba']+1)."';

Apmēram tā. Es jau nezinu kādas kolonnas un kā sauktas.

Edited by mounkuls
Link to comment
Share on other sites

A tu pamēģini!

 

Bet vispār nesaprotu kāpēc, tu palielini to vērtību pa divi ?

 

Un kveriju labāk:

"UPDATE counter SET vertiba='{$row['vertiba']}'"

 

mounkulis, reāli jau vispār viņam pietiktu ar šādu kodu :)

 

mysql_query("UPDATE counter SET vertiba = vertiva + 1");

Edited by andrisp
Link to comment
Share on other sites

×
×
  • Create New...