PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Basically my code checks for the number of rows for a value. If the value is within what it needs to be it displays a checkbox, if it doesnt then it will not display anything.
$dbh=mysql_connect ('localhost','user','pass') or die ("Unable to connect to MySQL server: <br>" . mysql_error());
mysql_select_db ('databasename', $dbh) or die ("Unable to select database: <br>" . mysql_error());
$query = "SELECT * FROM database WHERE code='ES-C1-07'";
$result = mysql_query($query);
$numrows = mysql_num_rows($result);
if ($numrows > "30") { // if program is full
}
else
{
<input type="checkbox" name="ES-C1-07" value="ES-C1-07">;
}
Why doesn't something like this work? Any help is appreciated!!!
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Note: As a general rule, putting 'urgent' and other discriptive terms that might suggest you need immediate help in your title is a sure fire way to get your post overlooked. Everyone's posts are urgent, and the volunteers that offer assistance in these forums do the best they can with that they have, regardless of the urgency of your particular request. This is not point you out directly, but being new, I thought I'd at least prepare you for our community. That being said...
Here's the logic you are giving the parser (with a little code cleanup):
<?php
// get the number of rows from the query
$numrows = mysql_num_rows($result);
// If the number of rows in the table is more than 30, do absolutely nothing
if ($numrows > 30) {
// if program is full
}
else
{
// Since there are less than 30 rows, echo out a form field.
echo '<input type="checkbox" name="ES-C1-07" value="ES-C1-07">';
}
?>
<?php
if ($numrows <= 30) {
// Since there are less than 30 rows, echo out a form field.
echo '<input type="checkbox" name="ES-C1-07" value="ES-C1-07">';
}
?>
// ............
else
{
// You can close the PHP block here. Everything will be outputted as-is.
?>
<input type="checkbox" name="ES-C1-07" value="ES-C1-07">;
<?php
// Start parsing PHP again..
}
<?
$dbh=mysql_pconnect ('localhost','username','password') or die ("Unable to connect to MySQL server: <br>" . mysql_error());
mysql_select_db ('database', $dbh) or die ("Unable to select database: <br>" . mysql_error());
$query = "SELECT * FROM TRANSACTION_PROGRAM_CODES WHERE PROGRAM_CODE='ES-C1-07'";
$result = mysql_query($query);
$numrows = mysql_num_rows($result);
if ($numrows > 30) { // if program is full
}
else
{
echo '<input type="checkbox" name="ES-C1-07" value="ES-C1-07">';
}
?>