Hi. I have a user with his unique username in a mysql table, but I have to test and do many queries to find it. I wonder if its a better way to avoid all does queries to the db.
I have multiple rows in the table with columns like user1
, user2
, user3
, user4
up to 30.
for ($x=0; $x < 30; $x ++){
$user = "user";
$user .= $x; //generate user1, user2, user3 etc
$result=mysql_fetch_object(mysql_query("SELECT * FROM table WHERE ".$user."='".$_SESSION['username']."'"));
if ($result){
Now if the $_SESSION['username']
is user30
in the table I do 29 queries before $result
is true and I can work with the results. Is there a better way to do this? How important is this anyway. Is there a big difference in cpu demand for 1 query and 30 queries?