/    Sign up×
Community /Pin to ProfileBookmark

Help with a Query please?

Hi Guys,

I was wondering if someone could help me with my query below as I can’t see why it’s not working.

Now I want to:

[b]GET the current story_id of the story the user is browsing and if there is nothing in the database row for manual_link_one_txt or manual_link_one_url or manual_link_two_txt or manual_link_two_url then output the message ‘Sorry, there are no related stories’ if these values are empty[/b]

However, if any of these columns are empty the system does not show the message – it just outputs two dot.jpg’s?

Any help most appreciated.

Thanks

Chris

[code=php]
<?
$query = “SELECT manual_link_one_txt, manual_link_one_url, manual_link_two_txt or manual_link_two_url FROM cms_stories where story_id=”.$_GET[‘story_id’];
$result = mysql_query($query) OR die(mysql_error());
$defineResults = mysql_num_rows($result);
if (empty($defineResults)) {
echo (“<DIV ALIGN=”CENTER”><strong><font size=’1′ face=’Verdana, Arial, Helvetica, sans-serif’>Sorry, there are no related
stories</font></div>”);

} else {

while($row = mysql_fetch_assoc($result)) {
echo ” <img src=’../images/story_images/dot.jpg’ width=’10’ height=’10’ align=’absbottom’ /><strong><font size=’1′ face=’Verdana, Arial, Helvetica, sans-serif’><a href='{$row[manual_link_one_url]}’>
{$row[manual_link_one_txt]}</a></font></strong><br />
<img src=’../images/story_images/dot.jpg’ width=’10’ height=’10’ align=’absbottom’ /><strong><font size=’1′ face=’Verdana, Arial, Helvetica, sans-serif’><a href='{$row[manual_link_two_url]}’>
{$row[manual_link_two_txt]}</a></font></strong <br />”;
}

}
?>
[/code]

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@JayMApr 16.2007 — [B]mysql_num_rows[/B] will return the number of rows found for that query. Hence, if it finds no rows, it should return 0. So you're testing condition in the if statement is incorrect.

Try this:

[code=php]
if ($defineResults == 0)
{
//...
}
[/code]
Copy linkTweet thisAlerts:
@chrisbauthorApr 16.2007 — Thanks for replying, but that's how I started off with the query and it did/does the same thing:

[code=php]
<?
$query = "SELECT manual_link_one_txt, manual_link_one_url, manual_link_two_txt or manual_link_two_url FROM cms_stories where story_id=".$_GET['story_id'];
$result = mysql_query($query) OR die(mysql_error());

$defineResults = mysql_num_rows($result);
if ($defineResults == 0) {
echo ("<DIV ALIGN="CENTER"><strong><font size='1' face='Verdana, Arial, Helvetica, sans-serif'>Sorry, there are no related

stories</font></div>");

} else {

while($row = mysql_fetch_assoc($result)) {
echo " <img src='../images/story_images/dot.jpg' width='10' height='10' align='absbottom' /><strong><font size='1' face='Verdana, Arial, Helvetica, sans-serif'><a href='{$row[manual_link_one_url]}'>
{$row[manual_link_one_txt]}</a></font></strong><br />
<img src='../images/story_images/dot.jpg' width='10' height='10' align='absbottom' /><strong><font size='1' face='Verdana, Arial, Helvetica, sans-serif'><a href='{$row[manual_link_two_url]}'>
{$row[manual_link_two_txt]}</a></font></strong <br />";
}

}
?>
[/code]


So I changed it to empty, but the code is still simply outputting dot.jpg's if it can't find anything?
Copy linkTweet thisAlerts:
@launchpad67aApr 16.2007 — I think there are some coding errors in your first part. Looking at this in a php editor I have corrected it to read:
[code=php]<?
$query = "SELECT manual_link_one_txt OR manual_link_one_url OR manual_link_two_txt OR manual_link_two_url FROM cms_stories WHERE story_id = ".$_GET['story_id'];
$result = mysql_query($query) OR die(mysql_error());

$defineResults = mysql_num_rows($result);
if ($defineResults == 0) {
echo "<div align='center'><strong><font size='1' face='Verdana, Arial, Helvetica, sans-serif'>Sorry, there are no related stories</font></div>";

} else {[/code]


Still working on the second part which I can see has errors as well.
×

Success!

Help @chrisb spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...