Jump to content

PHPcadet

Members
  • Posts

    14
  • Joined

  • Last visited

    Never

Everything posted by PHPcadet

  1. By entries do you mean the number of rows in the table? If so use the mysql_num_rows() function.
  2. Go into phpMyAdmin and check the structure of the table (duh).
  3. It seems like MySQL doesn\'t allow you to specify a length for TINYTEXT types. I tried it without the length, but then got another error stating that the primary key didn\'t have a length. So I changed the \'Name\' column to type VARCHAR and specified the length of 20 and it worked ok. Hope this fixes your problem.
  4. I thought mysql_num_rows returns a number. Shouldn\'t the if statement be like this?: [php:1:ef30ccf0ab]<?php $check1 = mysql_num_rows($result2); if($check1 == 0){ } ?>[/php:1:ef30ccf0ab]
  5. To get the last ten records of the table you can change your SELECT to: [php:1:02bad73fad]<?php $sql = \"SELECT id, name FROM articles ORDER BY id * -1 LIMIT 0,10\"; ?>[/php:1:02bad73fad] This will eliminate the $offset variable routine. Then you can just store them in the array and sort them as Barand showed.
  6. If I\'m not mistaken this will give you the sum of the ID field which is 1 + 2 + 3 = 6. I think you should use the COUNT function. Change this line: $query = "SELECT SUM(ID) AS totalrecords FROM table"; To this: $query = "SELECT COUNT(*) AS totalrecords FROM table"; Or you could simplify it using the mysql_num_rows function like this: [php:1:9228aa23a2]<?php $conn = mysql_connect(\'dbhost\', \'dbuser\', \'dbpass\') or die(mysql_error()); mysql_select_db(\'dbname\', $conn) or die(mysql_error()); $query = \"SELECT * FROM table\"; $result = mysql_query($query, $conn) or die(mysql_error()); $totalrecords = mysql_num_rows($result); echo \'Total Records \' . $totalrecords; mysql_close($conn) or die(mysql_error()); ?>[/php:1:9228aa23a2]
  7. Specifically in MySQL version 4.1, which is in alpha testing right now, you will be able to do subqueries.
  8. From my understanding of the MySQL manual, the IN clause can only contain values within the parentheses. See http://www.mysql.com/doc/en/Comparison_Operators.html for an expalnation.
  9. GREAT! Glad to be of help.
  10. I ran the script (CREATE and INSERT) in phpMyAdmin and did not get any errors. Could you post your script file that they are in. Check your mySQL manual to see what a 1064 error is.
  11. Are you trying to delete all the records from the table? If so, there is an easier way using the truncate command. See: http://www.phpfreaks.com/mysqlmanual/page/...e.html#TRUNCATE
  12. PHPcadet

    Update help

    Check the spelling of your column names. In the error message it says \"fileda\". In your UPDATE statement it says \"fielda\". I notice with MySQL and other languages, the error messages aren\'t always exact, meaning you should look \"around\" the code for the eror, sometimes it is before, sometimes it is after. Hope this helps.
  13. PHPcadet

    Update help

    The words \"table\" and \"tables\" are reserved words in MySQL. Not sure if that\'s your problem.
  14. With MySQL you can specify more than one column in the ORDER BY clause in your SELECT statement as in: SELECT * FROM mytable ORDER BY name, number You can even sort each column differently as in SELECT * FROM mytable ORDER BY name ASC, number DESC would give you : Bill 16 Bob 21 George 21 George 12 Jim 18
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.