Jump to content

Need help with PHP Join sql willing to pay through Paypal!


xtrax

Recommended Posts

Here's what works on my machine

 

<?php

$db = new MySQLi('localhost','root','','db');

$author_id = 19;

$query = "SELECT DISTINCT cat.varCategory
FROM tarticles art
LEFT JOIN tcategories cat ON art.intCategory = cat.intID
WHERE art.intAuthorId = $author_id
	AND art.intStatus = 1";

$result = $db->query($query);

if( $result == FALSE ) {
echo "Query failed! Query: $query <br> Error: $db->error";
} else {
while( $row = $result->fetch_assoc() ) {
	echo "{$row['varCategory']}<br>";
}
}

?>

Link to comment
Share on other sites

Ok i tried xyph  code but it stops the page from loading...

 

Nothing in the error logs or on the page to even indicate there is an error...

 

We are using the following MySQL 5.0.95-community in cPanel and PHP Version 5.3.13

 

would this have anything to do with it??

 

xtrax

Link to comment
Share on other sites

Never mind I got it xyph !!!!!!!!!!!!!!!!!!!!!  :D

 

I made some minor changes to the following and its now working I am also caching the results to reduce the load

 

This is what I came up with

 

 

$article_topics = $d->fetch("SELECT DISTINCT (cat.varCategory) FROM tarticles art LEFT JOIN tcategories cat ON art.intCategory = cat.intID WHERE art.intAuthorId = '$author_ID' AND art.intStatus = '1' LIMIT 0 , 30", "daily", "auth_topics".$author_ID.".af");
if($article_topics){
foreach($article_topics as $dtopic){
$catsname = $dtopic['varCategory'];
echo "<strong>".$catsname."</strong>, ";
}
}

 

 

Where can I make a donation and what would you like for payment!

 

xtrax  :D

 

Link to comment
Share on other sites

Is this what you wanted as well?

 

SELECT DISTINCT
  cat.varCategory,
  cat.intParentId,
  art.intCategory
FROM
  tarticles art
  LEFT JOIN
    tcategories cat
  ON
    art.intCategory = cat.intID
WHERE
  art.intAuthorId = 19

 

Alternately, you may have wanted

 

SELECT
  cat.varCategory,
  cat.intParentId,
  art.intCategory
FROM
  tarticles art
  LEFT JOIN
    tcategories cat
  ON
    art.intCategory = cat.intID
WHERE
  art.intAuthorId = 19
GROUP BY
  cat.varCategory

 

Though, in this case, those two queries may return the exact same results.

Link to comment
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.