Pls guys this is so easy, and I cant solve it.
Introduction:
I made connection to database, I have all variables set good and working.
Im making some kind of clickin site.
So each user must click others, thats like game.
So everyone need to click whole database. I saved in database id where user stoped. Example my id=1, and am under nick IA-Kova, stoped at user id=3.
Every user has his own link.
So here is question. I need to pull out info from database, like: where did loged in user stoped, whats link of next user, whats nick of next user.
So I need to printout that nick and link, and after you click on that link, and paste part of that page back on my page next user with his link should apear ...
<?php
include 'login.php'; /*this is log in part it works fine
session_start();
$credits=($given-$gets);
$result=mysql_query("SELECT * FROM table_name WHERE userid='$uid'");
$myrow=mysql_fetch_array($result);
$given=$myrow["given_clicks"];
$start=$myrow["start_from"];
$result=mysql_query("SELECT * FROM table_name WHERE id='$start'");
$nextlink=$myrow["link"];
$nextnick=$myrow["userid"];
$get=$myrow["got_clicks"];
/*This part is wierd, cause I need two same parts, 1 time when no submition was made by form
if($newarmy){ /*and one when you make submition
if($start<=$count){
$result=mysql_query("UPDATE table_name SET army_size='$newarmy',got_clicks=('$get'+1) WHERE id='$start'");
$start+=1;
$result=mysql_query("UPDATE table_name SET start_from='$start',given_clicks=('$given'+1) WHERE userid='$uid'");
$result=mysql_query($sql);
$result=mysql_query("SELECT * FROM table_name WHERE id='$start'");
$myrow=mysql_fetch_array($result);
$nextlink=$myrow["link"];
$nextnick=$myrow["userid"];
$get=$myrow["got_clicks"];
$given+=1;
?>
<table width="253" height="109" border="0" align="center">
<tr>
<td><div align="left">
<p>Next user: <?php echo "<a href=http://www.htmlforums.com/archive/index.php/{$nextlink}>$nextnick</a>"; ?> </p>
<form action="<?php echo $PHP_SELF; ?>" method="POST">
<p>Army size: <input name=newarmy type=text id="newarmy" size=9 maxlength=20>
</p>
<p align="center">
<input name="submit" type="submit" value="Submit">
</p></form>
</div></td>
</tr>
</table>
<?php
}
else $start=1;
}
$credits=($given-$gets);
?>
Whats wrong ? It goes fine when you just log in. Then it goes over max numbers of id, but count is max number of users (count = number of users).
Other things are well solved.
Is there way that I dont have to use two times same code !?Easyer question.
When you log in, it should give you link of user where you stoped.
Then when you paste part, it should loop between all users in database.
But I have problem, with that first pass ...
Any suggestions?um... what loop? there is no loop there.In short.
I take data that I need, but I have form. I got too click on link then get some info back.
I need to put that info in database, then go to next link.
I need to loop trough all links in database !
But I have problem, if you have php file like this:
<?php
something to pull out from database
then something to work with that info
if($submit){
}
And all data before submit is not in loop, it pass trough only once, thats problem !
So I need to make all under if, and I need 1 loop before !I have no clue what you are trying to doIts hard to explain ... Am thinking best way,...
scoutt can I send you all php files, so you can see ?
go to <!-- m --><a class="postlink" href="http://2crowded.com/KOC/clicker/">http://2crowded.com/KOC/clicker/</a><!-- m -->
hm you will not see if you dont register, so register..
for link take something long 55, else it wont work ..
So when you reg in, you should get in user page, where you can click...
I donno how to explain.Ok just help me with this, and Ill manage to go further.
I sorted ppl in database by id.
But if user is deleted from example id=5, and there are
id user link
1 user1 link2
2 user2 link3
3 user3 link4
4 user4 link5
6 user6 link6
So there are 5 users, and 1 was deleted.
And I want to take all links in database, 1 by 1, how to do it ?
So I need something like this: if your stop id=4
Next user is: user6
HOW TO DO IT ?GUYS ?
If I use this:
$start=2;
$result=mysql_query("SELECT * FROM table WHERE id='$start'");
And next time I use $result=mysql ...
he dont recognize it.
He doesnt search for id='$start', he just remembers that I used id= 1 !!!!
How to take result from database several times in same file ?!?!kova, i fall you wnted was a loop then this will be it
$result=mysql_query("SELECT * FROM table_name WHERE id='$start'");
while($myrow=mysql_fetch_array($result)){
// echo here your results and it will echo everything out
// that has a id of '$start'
}
that is a LOOP. also when you set $start=1 then what else is it suppose to use. not once did you incrementn start in that code above.
$start+=1;
that is not right.here is answare:
do{
if($start>=$max){
$start=1;
}
$result=@mysql_query("SELECT * table WHERE id='$start'LIMIT 1");
$myrow=mysql_fetch_array($result);
$id=$myrow["id"];
$nextnick=$myrow["userid"];
$nextlink=$myrow["link"];
$get=$myrow["got_clicks"];
if($id==''){
$start++;
}
$result=mysql_query("UPDATE table SET start_from='$start' WHERE userid='$uid'");
}while($id=='');
I needed loop that will exclude all NULL ids. And I calculated max, max = last id (if last id = 9, and there are 5 users), it will loop till 9, and get only 5... And I needed part that will start from first user if got to end.
Is it ok ? It works, but is it good solution ?!if it works then it must be a good solution.
Introduction:
I made connection to database, I have all variables set good and working.
Im making some kind of clickin site.
So each user must click others, thats like game.
So everyone need to click whole database. I saved in database id where user stoped. Example my id=1, and am under nick IA-Kova, stoped at user id=3.
Every user has his own link.
So here is question. I need to pull out info from database, like: where did loged in user stoped, whats link of next user, whats nick of next user.
So I need to printout that nick and link, and after you click on that link, and paste part of that page back on my page next user with his link should apear ...
<?php
include 'login.php'; /*this is log in part it works fine
session_start();
$credits=($given-$gets);
$result=mysql_query("SELECT * FROM table_name WHERE userid='$uid'");
$myrow=mysql_fetch_array($result);
$given=$myrow["given_clicks"];
$start=$myrow["start_from"];
$result=mysql_query("SELECT * FROM table_name WHERE id='$start'");
$nextlink=$myrow["link"];
$nextnick=$myrow["userid"];
$get=$myrow["got_clicks"];
/*This part is wierd, cause I need two same parts, 1 time when no submition was made by form
if($newarmy){ /*and one when you make submition
if($start<=$count){
$result=mysql_query("UPDATE table_name SET army_size='$newarmy',got_clicks=('$get'+1) WHERE id='$start'");
$start+=1;
$result=mysql_query("UPDATE table_name SET start_from='$start',given_clicks=('$given'+1) WHERE userid='$uid'");
$result=mysql_query($sql);
$result=mysql_query("SELECT * FROM table_name WHERE id='$start'");
$myrow=mysql_fetch_array($result);
$nextlink=$myrow["link"];
$nextnick=$myrow["userid"];
$get=$myrow["got_clicks"];
$given+=1;
?>
<table width="253" height="109" border="0" align="center">
<tr>
<td><div align="left">
<p>Next user: <?php echo "<a href=http://www.htmlforums.com/archive/index.php/{$nextlink}>$nextnick</a>"; ?> </p>
<form action="<?php echo $PHP_SELF; ?>" method="POST">
<p>Army size: <input name=newarmy type=text id="newarmy" size=9 maxlength=20>
</p>
<p align="center">
<input name="submit" type="submit" value="Submit">
</p></form>
</div></td>
</tr>
</table>
<?php
}
else $start=1;
}
$credits=($given-$gets);
?>
Whats wrong ? It goes fine when you just log in. Then it goes over max numbers of id, but count is max number of users (count = number of users).
Other things are well solved.
Is there way that I dont have to use two times same code !?Easyer question.
When you log in, it should give you link of user where you stoped.
Then when you paste part, it should loop between all users in database.
But I have problem, with that first pass ...
Any suggestions?um... what loop? there is no loop there.In short.
I take data that I need, but I have form. I got too click on link then get some info back.
I need to put that info in database, then go to next link.
I need to loop trough all links in database !
But I have problem, if you have php file like this:
<?php
something to pull out from database
then something to work with that info
if($submit){
}
And all data before submit is not in loop, it pass trough only once, thats problem !
So I need to make all under if, and I need 1 loop before !I have no clue what you are trying to doIts hard to explain ... Am thinking best way,...
scoutt can I send you all php files, so you can see ?
go to <!-- m --><a class="postlink" href="http://2crowded.com/KOC/clicker/">http://2crowded.com/KOC/clicker/</a><!-- m -->
hm you will not see if you dont register, so register..
for link take something long 55, else it wont work ..
So when you reg in, you should get in user page, where you can click...
I donno how to explain.Ok just help me with this, and Ill manage to go further.
I sorted ppl in database by id.
But if user is deleted from example id=5, and there are
id user link
1 user1 link2
2 user2 link3
3 user3 link4
4 user4 link5
6 user6 link6
So there are 5 users, and 1 was deleted.
And I want to take all links in database, 1 by 1, how to do it ?
So I need something like this: if your stop id=4
Next user is: user6
HOW TO DO IT ?GUYS ?
If I use this:
$start=2;
$result=mysql_query("SELECT * FROM table WHERE id='$start'");
And next time I use $result=mysql ...
he dont recognize it.
He doesnt search for id='$start', he just remembers that I used id= 1 !!!!
How to take result from database several times in same file ?!?!kova, i fall you wnted was a loop then this will be it
$result=mysql_query("SELECT * FROM table_name WHERE id='$start'");
while($myrow=mysql_fetch_array($result)){
// echo here your results and it will echo everything out
// that has a id of '$start'
}
that is a LOOP. also when you set $start=1 then what else is it suppose to use. not once did you incrementn start in that code above.
$start+=1;
that is not right.here is answare:
do{
if($start>=$max){
$start=1;
}
$result=@mysql_query("SELECT * table WHERE id='$start'LIMIT 1");
$myrow=mysql_fetch_array($result);
$id=$myrow["id"];
$nextnick=$myrow["userid"];
$nextlink=$myrow["link"];
$get=$myrow["got_clicks"];
if($id==''){
$start++;
}
$result=mysql_query("UPDATE table SET start_from='$start' WHERE userid='$uid'");
}while($id=='');
I needed loop that will exclude all NULL ids. And I calculated max, max = last id (if last id = 9, and there are 5 users), it will loop till 9, and get only 5... And I needed part that will start from first user if got to end.
Is it ok ? It works, but is it good solution ?!if it works then it must be a good solution.