Jump to content

bonzie

Members
  • Posts

    15
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

bonzie's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. That doesn't work neither :s [!--quoteo(post=385977:date=Jun 20 2006, 01:56 PM:name=joecooper)--][div class=\'quotetop\']QUOTE(joecooper @ Jun 20 2006, 01:56 PM) [snapback]385977[/snapback][/div][div class=\'quotemain\'][!--quotec--] $uname = $_SESSION['username']; echo "Welcome, $uname ."; try that instead [/quote]
  2. ok I tried this, however I don't get the username with the echo statement... Anyone an idea? [!--quoteo(post=385966:date=Jun 20 2006, 01:33 PM:name=joecooper)--][div class=\'quotetop\']QUOTE(joecooper @ Jun 20 2006, 01:33 PM) [snapback]385966[/snapback][/div][div class=\'quotemain\'][!--quotec--] to use sessions. all pages that are using them needs to have session_start(); at the top of them $_SESSION[''] is the varible used so to set the session varible for username use $_SESSION['username'] = $username; then across the other pages, you can bring up $_SESSION['username'] and it will return what ever the $username varible was set as in the first page [code]<?php session_start(); $username = $HTTP_POST_VARS['userName']; // this is correct! $id=$username; ?>[/code] change to this [code]<?php session_start(); $username = $HTTP_POST_VARS['userName']; // this is correct! $id=$username; $_SESSION['username'] = $username; ?>[/code] this will set the session varible and on the other page, use this to echo the username echo "Welcome, {$_SESSION['username']}."; [/quote]
  3. Hi all, Because giving through session variables don't work I would like to try session ids. This is my idea 1. Login page with form to fill out username and password (no session_start(); ), directed to home.php 2. home.php: [code] <?php session_start(); $username = $HTTP_POST_VARS['userName']; // this is correct! $id=$username; ?> <html> <body> <a href="recomm.php?<?php echo $id?>">Link</a> [/code] 3. recomm.php [code] session_start(); [/code] here I need the username of the user logged in. So I thought that I could use the variable $id... However, this variable is now empty. What do I do wrong?
  4. I tried with an easy example: login form: [code] <p><form method=post action="home.php>">   <table cellpadding="2" cellspacing="2" align="center" border="0">     <tr><td colspan="2" align="center">Please Log in here:</td>     </tr>     <tr><td align="right"class="logintext">Username:</td>            <td><input size="15" maxlength="10" name="userName" type="text"/></td>     </tr>     <tr><td align="right" class="logintext">Password:</td>            <td><input size="15" maxlength="10" name="userPassword" type="password"/></td>     </tr>     <tr align="center"><td colspan="2" align="center"><input value="login" name="action" type="hidden"/><input value="Log in" name="submit" type="submit"/>                               </td>     </tr>   </table> [/code] Now in home.php i put: [code] <?php session_start(); $id=session_id(); $username = $HTTP_POST_VARS['userName']; ?> In HTML body <a href="home2.php?<?php $id ?>"> link</a> [/code] The id in the URL doesn't work. And as i am a beginner I don't see why. Can you help? [!--quoteo(post=385924:date=Jun 20 2006, 11:46 AM:name=bonzie)--][div class=\'quotetop\']QUOTE(bonzie @ Jun 20 2006, 11:46 AM) [snapback]385924[/snapback][/div][div class=\'quotemain\'][!--quotec--] is it maybe better to use session ids? in the index2.php I would then put [code] <?php //start session session_start(); $id=session_id(); $username = $HTTP_POST_VARS['userName']; $password = $HTTP_POST_VARS['userPassword']; $_SESSION['user']=$username; $id=$username; // because I want the id to be the username ... ?> [/code] Is this correct? And how do I integrate then the id in the URL? thnx [/quote]
  5. is it maybe better to use session ids? in the index2.php I would then put [code] <?php //start session session_start(); $id=session_id(); $username = $HTTP_POST_VARS['userName']; $password = $HTTP_POST_VARS['userPassword']; $_SESSION['user']=$username; $id=$username; // because I want the id to be the username ... ?> [/code] Is this correct? And how do I integrate then the id in the URL? thnx [!--quoteo(post=385921:date=Jun 20 2006, 11:36 AM:name=Orio)--][div class=\'quotetop\']QUOTE(Orio @ Jun 20 2006, 11:36 AM) [snapback]385921[/snapback][/div][div class=\'quotemain\'][!--quotec--] Hmmm Everything seems fine, maybe it's the problem with the form? Your code says: $username = $HTTP_POST_VARS['userName']; $password = $HTTP_POST_VARS['userPassword']; Are you sure that in the login form the fields are called userName and userPassword ? And the method is post? Orio. [b]EDIT-[/b] I just saw you posted the form as well, and it's ok... I have no idea whats wrong! [/quote]
  6. in recomm.php I have [code] <?php //start session session_start(); $username=$_SESSION['user']; [/code] When I do [code] echo $username; [/code] I don't get anything. [!--quoteo(post=385916:date=Jun 20 2006, 11:24 AM:name=Orio)--][div class=\'quotetop\']QUOTE(Orio @ Jun 20 2006, 11:24 AM) [snapback]385916[/snapback][/div][div class=\'quotemain\'][!--quotec--] Do you start the sessions on recomm.php? It has to have session_start() in the begining so it can fetch the vars set on previous pages. Orio. [/quote]
  7. I read already some stuff on sessions, however probably I do something wrong. From my login page people are directed to index2.php. On this page I have [code] <?php //start session session_start(); $username = $HTTP_POST_VARS['userName']; $password = $HTTP_POST_VARS['userPassword']; $_SESSION['user']=$username; ... ?> [/code] Then in the body of my document (HTML) I have a link: [code] <body> <a class="menu" href="recomm.php">Get Recommendation</a> </body> [/code] I tried it like this, on the page "recomm.php" the session variable (_SESSION['user'])was empty... What do I wrong? Is it better to use session_id? And if yes how do I have to integrate this in the URL? thnx [!--quoteo(post=385906:date=Jun 20 2006, 11:00 AM:name=Orio)--][div class=\'quotetop\']QUOTE(Orio @ Jun 20 2006, 11:00 AM) [snapback]385906[/snapback][/div][div class=\'quotemain\'][!--quotec--] There are tons of tutorials out there explaining these stuff. Read, and you still cant figure out why some script doesnt work post it here and we'll try to fix it [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /] Orio. [/quote]
  8. Hi all, I try to create a small website with a login, however I don't get the sessions work. My login is (index.php): (in HTML) [code] <p><form method=post action="home.php>">   <table cellpadding="2" cellspacing="2" align="center" border="0">     <tr><td colspan="2" align="center">Please Log in here:</td>     </tr>     <tr><td align="right"class="logintext">Username:</td>            <td><input size="15" maxlength="10" name="userName" type="text"/></td>     </tr>     <tr><td align="right" class="logintext">Password:</td>            <td><input size="15" maxlength="10" name="userPassword" type="password"/></td>     </tr>     <tr align="center"><td colspan="2" align="center"><input value="login" name="action" type="hidden"/><input value="Log in" name="submit" type="submit"/>                               </td>     </tr>   </table> [/code] Now I want to create a session when people login, because I want to be able to identify people (via their username) when they browse further. I have tried several things but nothing worked. Could you help me? Thnx
  9. Thnx for your help. Some further in my scrpit I use a similar query, however there I only want to show the first 20 rows? How can i implement this? [!--quoteo(post=385684:date=Jun 19 2006, 06:53 PM:name=kenrbnsn)--][div class=\'quotetop\']QUOTE(kenrbnsn @ Jun 19 2006, 06:53 PM) [snapback]385684[/snapback][/div][div class=\'quotemain\'][!--quotec--] When there is only one statement in a statement block, you don't need the curly braces. The answer to to the OP's question was answered by the first two responders. Ken [/quote] I solved it myself... [!--quoteo(post=385722:date=Jun 19 2006, 08:15 PM:name=bonzie)--][div class=\'quotetop\']QUOTE(bonzie @ Jun 19 2006, 08:15 PM) [snapback]385722[/snapback][/div][div class=\'quotemain\'][!--quotec--] Thnx for your help. Some further in my scrpit I use a similar query, however there I only want to show the first 20 rows? How can i implement this? [/quote]
  10. Hi all, I am a beginner in PHP and therefore I need your help with the following. I have created in MySQL a table 'scores' with columns user_id and score. Now, I want to present the user_ids ordered by their score... I have done the folowing [code] $query="select user_id from scores order by score desc"; $result=mysql_query($query); $num_results=mysql_num_rows($result); $row=mysql_fetch_row($result); for ($count=0; $count<$num_results; $count++) echo row[$count]; [/code] I expected to see all the user_id however I don't get anything at all. Can anyone help me with this? Thanks
  11. that is the problem, then the array doesn't exist anymore: print_r($a); doesn't give anything euh maybe I put the problem differently you have for example a matrix A, the rows are the users and the columns the items: |100| |011| |001| A 1 in the matrix indicates that the user has bought the item I have a SQL table has_bought([u]item_id[/u], ([u]item_id[/u]), so with mysql I can determine if a user has bought a particular item. I thought of contructing an array to represent the matrix A: [code] array([user1]=>array([item1]=>1                                  [item2]=>0                                  [item3]=>0) array([user1]=>array([item1]=>0                                  [item2]=>0                                  [item3]=>0) ... [/code] Therefore I use [code] $arr_user_item=array(); for ($user_id=1; $user_id<=NUMBERUSERS; $user_id++) {    for ($item_id=1; $item_id<=NUMBERITEMS; $item_id++)    {    $arr_user_item[$user_id][$item_id]=0; //this value of row '$user_id' and column 'item_id' in matrix A    } } [/code] Until now everything works. When I for example do [code] echo $arr_user_item[1][1]; [/code] I get 0 on my screen. However I have to assign the right values to the array using the mysql-query on table has_bought. When I do this like I have showed earlier and I do again echo $arr_user_item[1][1]; or even print_r[$arr_user_item] nothing seems to happen. [code] for ($item_id=1; $item_id<=NUMBERUSERS; $item_id++) //constant NUMBERUSERS is the total number of users in our database {    for ($item_id=1; $item_id<=NUMBERITEMS; $item_id++) //constant NUMBERITEMS is the total number of items in our database    { // to see if user has bought the item    $query_user_item="select * from has_bought                       where user_id=".$user_id."          and item_id=".$item_id."";    $result_user_item=mysql_query($query_user_item);    $num_results_user_item=mysql_num_rows($result_user_item);    // if an entry found is found then user has bought the item:    if ($num_results_user_item>0)       {       $arr_user_item[$user_id][$item_id]=1;       }    else       {       $arr_user_item[$user_id][$item_id]=0;       }    } } [/code] When i do now print_r ($arr_user_item); I don't get anything. I checked if my query worked and yes it did. So why can't I work with my array after I assigned new values? [!--quoteo(post=384259:date=Jun 15 2006, 06:26 PM:name=thorpe)--][div class=\'quotetop\']QUOTE(thorpe @ Jun 15 2006, 06:26 PM) [snapback]384259[/snapback][/div][div class=\'quotemain\'][!--quotec--] Im sorry, but I still just can't understand what your doing. Anyway, try adding.... [code] print_r($a); [/code] to the end of the script, this will give you an idea of how what your final array contains.... maybe that will lead you to a solution. [/quote]
  12. Ok, I have been trying again and again. But I am still stuck with this... [img src=\"style_emoticons/[#EMO_DIR#]/unsure.gif\" style=\"vertical-align:middle\" emoid=\":unsure:\" border=\"0\" alt=\"unsure.gif\" /] Is it maybe because I assign values to the array in a for-loop that I can't get these values outside the loop? [img src=\"style_emoticons/[#EMO_DIR#]/unsure.gif\" style=\"vertical-align:middle\" emoid=\":unsure:\" border=\"0\" alt=\"unsure.gif\" /] [!--quoteo(post=384209:date=Jun 15 2006, 04:07 PM:name=bonzie)--][div class=\'quotetop\']QUOTE(bonzie @ Jun 15 2006, 04:07 PM) [snapback]384209[/snapback][/div][div class=\'quotemain\'][!--quotec--] I need to construct a kind of recommendation algorithm. I have a table in mysql named 'has_bought' with columns 'user_id' and 'item_id'. So an entry means that 'user' has bought 'item'. I need to construct a vector V for each user in the 'itemspace': You can think of this as the rows of a binary matrix A where the columns are the items: eg: user 1 |0 1 1| user 2 |1 0 1| user 3 |0 1 1| This means that user 1 has bought item 2 and 3. The constant NUMBERI is the number of users and the constant NUMBERJ the number of items in the database. They are defined as [code] $query_num_users="select * from people"; // table people contains data about users, key is user_id     $result_num_users=mysql_query($query_num_users, $connect);     $num_users=mysql_num_rows($result_num_users); define (NUMBERI, $num_users); $query2="select item_id from item"; // table item contains data about all the items of the shop     $result=mysql_query($query2,$connect);     $num_results=mysql_num_rows($result); //define constant NUMBERJ define (NUMBERJ, $num_results); [/code] I have constructed the array $a ['user']['item'] because I need to make compare the vectors of the different users to determine the most similar users to a certain user (the one logged in). I create the array with the following code: [code] $a(); for ($user_id=1; $user_id<=NUMBERI; $user_id++) {    for ($item_id=1; $item_id<=NUMBERJ; $item_id++)    {    $a[$user_id][$item_id]=0;    } } [/code] Now i would like toassign a 1 to a combination of user-item if the user has bought the item: To find this in the database I constructed the following query: [code] // to find combinations user-item for ($user_id=1; $user_id<=NUMBERI; $user_id++) {    for ($item_id=1; $item_id<=NUMBERJ; $item_id++)    { query3="select * from has_bought                       where user_id=".$user_id."          and item_id=".$item_id."";    $result3=mysql_query($query3, $connect);    $num_results_query3=mysql_num_rows($result3); // to assign the values to the array $a to create the binary matrix A (rows are the users and columns the items)    if ($num_results_query3>0)//if an entry found, this means that user has bought the item       {       $a[$user_id][$item_id]=1;       }    else       {       $a[$user_id][$item_id]=0;       }    } } [/code] [/quote]
  13. I need to construct a kind of recommendation algorithm. I have a table in mysql named 'has_bought' with columns 'user_id' and 'item_id'. So an entry means that 'user' has bought 'item'. I need to construct a vector V for each user in the 'itemspace': You can think of this as the rows of a binary matrix A where the columns are the items: eg: user 1 |0 1 1| user 2 |1 0 1| user 3 |0 1 1| This means that user 1 has bought item 2 and 3. The constant NUMBERI is the number of users and the constant NUMBERJ the number of items in the database. They are defined as [code] $query_num_users="select * from people"; // table people contains data about users, key is user_id     $result_num_users=mysql_query($query_num_users, $connect);     $num_users=mysql_num_rows($result_num_users); define (NUMBERI, $num_users); $query2="select item_id from item"; // table item contains data about all the items of the shop     $result=mysql_query($query2,$connect);     $num_results=mysql_num_rows($result); //define constant NUMBERJ define (NUMBERJ, $num_results); [/code] I have constructed the array $a ['user']['item'] because I need to make compare the vectors of the different users to determine the most similar users to a certain user (the one logged in). I create the array with the following code: [code] $a(); for ($user_id=1; $user_id<=NUMBERI; $user_id++) {    for ($item_id=1; $item_id<=NUMBERJ; $item_id++)    {    $a[$user_id][$item_id]=0;    } } [/code] Now i would like toassign a 1 to a combination of user-item if the user has bought the item: To find this in the database I constructed the following query: [code] // to find combinations user-item for ($user_id=1; $user_id<=NUMBERI; $user_id++) {    for ($item_id=1; $item_id<=NUMBERJ; $item_id++)    { query3="select * from has_bought                       where user_id=".$user_id."          and item_id=".$item_id."";    $result3=mysql_query($query3, $connect);    $num_results_query3=mysql_num_rows($result3); // to assign the values to the array $a to create the binary matrix A (rows are the users and columns the items)    if ($num_results_query3>0)//if an entry found, this means that user has bought the item       {       $a[$user_id][$item_id]=1;       }    else       {       $a[$user_id][$item_id]=0;       }    } } [/code] [!--quoteo(post=384194:date=Jun 15 2006, 03:38 PM:name=thorpe)--][div class=\'quotetop\']QUOTE(thorpe @ Jun 15 2006, 03:38 PM) [snapback]384194[/snapback][/div][div class=\'quotemain\'][!--quotec--] And what are there values then? Help us help you. Put this code in context.... show us your query code... something? I dont understand why you even have this code.... what is it meant to do? [/quote]
  14. these are defined earlier in the script so they have a value. [!--quoteo(post=384184:date=Jun 15 2006, 03:32 PM:name=thorpe)--][div class=\'quotetop\']QUOTE(thorpe @ Jun 15 2006, 03:32 PM) [snapback]384184[/snapback][/div][div class=\'quotemain\'][!--quotec--] Sorry, but that code makes little sense. Where do you define the constants NUMBERI and NUMBERJ ? [/quote]
  15. hello I am stuck with the following script. I have spent hours to make the whole script and now I tried it out and apparently the values I assign to the array based on the sql-query appear to be lost. When I try the 'echo' statement (last line of code) I dont get any output! [code] $a=array(); for ($i=1; $i<=NUMBERI; $i++) {    for ($j=1; $j<=NUMBERJ; $j++)    {    $a[$i][$j]=0;    } } echo $a[1][1]; for ($i=1; $i<=NUMBERI; $i++) {    for ($j=1; $j<=NUMBERJ; $j++)    {    ..... // here a sql-query    .....    if ($num_results>0)       {       $a[$i][$j]=1;       }    else       {       $a[$i][$j]=0;       }    } } echo $a[1][1]; [/code] Anyone who knows what I do wrong?
×
×
  • 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.