Jump to content

How do I select a field?


jokerbla

Recommended Posts

$sql="SELECT * FROM users WHERE username='$un' and password='$pw'";
$result=mysql_query($sql);
$row = mysql_fetch_assoc($result);
$_SESSION['id'] = $row['id'];

 

You may consider changing your SELECT statement. If you only require the id, change the * for id. If you only need a couple your still better implicitly selecting those columns rather than using the *.

I seem to be having another problem with the UPDATE

$sgvote = mysql_query("SELECT voted FROM vote") or die(mysql_error());
$row1 = mysql_fetch_array($sgvote);
$voted = $row1['voted'];

$sql="SELECT id FROM users";
$result=mysql_query($sql);
$row = mysql_fetch_assoc($result);
$newvoted = $row['id'];
//echo $row['id'];
$total = $voted." ".$newvoted;
echo "      voted: ".$voted;
echo "      newvoted: ".$newvoted;
echo "      total: ".$total;

$update = mysql_query("UPDATE vote SET voted=$total");

I want to make a list with the ids (that have voted), each id separated by space

$voted is 1, $newvoted is 1

$total is "1 1" cause the id that voted was 1 and initially the field was set by me to 1

 

So each time someone votes it's supposed to get it's id. Problem is it always stays at "1 1", when it's supposed to add " 1" each time someone votes. What am I doing wrong?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.