close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Validating against DB

Thread began 10/26/2010 12:58 pm by fdotmedia | Last modified 10/27/2010 9:42 am by Jason Byrnes | 2857 views | 14 replies |

fdotmedia

Validating against DB

I have a total number of people allowed in a class... I would like to have the class disappear from the dynamic drop down based on wether the count is <= 25...

This is what I have so far, I'm thinking there's an easier way using our WA tools...

<?php 
do {
?>
<option value="<?php echo $row_ClassDetails['CDID']; ?>" >
<?php
$mysqldate = $row_ClassDetails['CDDate'];
$mydate = date("M, d Y",strtotime($mysqldate));
echo $mydate;
?> -
<?php echo $row_ClassDetails['CDName']; ?> -
<?php
$cdid = $row_rtnUser['CDID'];

$sql = "SELECT COUNT(CDID) AS total FROM rtnUser WHERE CDID = $cdid";
$query = mysql_query($sql);
$recordset = mysql_fetch_assoc($query);
$count = $recordset["total"];

echo "$count";
?> of <?php echo $row_ClassDetails['CDMaximum']; ?> max.
</option>
<?php
} while ($row_ClassDetails = mysql_fetch_assoc($ClassDetails));
?>



This returns a "1" for all of the 7 classes.

The first class has a single user, the rest have 0...

Any help would be great!

Ted

Sign in to reply to this post

Jason ByrnesWebAssist

This isn't something the webassist tools can make any easier.

The count function counts the number of rows returned.


how are you storing the registered users?


Looking at your sql, it seams logical that it would return 1 for each of them.

Sign in to reply to this post

fdotmedia

Thanks for the reply Jason... I was assuming that the Server Validation may have some use here... Apparently no :-)...

I am returning the user in the 'rtnUser' recordset and using the 'CDID' row in both the 'ClassDetails' and 'rtnUsers' tables... Do I need to left join the 2 tables together?

Sign in to reply to this post

Jason ByrnesWebAssist

I'm not sure I follow, what would a record in the rtnUser table look like

Sign in to reply to this post

fdotmedia

rtnUsers table

`rtnUser` (
`rtnUID` int(10) NOT NULL auto_increment,
`rtnFName` varchar(255) NOT NULL,
`rtnLName` varchar(255) NOT NULL,
`rtnDOB` varchar(255) default NULL,
`rtnSSN` varchar(255) default NULL,
`rtnState` varchar(255) NOT NULL,
`rtnCity` varchar(255) NOT NULL,
`rtnEmail` varchar(255) NOT NULL,
`rtnPassword` varchar(255) NOT NULL,
`rtnPhone` varchar(255) NOT NULL,
`rtnPhone2` varchar(255) default NULL,
`rtnZipcode` varchar(255) default NULL,
`rtnReferred` varchar(255) default NULL,
`CTDID` int(10) default NULL,
`rtnCourtOther` varchar(255) default 'none',
`rtnCase` varchar(255) default NULL,
`CDID` int(10) default NULL,
`rtnPaid` varchar(255) default 'no',
`FDID` int(10) NOT NULL,
`rtnUserLevel` int(10) NOT NULL default '1',
PRIMARY KEY (`rtnUID`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=81 ;



ClassDetails table

`ClassDetails` (
`CDID` int(10) NOT NULL auto_increment,
`FID` int(10) NOT NULL,
`CDName` varchar(255) NOT NULL,
`CDAddress` varchar(255) NOT NULL,
`CDCity` varchar(255) NOT NULL,
`CDState` varchar(255) NOT NULL,
`CDZipcode` varchar(255) NOT NULL,
`CDPhone` varchar(255) NOT NULL,
`CDPrice` varchar(255) NOT NULL,
`CDDate` date NOT NULL,
`CDStartTime` varchar(255) NOT NULL,
`CDLastTime` date default NULL,
`CDLength` varchar(255) NOT NULL,
`CDMaximum` int(3) default NULL,
PRIMARY KEY (`CDID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=15 ;
Sign in to reply to this post

Jason ByrnesWebAssist

what is the recordset data returned if you do a select all of the rtnUser table

Sign in to reply to this post

fdotmedia

When I use the following code, I get 4... 4 is the total number of records I have in the db... only 1 has a class assigned to them...

<?php 
do {
?>
<option value="<?php echo $row_ClassDetails['CDID']; ?>" >
<?php
$mysqldate = $row_ClassDetails['CDDate'];
$mydate = date("M, d Y",strtotime($mysqldate));
echo $mydate;
?> -
<?php echo $row_ClassDetails['CDName']; ?> - <?php
$cdid = $row_rtnUser['CDID'];
$rtnUID = $row_rtnUser['rtnUID'];

$sql = "SELECT COUNT(CDID) AS total FROM rtnUser GROUP BY CDID";
$query = mysql_query($sql);

$count=0;
while ($recordset = mysql_fetch_assoc($query))
{
$count++;
}
echo "$count";
?> of <?php echo $row_ClassDetails['CDMaximum']; ?> max.
</option>
<?php
} while ($row_ClassDetails = mysql_fetch_assoc($ClassDetails));
?>
Sign in to reply to this post

fdotmedia

I think I'm making it too hard...

All I need to do is count the number of users with a CDID = 'whatever' and not display the class in my dynamic dropdown...

On that same page, in a different query, I compare NOW() < `CDLastTime`

SELECT * FROM ClassDetails WHERE NOW() < `CDLastTime` ORDER BY ClassDetails.CDDate ASC

The idea behind that is, if the class start time is INSIDE 48 hours (or whatever the 'CDLastTime' is) it doesn't show... So maybe I use the same strategy and not display the class once the users total >= `CDMaximum`...

The problem(?) is, the 'CDMaximum' row is in the 'ClassDetails' table and the 'CDID' row I'm counting is in the 'rtnUser' table... Does it make sense to do something like this?

SELECT * FROM rtnUser LEFT JOIN ClassDetails on rtnUser.CDID = ClassDetails.CDID COUNT(rtnUID) AS total FROM rtnUser GROUP BY CDID



In which case, do I need to LEFT JOIN the 'ClassDetails' and 'rtnUser' tables then count the CDID??? Or can I because the 'ClassDetails' table has a different CDID count???

Your thoughts?

Sign in to reply to this post

Jason ByrnesWebAssist

I cant answer your questions without seeing the actual data.

Sign in to reply to this post

fdotmedia

here is my DB and .php page...

the dynamic dropdown in question is line 456

Any help you could muster would rock!

Ted

Attached Files
Step1-ClassDetails-rtnUser.zip
Sign in to reply to this post
loading

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...