lssjg Posted May 14, 2006 Share Posted May 14, 2006 for the 2nd time i am stuck.,... this time it isn't just adding { and }.The following my edited version of the whole php script... the bits i took out is just the table and the layout of each table of news...[code]<?include 'include/config.php';$query = mysql_query('SELECT * FROM news ORDER BY newsid DESC');while($news = mysql_fetch_array($query)) {$username = mysql_query("SELECT username FROM users WHERE loginname='{$news['author']}'"); echo "<td align=\"center\" colspan=\"2\">Posted by <a href=\"user.php?action=profile&mode=view&user={$news['author']}\">$username</a> | Posted at {$news['date']}<br /><br />"; }?>[/code]Ok... now explanation time...For each row in 'news' it will- grab the username for the 'author'- stick the username in after the words 'posted by'- and a few dozen other things that aren't related to the problemNow... what's happening... there isn't any error... (thus why i don't have anything to go on)instead this happens Posted by Resource id #8 starting at 8... the next news is 9 then 10 and then 11.... that's the 4 test news entries i've done. though the newsid for them isn't 8, 9 10 or 11.. it's 1, 2, 4 and 5... cause i deleted one.Anyway... of course the author part is still working because the link is still going to the correct addressi tested putting test1 as the author of an entry and also a member in users... and thus it pointed at [a href=\"http://localhost/site/user.php?action=profile&mode=view&user=test1\" target=\"_blank\"]http://localhost/site/user.php?action=prof...view&user=test1[/a] so it can make the link between the tables... it just gives me resource link all the time.It is doing the same in FF and IECan anyone please help?P.S. the author is simply the login name of the user that wrote the news.... author isn't username because i'm allowing changing of username.... Quote Link to comment https://forums.phpfreaks.com/topic/9645-news-problem-same-scripts-different-problem/ Share on other sites More sharing options...
toplay Posted May 14, 2006 Share Posted May 14, 2006 1) You can't use $username like that because you forgot to do a fetch for the second query!2) You're code doesn't check for errors. Click on the [a href=\"http://www.phpfreaks.com/forums/index.php?showtopic=31047&view=findpost&p=153359\" target=\"_blank\"]PHP F.A.Q.[/a] link. Find and read the [b]MySQL Data Retrieval[/b] section for example code of getting data from MySQL with error checking after every MySQL command.3) You can do one query instead of two by using a join. See tutorial: [a href=\"http://www.keithjbrown.co.uk/vworks/mysql/mysql_p5.shtml\" target=\"_blank\"]http://www.keithjbrown.co.uk/vworks/mysql/mysql_p5.shtml[/a] Quote Link to comment https://forums.phpfreaks.com/topic/9645-news-problem-same-scripts-different-problem/#findComment-35680 Share on other sites More sharing options...
lssjg Posted May 15, 2006 Author Share Posted May 15, 2006 Huh........ that kinda doesn't make much sense... could you give an example...like i have read it but i don't kinda understand ... could you show me what you mean? Quote Link to comment https://forums.phpfreaks.com/topic/9645-news-problem-same-scripts-different-problem/#findComment-35865 Share on other sites More sharing options...
lssjg Posted May 17, 2006 Author Share Posted May 17, 2006 bump..i really would quite like to know this... could someone give an example Quote Link to comment https://forums.phpfreaks.com/topic/9645-news-problem-same-scripts-different-problem/#findComment-36528 Share on other sites More sharing options...
toplay Posted May 17, 2006 Share Posted May 17, 2006 The FAQ had MySQL fetch examples. So, does the join tutorial. Anyway, below are a couple of untested examples (there maybe PHP or SQL syntax errors).Example 1:[code]include 'include/config.php';$query = mysql_query('SELECT `author`, `date` FROM `news` ORDER BY newsid DESC');if (!$query) { echo 'SQL error on news select', mysql_error(); exit;}while($news = mysql_fetch_assoc($query)) {$result = mysql_query("SELECT `username` FROM `users` WHERE `loginname`='{$news['author']}'");if (!$result) { echo 'SQL error on users select', mysql_error(); exit;}$row = mysql_fetch_assoc($result);$username = $row ? $row['username'] : ''; // if no data, set to empty stringecho "<td align=\"center\" colspan=\"2\">Posted by <a href=\"user.php?action=profile&mode=view&user={$news['author']}\">$username</a> | Posted at {$news['date']}<br /><br />";}[/code]Example 2:[code]include 'include/config.php';$query = mysql_query('SELECT `news`.author, `news`.date, `users`.username FROM `news` LEFT JOIN `users` ON `news`.author = `users`.loginname ORDER BY `news`.newsid DESC');if (!$query) { echo 'SQL error on select', mysql_error(); exit;}while($row = mysql_fetch_assoc($query)) {echo "<td align=\"center\" colspan=\"2\">Posted by <a href=\"user.php?action=profile&mode=view&user={$row['author']}\">{$row['username']}</a> | Posted at {$row['date']}<br /><br />";}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/9645-news-problem-same-scripts-different-problem/#findComment-36540 Share on other sites More sharing options...
lssjg Posted May 17, 2006 Author Share Posted May 17, 2006 Hey, thanks....i have taken a look at both... the 2nd doesn't work... but the 1st does, so i'm using that, but i have edited it quite a bit....... it almost looks like a different language.... hee [img src=\"style_emoticons/[#EMO_DIR#]/laugh.gif\" style=\"vertical-align:middle\" emoid=\":laugh:\" border=\"0\" alt=\"laugh.gif\" /] anyway..... now my only problem, is now the actual news isn't showing up on ff or ie Quote Link to comment https://forums.phpfreaks.com/topic/9645-news-problem-same-scripts-different-problem/#findComment-36543 Share on other sites More sharing options...
toplay Posted May 17, 2006 Share Posted May 17, 2006 I've updated the 2nd example. You really should use one query. It will be a whole lot faster.Good luck. Quote Link to comment https://forums.phpfreaks.com/topic/9645-news-problem-same-scripts-different-problem/#findComment-36688 Share on other sites More sharing options...
lssjg Posted May 17, 2006 Author Share Posted May 17, 2006 ok... now the 2nd never really worked... and without editing this new 3nd i get Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in E:\Websites\Server\www\site\site\news.php on line 21Anyway.. that's href=\"user.php?action=profile&mode=view&user={$news['author']}\">$username</a> | what i was really trying to do is...before this thread i could get everything woring but, i got resource id # something as the username..... so i start using the 1st example.... and suddenly the news (the actual) news doesn't turn up......what iw ant is for the news to come back Quote Link to comment https://forums.phpfreaks.com/topic/9645-news-problem-same-scripts-different-problem/#findComment-36754 Share on other sites More sharing options...
toplay Posted May 18, 2006 Share Posted May 18, 2006 When needing help, always post the most current relevant code with error and line number of where the error is.To help with echoing variables click on the [a href=\"http://www.phpfreaks.com/forums/index.php?showtopic=31047&view=findpost&p=153359\" target=\"_blank\"]PHP F.A.Q.[/a] link. Find and read the answer to [b]Q: Is there another way of getting around escaping quotes all the time?[/b].Another approach is to use the heredoc method:[a href=\"http://us2.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc\" target=\"_blank\"]http://us2.php.net/manual/en/language.type....syntax.heredoc[/a]Parse Errors are caused by human error. Check on the line of the error, but usually one to many lines before it, for missing closing tags (i.e. ", ), }, ;, etc.).Here's a list of what those PHP tokens seen in error messages mean:[a href=\"http://us2.php.net/manual/en/tokens.php#tokens\" target=\"_blank\"]http://us2.php.net/manual/en/tokens.php#tokens[/a] Quote Link to comment https://forums.phpfreaks.com/topic/9645-news-problem-same-scripts-different-problem/#findComment-36790 Share on other sites More sharing options...
lssjg Posted May 18, 2006 Author Share Posted May 18, 2006 the reason why i made another post... is because i couldn't work it out... i tried 3 other methods.... and the script i am currently trying is the 1st example (in a couple of posts above). Once i get that working i will modifiy it to my hearts content... Quote Link to comment https://forums.phpfreaks.com/topic/9645-news-problem-same-scripts-different-problem/#findComment-36832 Share on other sites More sharing options...
lssjg Posted May 22, 2006 Author Share Posted May 22, 2006 still need help making this appear... Quote Link to comment https://forums.phpfreaks.com/topic/9645-news-problem-same-scripts-different-problem/#findComment-37907 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.