Re: [PHP-DB] SQL COUNT vs mysql_num_rows
if tables are joined correctly it shouldn't be any problem to get count of a column, and yes - delegating that task to the database should be more efficient concerning the execution time boyan -- [EMAIL PROTECTED] wrote: maybe mysql cannot COUNT the result from more than 1 table, hence the mysql_num_rows function - but isn't it good programming practice to get the SQL to do as much work up front? - Do you Yahoo!? Protect your identity with Yahoo! Mail AddressGuard -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Problem
A bit difficult to debug this without the file included (config.php); providing the error message would also be helpful. At first glance, I'm just wondering what does the dot mean in the table name used in the FROM clause: FROM school.physics_chris_rockets It shouldn't generate a php syntacs error message, but I'm afraid that query wont work boyan -- Jacob Hackamack wrote: Currently there seems to be some problem with syntax of some sort, for some reason I keep getting thrown back parse errors, commenting out the lines just moves the parse error line around. If anybody has any help thanks in advance. include('config.php'); $Period = $_POST["Period"]; $Name = $_POST["Name"]; $conn = mysql_connect ( $dbhost , $dbuser , $dbpass ); $sql_select = 'SELECT * FROM school.physics_chris_rockets WHERE Period LIKE '.$Period.' AND Visible LIKE "Y" ORDER by Position, Name, Date'; $result = mysql_query($sql_select); echo 'Physics Sign-Up Input'; echo ''; echo ''; echo ''; echo 'Welcome '.$Name.', '; echo ' '; $Space = ''; $Data = $dataRow[1] ; echo' Position'; echo' Openings'; echo' '; while ( $dataRow = mysql_fetch_row ( $result ) ) { if ($Space != $dataRow[3]) { echo ' '; echo ' '; echo ''.$dataRow[3].''; $Space = $dataRow[3] ; } else { echo ''; } if ($Data == "") { echo "Open"; } else { echo ''.$dataRow[1].''; } } echo ''; echo ''; echo ''; echo ''; echo ''; ?> Jacob -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] SELECT COUNT - result from two tables
Putting more than one table in the FROM clause means tables are joined, then at least following problems could arise: - using WHERE clause you can have empty recordset returned and then COUNT conflicts with it because there is actually no any data to be returned; - joining two (or more) tables without using aliases to the equally named columns in the SELECT/WHERE/COUNT clauses will produce error message instead of expecting data; - COUNT(*) wont work if u have equal table names in the tables; If you give us some more detail description of the tables then it will be easier to find where the problem is Boyan -- John W. Holmes wrote: Mark Gordon wrote: Yes, query is definitely working without COUNT(*). Even in the most stripped down form, the query fails: $sql = "SELECT COUNT(bandid), genre FROM bands, genre"; $result=mysql_query($sql); while ($gen=mysql_fetch_row($result)) { echo $gen[1]; } Fails how? If it echos zero, it's not failing; your query just isn't returning any rows (regardless whether you think it should or not). -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Help: do ... while, reverse data query
you can do it at sql level by using ORDER BY ... DESC like: SELECT * FROM categories WHERE cat_id = '$cat' ORDER BY cat_id DESC and then proceed the returned recordset in 'normal' way (order) -- Douglas Freake wrote: Hi there, I need to do a loop where the mysql query starts at the bottom and goes up, as if the data was in reverse order. This is for building a category/ sub_category menu. Data structure: (cat_id, cat_sub, cat_name) sample routine: do { $sql = "SELECT * FROM categories WHERE cat_id = '$cat'"; $go = mysql_num_rows($sql_result); $cat = $row["cat_sub"]; $cat_id = $row["cat_id"]; } while ( $go == 1); Any ideas how to to start a the end of the database? Thanks for your help! Doug -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php