php,selecting userid

Discussion in 'PHP' started by tldmic, Apr 10, 2010.

  1. #1
    Hi all,

    I have the following table

    id userid catid ariticle_title Article
    1 uid2 2 by_uid2 details
    2 uid2 3 by_uid2 details
    3 uid1 6 by_uid1 details

    catid means article category e.g 1=fiction,2=science,3=drama,4=action,etc


    Here is my problem:

    Lets say I am trying to access' all the articles by uid2 to be listed,

    here is my code:


    if($_GET['catid']== 2)
    {

    $article_title = mysql_query("SELECT* FROM userArticles WHERE userid='$session->userid' AND catid=2 ") or die(mysql_error());

    while($row = mysql_fetch_array( $article_title ))
    {
    // Print out the contents of each row into a table
    $article = $row['id'];
    echo "<li><A href='my_articles.php?article_id=$article_id' >".$row['article_title']."</a>";
    }
    }

    please help me,
    I have been struggling with this thing for days now,
    many thanks
    tldmic
     
    tldmic, Apr 10, 2010 IP
  2. lukeg32

    lukeg32 Peon

    Messages:
    645
    Likes Received:
    19
    Best Answers:
    1
    Trophy Points:
    0
    #2
    You havent said what your problem is? What isnt working? Are you getting errors? Or is isnt displaying correctly? etc etc.....

    You will usually get aquicker response if you include a full description of the problem.... With that said....


    In the above, you have not set any values for article_id nor are there any values for $row['id'] and $row['article_title']......

    You might want to use mysql_fetch_assoc instead of array which uses keys instead of numerical array values....

    http://uk3.php.net/manual/en/function.mysql-fetch-assoc.php
     
    lukeg32, Apr 10, 2010 IP
  3. tldmic

    tldmic Peon

    Messages:
    41
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3


    Ok!!,

    The thing is that when I run the scrip, nothing is displayed, so there is an error somewhere in the code which I cannot find
     
    tldmic, Apr 11, 2010 IP
  4. tldmic

    tldmic Peon

    Messages:
    41
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    tldmic, Apr 11, 2010 IP
  5. tldmic

    tldmic Peon

    Messages:
    41
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    forums.digitalpoint.com/showthread.php?t=1763802&posted=1#post13990294
     
    tldmic, Apr 11, 2010 IP
  6. mike.judd

    mike.judd Greenhorn

    Messages:
    84
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    18
    #6
    1) Try $_REQUEST['catid'] == 2;

    2) Try $queryStr = "SELECT * FROM userArticles WHERE userid = '" . $session->userid . "' AND catid = 2"; (you gotta rewrite your sql statement, it's ugly to me)
    $result = mysql_query ($queryStr);

    3) Try

    $return = array();

    while ..... {

    $return[] = $row;
    }

    foreach ($return as $item) {
    echo ....;
    }

    5) The code generates error may not be this block but another block, check whole thing to see if you have missed any ";"

    Good luck
     
    mike.judd, Apr 11, 2010 IP
  7. lukeg32

    lukeg32 Peon

    Messages:
    645
    Likes Received:
    19
    Best Answers:
    1
    Trophy Points:
    0
    #7
    Did you change your mysql fetch function to use an associative array instead, as above?
     
    lukeg32, Apr 11, 2010 IP
  8. tldmic

    tldmic Peon

    Messages:
    41
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Hi,

    I did change mysql fetch func to assoc,

    Ok,
    I used your method, this is my findings,

    when I remove user= "...." from $queryStr, it diplays only <li> dots with no output.
    when I remove cadid=1 from queryStr and leave user= ...., nothing is displayed,

    my userid =$session... works fine, I have tested it to see if it outs values, it does.

    I dont know what could be wrong :(
     
    tldmic, Apr 11, 2010 IP
  9. tldmic

    tldmic Peon

    Messages:
    41
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    thank you all, its working perfectly,
    the problem was with my post, i posted the wrong userid's first using my old coding style,
    thank you all
     
    tldmic, Apr 11, 2010 IP
  10. lukeg32

    lukeg32 Peon

    Messages:
    645
    Likes Received:
    19
    Best Answers:
    1
    Trophy Points:
    0
    #10
    Heh - yeah, been there, done that! :) Glad its working ok now for you.
     
    lukeg32, Apr 11, 2010 IP