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
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
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
Ok, here is what I want to achieve, this is the typic thing I tookl from the URL directory. http://forums.digitalpoint.com/showthread.php?t=1763802&posted=1#post13990294
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
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
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