Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
177 views
in Technique[技术] by (71.8m points)

php - Missing row from mysqli $query

I have a problem with MySqli not outputting the result of my query.

$cxn=mysqli_connect($host,$user,$pw,$dbname) or die("Error connecting to server");

if(!$cxn=mysqli_connect($host,$user,$pw,$dbname)){

        $message=mysqli_error($cxn);
        echo $message;
        die();

}

$query= "SELECT * from merchantinfo WHERE industry='Retail'";
$result=mysqli_query($cxn,$query) or die("Could not execute the query");
$row=mysqli_fetch_assoc($result);


while($row = mysqli_fetch_assoc($result))
{
extract($row);
echo "$INDUSTRY: $NAME<br/>";
}

And this is the table i'm currently using.(merchantinfo)

MerchantID    INDUSTRY    NAME              DESCRIPTION
1             Dining      Burger King       Whopper,Whoppers galore!
2             Retail      ZARA              A large clothing retailer
3             Aviation    Virgin Airlines   Lolwut

i am currently getting a totally blank page as my result after my query, though i cant seem to figure out the problem. i've tried changing the 'industry' in $query and the while loop to all caps to match the capitalisation in the table, i've also tried using them all in small caps. Yet i am still getting a blank page as a output.

I've also tried changing the $query to

$query="SELECT * FROM merchantinfo";

which produces the result :

Retail:ZARA
Aviation:Virgin Airlines

i would appreciate it if someone could point out the mistake in the code or point me in the right direction

Thanks!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Remove:

$row=mysqli_fetch_array($result);

It is fetching your first row and is unnecessary (it is essentially discarding it).

Also, unless your column names are uppercase this won't work:

extract($row);
echo "$INDUSTRY: $NAME<br/>";

It would need to be the same case as your actual column names.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...