nepzap2 Posted March 2, 2009 Share Posted March 2, 2009 I'm just curious if anyone finds something wrong with this query $sql = "SELECT * FROM Journal WHERE type = News Article LEFT JOIN JournalImages ON Journal.image_id = JournalImages.image_id ORDER BY Journal.created DESC"; It is not working, but when I get rid of the "WHERE type = News Article" it works. I'll appreciate any help. Thanks, Quote Link to comment https://forums.phpfreaks.com/topic/147573-solved-hello-all/ Share on other sites More sharing options...
br0ken Posted March 2, 2009 Share Posted March 2, 2009 You need single speech marks around News Article. $sql = "SELECT * FROM Journal WHERE type = 'News Article' LEFT JOIN JournalImages ON Journal.image_id = JournalImages.image_id ORDER BY Journal.created DESC"; Quote Link to comment https://forums.phpfreaks.com/topic/147573-solved-hello-all/#findComment-774696 Share on other sites More sharing options...
nepzap2 Posted March 2, 2009 Author Share Posted March 2, 2009 Thanks for your reply br0ken, I thought that may be the case... but I add those single quotes like below $sql = "SELECT * FROM Journal WHERE type = 'News Article' LEFT JOIN JournalImages ON Journal.image_id = JournalImages.image_id ORDER BY Journal.created DESC"; and I get this Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /usr/local/apache/vhosts/myDomain.com/Journals/news.php on line 21 Quote Link to comment https://forums.phpfreaks.com/topic/147573-solved-hello-all/#findComment-774707 Share on other sites More sharing options...
premiso Posted March 2, 2009 Share Posted March 2, 2009 You most likely have an error in your sql. You need to check if mysql_error is populated, if it is echo that out as it will show the error. That or the SQL returned 0 records and you can use mysql_num_rows to check that. Quote Link to comment https://forums.phpfreaks.com/topic/147573-solved-hello-all/#findComment-774712 Share on other sites More sharing options...
br0ken Posted March 2, 2009 Share Posted March 2, 2009 Are you passing the $sql variable into mysql_query first? Paste all of your code please but it should read something like: $sql = "SELECT * FROM Journal WHERE type = News Article LEFT JOIN JournalImages ON Journal.image_id = JournalImages.image_id ORDER BY Journal.created DESC"; $result = mysql_query($sql); while($row = mysql_fetch_assoc($result)) { // Do something here } Quote Link to comment https://forums.phpfreaks.com/topic/147573-solved-hello-all/#findComment-774713 Share on other sites More sharing options...
nepzap2 Posted March 2, 2009 Author Share Posted March 2, 2009 Hello br0ken Yes I Am. Below is what I'm trying to achieve <?php include('includes/conn.php'); $sql = "SELECT * FROM Journal WHERE type = 'News Article' LEFT JOIN JournalImages ON Journal.image_id = JournalImages.image_id ORDER BY Journal.created DESC"; $result = mysql_query($sql); ?> <div id="wrapper"> <div id="maincontent"> <?php while ($row = mysql_fetch_assoc($result)) { ?> <?php $image = $row['filename']; echo "<img src='saimages/thumbs/$image' alt='$image' class='articlesThumbs' />" ; ?> <h2><?php echo $row['title']; ?></h2> <p class="thumbParagraph"> <?php /* $extract = getFirst($row['article']); echo $extract[0]; if ($extract[1]) { echo '<br /><br /><a href="details.php?article_id='.$row['article_id'].'" class="thumbParagraphLink"> More</a>'; } */ $article = $row['article']; $article_array = explode(" ", $article ); if(count($article_array) > 50){ $article = ""; for($i = 0; $i < 50; ++$i){ $article .= ($article_array[$i] . " "); } $article .= " ..."; } echo nl2br($article); echo '<br /><br /><a href="details.php?article_id='.$row['article_id'].'" class="thumbParagraphLink"> More</a>'; ?> </p> <?php } ?> </div> Quote Link to comment https://forums.phpfreaks.com/topic/147573-solved-hello-all/#findComment-774721 Share on other sites More sharing options...
premiso Posted March 2, 2009 Share Posted March 2, 2009 $result = mysql_query($sql) or die("SQL WAS: {$sql}<br /> Error was: " . mysql_error()); See what error that gives you. Quote Link to comment https://forums.phpfreaks.com/topic/147573-solved-hello-all/#findComment-774723 Share on other sites More sharing options...
a-scripts.com Posted March 2, 2009 Share Posted March 2, 2009 I believe that the WHERE clause is supposed to be used AFTER the JOIN part .. SELECT * FROM Journal LEFT JOIN JournalImages ON Journal.image_id = JournalImages.image_id WHERE type = 'News Article' ORDER BY Journal.created DESC Quote Link to comment https://forums.phpfreaks.com/topic/147573-solved-hello-all/#findComment-774732 Share on other sites More sharing options...
nepzap2 Posted March 2, 2009 Author Share Posted March 2, 2009 Thank you guys. Apparently the error was that the " WHERE type = 'News Article' " in the beginning was beaking the join. SELECT * FROM Journal LEFT JOIN JournalImages ON Journal.image_id = JournalImages.image_id WHERE type = 'News Article' ORDER BY Journal.created DESC" Quote Link to comment https://forums.phpfreaks.com/topic/147573-solved-hello-all/#findComment-774742 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.