Jump to content

Recommended Posts

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,

Link to comment
https://forums.phpfreaks.com/topic/147573-solved-hello-all/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/147573-solved-hello-all/#findComment-774707
Share on other sites

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

}

Link to comment
https://forums.phpfreaks.com/topic/147573-solved-hello-all/#findComment-774713
Share on other sites

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>

Link to comment
https://forums.phpfreaks.com/topic/147573-solved-hello-all/#findComment-774721
Share on other sites

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"

Link to comment
https://forums.phpfreaks.com/topic/147573-solved-hello-all/#findComment-774742
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.