从mySQL获取到HTML TABLE(Fetch from mySQL to HTML TABLE)
我已经使用过这段代码,但除了在网页上显示表格之外,它还没有取得任何其他内容。
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>database connections</title> </head> <body> <?php $username = "root"; $password = " "; $host = "localhost"; $connector = mysql_connect($host,$username,$password) or die("Unable to connect"); echo "Connections are made successfully::"; $selected = mysql_select_db("ticad", $connector) or die("Unable to connect"); //execute the SQL query and return records $result = mysql_query("SELECT * FROM users "); ?> <table border="2" style= "background-color: #84ed86; color: #761a9b; margin: 0 auto;" > <thead> <tr> <th>id</th> <th>Names</th> <th>Company</th> <th>Position</th> <th>Email</th> <th>Event</th> <th>Comments</th> </tr> </thead> <tbody> <?php while( $row = mysql_fetch_assoc( $result ) ){ echo "<tr> <td>{$row\['id'\]}</td> <td>{$row\['Names'\]}</td> <td>{$row\['Company'\]}</td> <td>{$row\['Position'\]}</td> <td>{$row\['Email'\]}</td> <td>{$row\['Event'\]}</td> <td>{$row\['Comments'\]}</td> </tr>\n"; } ?> </tbody> </table> <?php mysql_close($connector); ?> </body> </html>
I have used this code but its not fetching anything other than displaying the table on the web.
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>database connections</title> </head> <body> <?php $username = "root"; $password = " "; $host = "localhost"; $connector = mysql_connect($host,$username,$password) or die("Unable to connect"); echo "Connections are made successfully::"; $selected = mysql_select_db("ticad", $connector) or die("Unable to connect"); //execute the SQL query and return records $result = mysql_query("SELECT * FROM users "); ?> <table border="2" style= "background-color: #84ed86; color: #761a9b; margin: 0 auto;" > <thead> <tr> <th>id</th> <th>Names</th> <th>Company</th> <th>Position</th> <th>Email</th> <th>Event</th> <th>Comments</th> </tr> </thead> <tbody> <?php while( $row = mysql_fetch_assoc( $result ) ){ echo "<tr> <td>{$row\['id'\]}</td> <td>{$row\['Names'\]}</td> <td>{$row\['Company'\]}</td> <td>{$row\['Position'\]}</td> <td>{$row\['Email'\]}</td> <td>{$row\['Event'\]}</td> <td>{$row\['Comments'\]}</td> </tr>\n"; } ?> </tbody> </table> <?php mysql_close($connector); ?> </body> </html>
原文:https://stackoverflow.com/questions/38952437
更新时间:2023-08-18 18:08
最满意答案
使用
TRY_CONVERT(UNIQUEIDENTIFIER, parameter2) AS customerguid
代替
CONVERT(UNIQUEIDENTIFIER, parameter2) AS customerguid
视图内联到查询中,
CONVERT
可以在WHERE
之前运行。对于其他一些讨论,请参阅SQL Server不应引发不合逻辑的错误
Use
TRY_CONVERT(UNIQUEIDENTIFIER, parameter2) AS customerguid
instead of
CONVERT(UNIQUEIDENTIFIER, parameter2) AS customerguid
Views are inlined into the query and the
CONVERT
can run before theWHERE
.For some additional discussion see SQL Server should not raise illogical errors
相关问答
更多-
第一个查询是可以的,但是你在GUID的第一部分缺少一个数字,它应该有8个数字,而不是7个......像这样: SELECT * FROM MyTable WHERE id = '71494DD6-90FB-417D-B9E2-28F34103C039' The first query is ok, but you are missing a digit on the first part of the GUID, it should have 8 digits, not seven....somethin ...
-
在SQL Server中将varchar转换为uniqueidentifier(Convert varchar to uniqueidentifier in SQL Server)[2021-10-30]
DECLARE @uuid VARCHAR(50) SET @uuid = 'a89b1acd95016ae6b9c8aabb07da2010' SELECT CAST( SUBSTRING(@uuid, 1, 8) + '-' + SUBSTRING(@uuid, 9, 4) + '-' + SUBSTRING(@uuid, 13, 4) + '-' + SUBSTRING(@uuid, 17, 4) + '-' + SUBSTRING(@uuid, 21, 12) ... -
从字符串转换为uniqueidentifier时转换失败(Conversion failed when converting from a character string to uniqueidentifier)[2024-04-26]
我对这个问题只有一个想法 - T1.ApplicationUserID和T2.UserID的类型是不同的......我认为这个Flash会因为你提到的错误而出现。 请检查数据类型,它们是什么? I have only one idea about this issue - the types of T1.ApplicationUserID and T2.UserID are different ... I think that this flash appears because of error you' ... -
在存储过程中插入GUID(uniqueidentifier)值(Inserting GUID (uniqueidentifier) value in stored procedure)[2023-05-09]
这只是使用SSMS向导执行存储过程时(部分)中断的行为。 当从客户端代码实际调用它时,大多数数据访问库允许您使用适当的类型传递参数(例如,作为来自.Net代码的Guid),数据访问库将确保它正确传递。 如果直接将其写入查询窗口,请用单引号将值包围。 That's only the (partially) broken behaviour when executing the stored procedure using the SSMS wizard. When actually calling it fr ... -
带有MySQL的实体框架6 - UniqueIdentifier问题(Entity Framework 6 with MySQL - UniqueIdentifier issues)[2023-11-06]
我必须使用CHAR(36)而不是VARCHAR(64)(在迁移时由MySql Workbench工具生成),实体框架会自动将其视为GUID,一切都正常。 I have to use CHAR(36) instead of VARCHAR(64) (which has been generated by MySql Workbench tool at the time of migration) and the Entity Framework automatically treats it as GUID ... -
是否建议将VARIQUEIDENTIFIER数据存储在VARCHAR类型中?(Is it advisable to store UNIQUEIDENTIFIER data in VARCHAR type?)[2022-10-31]
如果您所说的列不是用作主键或索引,那么您将不会遇到任何问题 - 您可以随意存储任何内容。 如果该列已经是索引甚至主键,您将遇到相同的问题(关于您的帖子说数据的长度可变) 如果在进行此更改时引入索引或主键,则应考虑使用可变长度列对此可能产生的性能影响。 如果以上是不可避免的,一个好的建议是尝试将列的大小减小到36(我认为这是大多数系统和框架生成的唯一标识符的标准长度,包括SQL Server的UNIQUEIDENTIFIER类型,它通过5个字母数字实体表示,完全由用(4)连字符分隔的32个符号组成。 如果当前 ... -
从varchar到uniqueidentifier的SQL转换在视图中失败(SQL conversion from varchar to uniqueidentifier fails in view)[2023-09-29]
使用 TRY_CONVERT(UNIQUEIDENTIFIER, parameter2) AS customerguid 代替 CONVERT(UNIQUEIDENTIFIER, parameter2) AS customerguid 视图内联到查询中, CONVERT可以在WHERE之前运行。 对于其他一些讨论,请参阅SQL Server不应引发不合逻辑的错误 Use TRY_CONVERT(UNIQUEIDENTIFIER, parameter2) AS customerguid instead ... -
将字符串转换为asp.net中的uniqueidentifier(Convert string to SQL Server uniqueidentifier in asp.net)[2023-06-30]
Guid有一个构造函数,它将一个string作为参数。 Guid aGuid = new Guid(aString); 确保它的格式正确: 包含以下格式之一的GUID的字符串(“d”表示忽略大小写的十六进制数字): 32个连续的数字:ddddddddddddddddddddddddddddddddd -要么- 在组之间连接8,4,4,4和12个数字组。 整个GUID可以选择性地包含在大括号或圆括号中:dddddddddddddddddddddddddddddddd - 或 - (ddddddddddddd ... -
尝试以下操作: SET DATEFORMAT YMD; UPDATE [Database].[dbo].[Table] SET [DoB]=[DoBText] WHERE ISDATE( [DoBText] ) = 1 这将转换那些被认为是有效的日期/时间值,其余的将保持原样。 Try the following: SET DATEFORMAT YMD; UPDATE [Database].[dbo].[Table] SET [DoB]=[DoBText] WHERE ISDATE( [DoBText ...
-
SQL查询错误:转换varchar值时转换失败(SQL query error: Conversion failed when converting the varchar value)[2022-10-08]
@data_column是一个int,因此您需要将其转换为varchar,因为您正在构建一个字符串。 SET @mySql = 'INSERT INTO '+@table_name+'('+@column_name+') VALUES('+ Convert(Varchar(10), @data_column)+')' 当sql server遇到混合字符串和int的表达式时,它会尝试将字符串转换为int(而不是相反)。 这在此处记录: SQL Server数据类型优先级 @da ...