You are missing our premiere tool bar navigation system! Register and use it for FREE!

NukeCops  
•  Home •  Downloads •  Gallery •  Your Account •  Forums • 
Readme First
- Readme First! -

Read and follow the rules, otherwise your posts will be closed
Modules
· Home
· FAQ
· Buy a Theme
· Advertising
· AvantGo
· Bookmarks
· Columbia
· Community
· Donations
· Downloads
· Feedback
· Forums
· PHP-Nuke HOWTO
· Private Messages
· Search
· Statistics
· Stories Archive
· Submit News
· Surveys
· Theme Gallery
· Top
· Topics
· Your Account
Who's Online
There are currently, 70 guest(s) and 1 member(s) that are online.

You are Anonymous user. You can register for free by clicking here
Nuke Cops :: View topic - shopstop module / new block creation / mysql help [ ]
 Forum FAQ  •  Search  •   •  Memberlist  •  Usergroups   •  Register  •  Profile •    •  Log in to check your private messages  •  Log in

 
Post new topic  Reply to topicprinter-friendly view
View previous topic Log in to check your private messages View next topic
Author Message
tfry
Nuke Cadet
Nuke Cadet


Joined: Jun 21, 2003
Posts: 3


PostPosted: Sun Jun 22, 2003 12:42 pm Reply with quoteBack to top

I am in the process of creating a new block for use with the shopstop shopping module. The block will display a random product from the database. So far everything is working ok, I have it setup so that the block only shows products that are marked visible=yes If I have a product marked visible=no then it should not show. The problem is that occasionally the block shows up but with nothing in it. I'm assuming that the nothing would be the products marked visible=no How do I fix it so that it always shows a product ? code is below

<?php

if (eregi("block-Random_Product.php", $_SERVER['PHP_SELF'])) {
Header("Location: index.php");
die();
}

global $prefix, $multilingual, $currentlang, $db, $tipath, $user, $cookie;

$r_options = "";
if (isset($cookie[4])) { $r_options .= "&mode=$cookie[4]"; }
if (isset($cookie[5])) { $r_options .= "&order=$cookie[5]"; }
if (isset($cookie[6])) { $r_options .= "&thold=$cookie[6]"; }

if ($multilingual == 1) {
$querylang = "AND (alanguage='$currentlang' OR alanguage='')"; /* the OR is needed to display stories who are posted to ALL lan$
} else {
$querylang = "";
}

$numrows = $db->sql_numrows($db->sql_query("SELECT * FROM ".$prefix."_store"));
if ($numrows > 1) {
$sql = "SELECT pid FROM ".$prefix."_store";
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result)) {
$pid = $row[pid];
$pid_array .= "$pid-";
}
$r_pid = explode("-",$pid_array);
mt_srand((double)microtime()*1000000);
$numrows = $numrows-1;
$pid = mt_rand(0, $numrows);
$pid = $r_pid[$pid];
} else {
$pid = 1;
}
$sql = "SELECT pid, shortdes, name, imgsrc, price FROM ".$prefix."_store WHERE pid='$pid' AND visible=\"yes\" $querylang
ORDER BY pid DESC LIMIT
0,9";
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
$imgsrc = $row[imgsrc];
$shortdes = $row[shortdes];
$name = $row[name];
$price = $row[price];
$content .= "<table border=\"0\" width=\"100%\">";
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result)) {
$content .= "<br><center><a href=\"\"><img src=\"$row[imgsrc]\" border=0<p>";
$content .= "<tr><td valign=\"top\"></td><td><center><a href=\"\">$row[name]</a></td></tr>";
$content .= "<tr><td valign=\"top\"></td><td><center>$row[shortdes]</a></td></tr>";
$content .= "<tr><td valign=\"top\"></td><td><center>$row[price]</a></td></tr>";
}
$content .= "</table>";

?>
Find all posts by tfryView user's profileSend private message
Raven
General
General


Joined: Mar 22, 2003
Posts: 5233

Location: USA

PostPosted: Sun Jun 22, 2003 1:20 pm Reply with quoteBack to top

This is a sidenote and I doubt that it will fix your problem, but always use single quotes in SQL queries. Change
Quote:
$sql = "SELECT pid, shortdes, name, imgsrc, price FROM ".$prefix."_store WHERE pid='$pid' AND visible=\"yes\"
to
Code:
$sql = "SELECT pid, shortdes, name, imgsrc, price FROM ".$prefix."_store WHERE pid='$pid' AND visible='yes'
Reasons being, amonst other things, is that true ANSI syntax requires it and many dbms's will croak, although MySQL is forgiving and double quotes take more compiler time, albeit negligible in just an isolated incident Wink.

_________________
Those who hear not the music think the dancers mad.
Raven Web Hosting|My Scripts & Stuff
Find all posts by RavenView user's profileSend private messageVisit poster's website
tfry
Nuke Cadet
Nuke Cadet


Joined: Jun 21, 2003
Posts: 3


PostPosted: Sun Jun 22, 2003 2:33 pm Reply with quoteBack to top

thanks, I made that change but it didn't seem to help. I'm kinda new at coding in php/mysql so I'm kinda at a point where I'm stuck
Find all posts by tfryView user's profileSend private message
Raven
General
General


Joined: Mar 22, 2003
Posts: 5233

Location: USA

PostPosted: Sun Jun 22, 2003 4:11 pm Reply with quoteBack to top

There are a couple of ways. You could put a "default" product in your table that has a description like No Products Selected, or whatever. The other way is to have an 'else' clause after you get the num_rows result. Another question for you, I notice that you say if ($numrows > 1). Wouldn't you rather mean if ($numrows > 0) ? Otherwise 2 rows have to be selected before that logic is performed.

_________________
Those who hear not the music think the dancers mad.
Raven Web Hosting|My Scripts & Stuff
Find all posts by RavenView user's profileSend private messageVisit poster's website
tfry
Nuke Cadet
Nuke Cadet


Joined: Jun 21, 2003
Posts: 3


PostPosted: Sun Jun 22, 2003 5:49 pm Reply with quoteBack to top

The else clause would probably be a good idea. Just not sure how to do it yet. i'm kinda new to php and mysql. Would the else clause stop it from displaying no records at all ? Basically the whole idea of the thing is to display random products from the catalog. one of the fields in the catalog is visible if set to yes then it displays ok, if it is set to no then it displays nothing on the screen, all i get is the title for the block with no content in the box. this is going to be a new block for the stopshop shopping module for phpnuke. i really need to solve this one so that i can make sure a product always shows. i would think that if a product is turned off it would skip it display the next random product. weird < appreciate the help, us newbies to php, sql programming need help >
Find all posts by tfryView user's profileSend private message
Display posts from previous:      
Post new topic  Reply to topicprinter-friendly view
View previous topic Log in to check your private messages View next topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



Powered by phpBB © 2001, 2005 phpBB Group

Ported by Nuke Cops © 2003 www.nukecops.com
:: FI Theme :: PHP-Nuke theme by coldblooded (www.nukemods.com) ::
Powered by · TOGETHER TEAM srl ITALY http://www.togetherteam.it · DONDELEO E-COMMERCE http://www.DonDeLeo.com
Web site engine's code is Copyright © 2002 by PHP-Nuke. All Rights Reserved. PHP-Nuke is Free Software released under the GNU/GPL license.
Page Generation: 0.815 Seconds - 380 pages served in past 5 minutes. Nuke Cops Founded by Paul Laudanski (Zhen-Xjell)
:: FI Theme :: PHP-Nuke theme by coldblooded (www.nukemods.com) ::