Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...