我可以将这些查询压缩为更少的内容吗
是否可以进行 1 次查询并仍然提取所需的数据?
我有很多疑问,想合并它们以使页面加载更快。
干杯
$result = mysql_query("SELECT * FROM products where added = '$date'");
$new_items = mysql_num_rows($result);
$result = mysql_query("SELECT * FROM products where isasin = 1");
$isasin = mysql_num_rows($result);
$result = mysql_query("SELECT * FROM products where isasin = 0");
$notasin = mysql_num_rows($result);
$result = mysql_query("SELECT * FROM products where EAN = ''");
$blank_ean = mysql_num_rows($result);
$result = mysql_query("SELECT * FROM products where EAN = '-'");
$ean_line = mysql_num_rows($result);
$result = mysql_query("SELECT * FROM products where EAN = 'PRERELEASE'");
$ean_prerelease = mysql_num_rows($result);
$result = mysql_query("SELECT * FROM products where format = 'delete'");
$delete = mysql_num_rows($result);
$result = mysql_query("SELECT * FROM products where format = 'VIDEO GAMES'");
$vgames = mysql_num_rows($result);
$result = mysql_query("SELECT * FROM products where format = 'CONSOLE ACCESORIES'");
$conacc = mysql_num_rows($result);
$result = mysql_query("SELECT * FROM products where format = 'Games'");
$games = mysql_num_rows($result);
$result = mysql_query("SELECT * FROM products where format = 'Cool Stuff'");
$cool_stuff = mysql_num_rows($result);
$result = mysql_query("SELECT * FROM products where format = 'Unknown'");
$Unknown = mysql_num_rows($result);
$result = mysql_query("SELECT * FROM products where description = ''");
$no_desc = mysql_num_rows($result);
$result = mysql_query("SELECT * FROM products where product_name = ''");
$no_name = mysql_num_rows($result);
//game stats
$result = mysql_query("SELECT * FROM products where format = 'Xbox 360'");
$xbox360 = mysql_num_rows($result);
$result = mysql_query("SELECT * FROM products where format = 'Playstation 3'");
$ps3 = mysql_num_rows($result);
$result = mysql_query("SELECT * FROM products where format = 'Nintendo DS'");
$nds = mysql_num_rows($result);
$result = mysql_query("SELECT * FROM products where format = 'Nintendo Wii'");
$wii = mysql_num_rows($result);
$result = mysql_query("SELECT * FROM products where format = 'PC'");
$pc = mysql_num_rows($result);
$result = mysql_query("SELECT * FROM products");
$total_games = mysql_num_rows($result);
Is it possible to make 1 query and still pull the required data?
I have many queries and would like to consolidate them to make the page load faster.
Cheers
$result = mysql_query("SELECT * FROM products where added = '$date'");
$new_items = mysql_num_rows($result);
$result = mysql_query("SELECT * FROM products where isasin = 1");
$isasin = mysql_num_rows($result);
$result = mysql_query("SELECT * FROM products where isasin = 0");
$notasin = mysql_num_rows($result);
$result = mysql_query("SELECT * FROM products where EAN = ''");
$blank_ean = mysql_num_rows($result);
$result = mysql_query("SELECT * FROM products where EAN = '-'");
$ean_line = mysql_num_rows($result);
$result = mysql_query("SELECT * FROM products where EAN = 'PRERELEASE'");
$ean_prerelease = mysql_num_rows($result);
$result = mysql_query("SELECT * FROM products where format = 'delete'");
$delete = mysql_num_rows($result);
$result = mysql_query("SELECT * FROM products where format = 'VIDEO GAMES'");
$vgames = mysql_num_rows($result);
$result = mysql_query("SELECT * FROM products where format = 'CONSOLE ACCESORIES'");
$conacc = mysql_num_rows($result);
$result = mysql_query("SELECT * FROM products where format = 'Games'");
$games = mysql_num_rows($result);
$result = mysql_query("SELECT * FROM products where format = 'Cool Stuff'");
$cool_stuff = mysql_num_rows($result);
$result = mysql_query("SELECT * FROM products where format = 'Unknown'");
$Unknown = mysql_num_rows($result);
$result = mysql_query("SELECT * FROM products where description = ''");
$no_desc = mysql_num_rows($result);
$result = mysql_query("SELECT * FROM products where product_name = ''");
$no_name = mysql_num_rows($result);
//game stats
$result = mysql_query("SELECT * FROM products where format = 'Xbox 360'");
$xbox360 = mysql_num_rows($result);
$result = mysql_query("SELECT * FROM products where format = 'Playstation 3'");
$ps3 = mysql_num_rows($result);
$result = mysql_query("SELECT * FROM products where format = 'Nintendo DS'");
$nds = mysql_num_rows($result);
$result = mysql_query("SELECT * FROM products where format = 'Nintendo Wii'");
$wii = mysql_num_rows($result);
$result = mysql_query("SELECT * FROM products where format = 'PC'");
$pc = mysql_num_rows($result);
$result = mysql_query("SELECT * FROM products");
$total_games = mysql_num_rows($result);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你只需要看数量、看外观。而且,从外观上看,它是MySQL。这是您的一个查询:
每个计数都是一列,您应该相应地为它们别名
You only need the counts, by the looks. Also, by the looks, it's MySQL. Here is your one query:
Each count is a column, you should alias them accordingly
好的,最后一个查询选择了所有记录,因此之前的查询是多余的。如果您想在不选择所有记录的情况下执行此操作,请使用以下内容:
您可以使用 OR 来选择与指定条件 1 或条件 2 匹配的任何记录。 AND 的用法不同,意味着记录必须匹配 criteria1 AND criteria2 才能返回。在 w3schools 上查找 And/OR 以获取可靠的示例。
Ok, the last query selects all records so the previous queries are redundant. If you want to do this without selecting all records use something like:
You can use OR for selecting any records matching the specified criteria1 OR criteria2. AND is used differently and means a record must match criteria1 AND criteria2 to be returned. Look up And/OR on w3schools for solid examples.