RE: [PHP-DB] Select Query--Need help urgently
Irin said: $sql = mysql_query(SELECT * FROM class where timetable_day='Monday'); $row = mysql_fetch_array($sql); $result = $db-query($sql); $numofrows = mysql_num_rows($sql); From the PHP manual: array mysql_fetch_array ( resource result [, int result_type]) You can't send the function mysql_fetch_array a string as a parameter. It needs a result resource. Assuming that your $db class returns a result resource, you can try this: $sql = SELECT * FROM table; $result = $db-query($sql); $row = mysql_fetch_array($result); $numofrows = mysql_num_rows($result); If for some reason you don't know what that class function query is returning, you can do it this way and it will work for sure: $sql = SELECT * FROM table; $result = mysql_query($sql); $row = mysql_fetch_array($result); $numofrows = mysql_num_rows($result); HTH, Katie Dewees Web Developer E-mail: [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Select Query--Need help urgently
Irin said: $sql = mysql_query(SELECT * FROM class where timetable_day='Monday'); Oops, I see that he DID do a mysql_query and save the result resource in $sql. Sorry, guys! I haven't had my coffee yet this morning! Katie Dewees Web Developer E-mail: [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Array sorting question...
NIPP, SCOTT V (SBCSI) wrote: I am trying to populate an array from a MySQL database. I think I have the code correct to populate the array, but I need to somehow sort the array eliminating duplicate values. I think I can loop through the array doing a comparison and building a new array by discarding the value if it is a duplicate, but I was not sure if there was a more efficient way of doing this. You can ask for only unique values to be returned in the database result. Try something like this: $sql = SELECT UNIQUE username FROM table WHERE where_clause ORDER BY username; Katie Dewees Web Developer/PHP Programmer [EMAIL PROTECTED] http://www.evans-young.com -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] query that finds when something is NOT IN a table
(Using MySQL and PHP) I need to only return a row from table1 if its id is not found in table2. The query below is how I think it should work. However (as I had imagined), this doesn't work. Syntax error (you can't put a select inside a select like that). SELECT table1.id FROM table1 WHERE table1.sold=1 AND table1.id NOT IN (SELECT table2.table1_id FROM table2) (and no, those aren't the real table or field names - just trying to be clear) I could do a SELECT first that gets all the values in the table2, then (in PHP) run through a result set of rows from table1, checking each time to see if its id is in table2, and if it isn't, display it...but this seems excessive. I went through all of the functions to use in a WHERE clause in my MySQL book...am I missing something? Thanks, -- Katie Evans-Young Web Developer Evans-Young Designs E-mail: [EMAIL PROTECTED] --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.445 / Virus Database: 250 - Release Date: 1/21/2003 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php