简体   繁体   English

用php查询mysql行

[英]querying mysql rows with php

hi friends my problem is i have some excel sheets which are uploaded to database then that data will be retrieved and posted in a web portal. 嗨,朋友,我的问题是我有一些Excel工作表,这些工作表已上传到数据库,然后数据将被检索并发布在Web门户中。

my problem is i cant able to query particular data which is marked in this pic 我的问题是我无法查询此图片中标记的特定数据

can anyone help me query only numbers[all] without '%' and assign them to a variable ..... 谁能帮我只查询没有'%'的数字[all]并将它们分配给变量...

<?php

$con = mysql_connect("localhost","root","");

if(!$con)die (msql_error());

$db = mysql_select_db("csv");

if(!$db) die(mysql_error());

$query = mysql_query("select * from users");

$rows = mysql_fetch_array($query);
______________________________________________________
**if i have column like this how to extract only 1,12,14,60,4 ? without '%'
and also remove first row "High value %" and post them in this format
$output = array(1,12,14,60,4)**
______________________________________________________
High value%
1%
12%
14%
60%
4%

You can use trim function, to get rid of the '%' characters. 您可以使用trim功能来摆脱'%'字符。

I code the following test: 我编写以下测试代码:

$test = "15%";
echo trim($test,"%");

----------FULL TEST--------------

$test = "15%"; //test case
echo "Test:".trim($test,"%")."</br>";

$rows = array('1%','2%','3%');
$aux = array();

foreach($rows as $key)
{
echo trim($key,"%")."</br>"; //just output
$aux[] = trim($key,"%"); //or transforming
}

var_dump($aux);

Mysql version: MySQL版本:

set @test = "15%";
select trim(BOTH '%' FROM @test);

#Retrieve all rows but first
select name,trim(BOTH '%' FROM lastname) as normal,trim(BOTH '%' FROM email) as high 
from users limit 1,1000;


#select row based on Normal %
select name, trim(BOTH '%' FROM lastname) as normal,trim(BOTH '%' FROM email) as high
from users
where trim(BOTH '%' FROM lastname) = 5;

SQL Fiddle: http://sqlfiddle.com/#!2/bf0b2/5 SQL小提琴: http ://sqlfiddle.com/#!2 / bf0b2 / 5

Codepad: http://codepad.viper-7.com/fmw59H (updated) 键盘: http//codepad.viper-7.com/fmw59H (已更新)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM