mysql_fetch_array

I can’t explain what i’m having a problem with easily but here it is,
i made it look for rows and their names but a button can’t see the difference between 2 arrays in a while function because you click it at the end i need a work arround to be able to see which array the button needs to change the number for, here is the code:

[php]$sql="SELECT * FROM anime WHERE username = ‘$username’ ";
$result=mysql_query($sql) or die(mysql_error());
while($rows=mysql_fetch_array($result))
{

if (isset($_POST[‘submit1’]))
{ mysql_query(“UPDATE anime SET episode=’$rows[episode]’+1 where name=’$rows[name]’ AND username=’$username’”) or die(“cannot send your password”);
header(“Location: {$_SERVER[‘HTTP_REFERER’]}”);
}

if (isset($_POST[‘submit2’]))
{ mysql_query(“UPDATE anime SET episode=’$rows[episode]’-1 where name=’$rows[name]’ AND username=’$username’”) or die(“cannot send your password”);
header(“Location: {$_SERVER[‘HTTP_REFERER’]}”);
}
?>

anime: <?php echo "$rows[name]"; ?>
episode: <?php echo "$rows[episode]"; ?>
<?php } mysql_close();[/php]

i can’t explain it well i hope you can understand what i mean when you read the code, the name that changes is for both names because name=’$rows[name]’ is just all of the rows…
what kind of function or thing can be a workaround for this??

Try adding or subtracting before the query and remove the single quotation marks on the field episode like this:
[php]
if (isset($_POST[‘submit1’]))
{
$rows[‘episode’] += 1;
mysql_query(“UPDATE anime SET episode=$rows[episode] where name=’$rows[name]’ AND username=’$username’”) or die(“cannot send your password”);
header(“Location: {$_SERVER[‘HTTP_REFERER’]}”);
}

if (isset($_POST[‘submit2’]))
{
$rows[‘episode’] -= 1;
mysql_query(“UPDATE anime SET episode=$rows[episode] where name=’$rows[name]’ AND username=’$username’”) or die(“cannot send your password”);
header(“Location: {$_SERVER[‘HTTP_REFERER’]}”);
}[/php]

and try to use mysql_fetch_assoc($result) or mysql_fetch_array($result,MYSQL_ASSOC).

Sponsor our Newsletter | Privacy Policy | Terms of Service