Jump to content

How do I select a field?


jokerbla

Recommended Posts

I have a table with 3 fields, one of which is primary, auto-increment, like an id. How do I select the id?

 

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

that didn't work

Link to comment
Share on other sites

$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 *.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.