Jump to content

Barand

Moderators
  • Posts

    24,563
  • Joined

  • Last visited

  • Days Won

    822

Everything posted by Barand

  1. I use PHPEd on Windows - has its own built-in debugger
  2. asort() does not return an array. It sorts the array in the parameter.
  3. I haven't used sqlite but I think you need $result = $db->query('SELECT * FROM readingstable'); while($row = $result->fetch()) {
  4. TIP: Avoid column names such as "desc". DESC is a reserved word in SQL
  5. Correct syntax is select * from jokes where jokeby like '%anonymous%' or joketitle like '%anonymous%'
  6. By using an "ORDER BY ..." clause in your query. As I don't know your table structure there is no way I can tell you any more. If you have a date column, then order by date DESC
  7. Have you used MS SQL Server?
  8. Going through your code and debugging it is your responsibility unless you want to hire a consultant edit : lol
  9. vinny42, Are you just on commission from PostgreSQL or a full-time salaried evangelist? Most of us who are using MySQL don't give a damn how it's done in PostgreSQL, SQL Server or any other RDBMS.
  10. and SUB = '159' or SUB = '111' or SUB = '71' can be written more easily as and SUB IN ('159', '111', '71') which then sidesteps the (...) problem
  11. If you haven't noticed, there is no sign of $_POST['product_no'] in that array.
  12. MySQL database is fine. It is mysql_* set of functions that is deprecated. Use the mysqli (mysql improved) or PDO libraries instead
  13. When using string values in a query they should be enclosed in single quotes otherwise SQL treats them as column names. WHERE name = $nName should be WHERE name = '$nName'
  14. Use fetch_assoc() or fetch_row() and not fetch_array() as the latter fetches the data twice. $data = array(); $result = mysqli_query($con,"SELECT data1, data2, data3 FROM datatable"); while($row=mysqli_fetch_assoc($result)){ $data[] = $row; }
  15. In which case you need to make it as idiot-proof as possible Create a table of players. This is the only place that will contain the player name so spelling mismatches can't happen. Use this table to create a dropdown selection of player names with the ids as the option values. Thisselected id goes into the points table. CREATE TABLE player ( player_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, player_name VARCHAR(100) ); CREATE TABLE points ( id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, player_id INT, points INT ); +-------------+ | player | +-------------+ +-------------+ | player_id |----+ | points | | player_name | | +-------------+ +-------------+ | | id | +---<| player_id | | points | +-------------+
  16. An auto_increment key isn't mandatory so long as you have another column that contains unique values and is a candidate for a primary key. For example, in an employee database you might use the company employee number or national insurance number. Names are not good candidates for a primary key; two people can legitimately have the same name plus it is easy to mistype a name giving two people when there should only be one.
  17. Don't forget to sanitize all string inputs with mysqli_real_escape_string() before inserting them into your database. Numerics can be sanitized with intval() or floatval().
  18. People with the same score should have equal rank EG id score rank -- ----- ---- 7 10 1 1 9 2 5 9 2 6 8 4 4 8 4 2 8 4 3 5 7 This, however, gives rise to another problem. Depending on how many share the same rank there may or may not be a rank of rank+1 or rank-1. Take id 4 with 8 points and rank of 4. In this case the score above has rank-2 and score below has rank+3 This query will find ranks as opposed to row numbers SELECT a.id, a.score as scoreA, a.rank as rankA FROM ( SELECT id, @rowa := @rowa+1 as row, @ranka := IF(score=@prevscorea, @ranka, @rowa) as rank, @prevscorea := score as score FROM scores JOIN (SELECT @rowa:=0, @ranka:=0,@prevscorea:=0) as init ORDER BY score DESC ) as a
  19. Variables inside single quotes don't work eg $string1 = "happy"; $string2 = "birthday"; echo '$string1' . " " . '$string2'; // --> $string1 $string2 echo "$string1 $string2"; // --> happy birthday echo $string1 . ' ' . $string2; // --> happy birthday
  20. Put your team data in a single table, say "teams", with each row containing the team_id.. Then SELECT .... FROM teams WHERE team_id = ?
  21. Why would you want to with numeric values? Concatenation is for strings.
  22. But in answer to your question, you cannot assign table or column names to parameters in a prepared statement, you can only supply column values.
  23. ROFL
  24. perhaps the clue is almost 500 views and no-one knows what you are talking about?
  25. So you have a separate table for each team where the table name is the team id?
×
×
  • 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.