Reputation: 95
I made a portal where i have to fetch result with primary key as id i am using it everywhere storing it in a variable however there is a certain problem that i am facing
$sql="SELECT users from hostelusers WHERE users Like'%$roll%'";
$result = mysql_query($sql) or die(mysql_error());
$rows=mysql_fetch_row($result);
$uid=$rows[0];
$_SESSION['uid']=$uid;
In my code the variable $uid is echoing out values of column 1 ie users however I have selected column 0 which is id(in the table in mysql)
can't think of any mistake there
Upvotes: 0
Views: 51
Reputation: 3483
your mysql query string is wrong . You are using :
$sql="SELECT users from hostelusers WHERE users Like'%$roll%'";
And how do you expect to get id
field in the result ??
Moreover you will be having only a single column [field] in your rows[]
and that is rows[0]
if you want to use rows[0]
to get your id
field
Change your query to this
$sql="SELECT id from hostelusers WHERE users Like'%$roll%'";
or this:
$sql="SELECT * from hostelusers WHERE users Like'%$roll%'";
and it will work for sure
Upvotes: 2