I cant seem to get a count of rows in a query. I have tried numerous and various methods, but cant get a result.
This is one of the sets of experimentaions. The query works, it produces a result of the items checked, however getting a count of rows is eluding me.
The LIMIT also does not work.
mysql_select_db($database_assess, $assess_remote);
$fid="SELECT name, count(*) FROM counties WHERE name = 'checked' LIMIT 5";
$result1=mysql_query($fid, $assess_remote);
$row = mysql_fetch_array($result1);
$row_count = mysql_num_rows($result1);
$fetch=mysql_fetch_row($result1);
echo 'id'.$row['firm_id'].'<br />';
echo 'row count'.$row_count.'<br />';
$count=count($result1);
echo 'count'.$count;
echo 'fetch'.$fetch;
In the above I get this result:
id
row count1
count1fetchnum_results
I have the original query in the same page as this:
mysql_select_db($database_assess, $assess_remote);
$query_county_result = "SELECT * FROM counties WHERE name ='checked' LIMIT 5";
$result=mysql_query($query_county_result, $assess_remote);
$row = mysql_fetch_array($result);
$row_count = mysql_num_rows($result);
I also have this in fishing for something to work:
////////////////////////////this is working\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
if ( !empty($_POST['county']))
foreach ( $_POST['county'] AS $id => $name )
echo 'You have selected '. " {$name}".'<br />';
///////////////////above working, generates list of values(text)\\\\\\\\\\\\\\\\\\\\\\\\
echo 'count_result()'.count($result1).'<br />';
echo 'count_row()'.count($row).'<br />';
echo 'count_row_count()'.count($row_count).'<br />';
echo 'id()'.count($id).'<br />';
echo 'count_fid()'.count($fid).'<br />'.'<br />'.'<br />';
echo 'fetch'.$fetch.'<br />'.'<br />'.'<br />';
echo 'this is where the for starts';
for($i=0; $i<$_POST['counties']; $i++){
echo 'result1()'.count($id).'<br />';
echo 'row()'.count($row).'<br />';
echo 'row_count()'.count($row_count).'<br />';
echo 'fid'.count($fid).'<br />';
echo 'fetch'.$fetch;
echo 'checked'.$name.'<br />'.'<br />';
}
These are the results: (atually the block starting with result1()1
I get 15 times)
You have selected Aroostook County
You have selected Cumberland County
You have selected Franklin County
count_result()1
count_row()2
count_row_count()1
id()1
count_fid()1
fetch
this is where the for startsresult1()1
row()2
row_count()1
fid1
fetchcheckedFranklin County
result1()1
row()2
row_count()1
fid1
fetchcheckedFranklin County
result1()1
row()2
row_count()1
fid1
fetchcheckedFranklin County
This is coming from a dynamically created checklist. The code for it is
<?php $st=$_SESSION['name'];
//echo 'There are '."$totalRows_Recordset1" . ' Counties in' . " $choice_name";
if ( isset($_POST['submit']) ) { // if form is submitted, process it
print "<form action=\\"counties-result.php\\" method=\\"POST\\">\
";
if ($Recordset1) {
print "<table width=200 border=0>\
";
print "<th> </th>\
";
print "</tr>\
";
//create table
$i = 0;
while ( $row = mysql_fetch_array($Recordset1) ) {
$i++;
print "<tr>\
";
print "<td><input type=\\"checkbox\\" name=\\"county[$i]\\" value=\\"$row[name]\\">";
//echo "<td>{$row['state_id']}</td>\
";
echo "<td>{$row['name']}</td>\
";
echo "</tr>\
";
}//end while
print "</table>\
";
} else {
echo("<P>Error performing query: " .
mysql_error() . "</P>");
}
print "<input type=\\"hidden\\" name=\\"counties\\" value=\\"$i\\"/>\
";
print "<input type=\\"submit\\" name=\\"submit\\" value=\\"Go\\"/>\
";
}?>
<?php $insquery = "CREATE TABLE 'countchoice'"?>
<?php $checked= $_SESSION['checked']; ?>
I have started a new query using the above query, the only thing that is changed is the WHERE is pointing to a bit a data in the DB and not a qeary result.
Anyone be able to help me on this?
Thank you
Gary