Page 2 of 2
Posted: Tue Dec 19, 2006 11:24 pm
by psurrena
It returns 0
Code: Select all
function viewServices($category) {
$query = "SELECT * FROM checkboxes_final WHERE cid='$cid' AND check_cat='$category'";
$result = mysql_query($query) or die (mysql_error() . 'Cannot Retrieve Information');
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$check_text = $row['check_text'];
echo $check_text;
}
return $check_text;
echo mysql_num_rows($result);
}
Posted: Tue Dec 19, 2006 11:40 pm
by John Cartwright
Once a function hits a return, it will terminate.. try putting the mysql_num_rows(..) before the return
Posted: Tue Dec 19, 2006 11:42 pm
by psurrena
Above "return $check_text;" is zero and in the loop returns nothing...
Posted: Tue Dec 19, 2006 11:46 pm
by John Cartwright
I didn't realize this, but you need to pass $cid to the function. This is whats causing your query to return 0 rows.. assuming there are actually rows in your table.
it helps to have error_reporting(E_ALL); to catch uninitialized variables.
muliple inserts - SOLVED
Posted: Wed Dec 20, 2006 1:15 am
by psurrena
HERE IT IS!
I use $cid=$_GET['cid'] in the beginning but as you said - I wasn't using it in the function. That was the first problem. The second problem was using reversing my use of semicolons and quotes in the SQL query. Now it works!
Thank you so much for all your help!
Code: Select all
<?php
function viewServices($cid, $category) {
$query = "SELECT check_text FROM checkboxes_final WHERE cid='$cid' AND check_cat='$category'";
$result = mysql_query($query) or die (mysql_error() . 'Cannot Retrieve Information');
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$check_text = $row['check_text'];
}
echo "Rows: " . mysql_num_rows($result);
return $check_text;
}
$final = viewServices($cid, 'membership_database');
echo $final;
echo '</ul>';
?>