-
Posts
24,563 -
Joined
-
Last visited
-
Days Won
822
Everything posted by Barand
-
Debug PHP code at run-time (step-over) with breakpoints
Barand replied to softsolutions's topic in PHP Coding Help
I use PHPEd on Windows - has its own built-in debugger -
asort() does not return an array. It sorts the array in the parameter.
-
Displaying contents of Sqlite Database in php
Barand replied to alexmahone's topic in PHP Coding Help
I haven't used sqlite but I think you need $result = $db->query('SELECT * FROM readingstable'); while($row = $result->fetch()) { -
TIP: Avoid column names such as "desc". DESC is a reserved word in SQL
-
Correct syntax is select * from jokes where jokeby like '%anonymous%' or joketitle like '%anonymous%'
-
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
-
Have you used MS SQL Server?
-
Update query with nl2br and preg_replace, something funny happening
Barand replied to Guber-X's topic in PHP Coding Help
Going through your code and debugging it is your responsibility unless you want to hire a consultant edit : lol -
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.
-
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
-
If you haven't noticed, there is no sign of $_POST['product_no'] in that array.
-
MySQL database is fine. It is mysql_* set of functions that is deprecated. Use the mysqli (mysql improved) or PDO libraries instead
-
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'
-
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; }
-
sending form results to a file to use the file include latter how pls?
Barand replied to Baxt01's topic in PHP Coding Help
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 | +-------------+ -
sending form results to a file to use the file include latter how pls?
Barand replied to Baxt01's topic in PHP Coding Help
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. -
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().
-
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
-
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
-
Put your team data in a single table, say "teams", with each row containing the team_id.. Then SELECT .... FROM teams WHERE team_id = ?
-
Why would you want to with numeric values? Concatenation is for strings.
-
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.
-
perhaps the clue is almost 500 views and no-one knows what you are talking about?
-
So you have a separate table for each team where the table name is the team id?