Jump to content

[SOLVED] Hello All


nepzap2

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

Archived

This topic is now archived and is closed to further replies.

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