PHP mysql_query returns all blank values?

I have a massive list of values located in the Database “sweebez_ideagen” in the Table “NAICS”.

All I’m trying to do is write a php script that pulls 500 random values and makes a nice list of them.

When I’m in phpmyadmin, I can run the query “SELECT N_DESCRIPTION FROM NAICS ORDER BY RAND( ) LIMIT 0 , 500” and get everything I want.

But when I tried to code that query to execute in php, i get this:




(^ 500 dots in total)

The data should be readable, since the type is as follows:
column: N_DESCRIPTION
type: varchar(250)
encoding: utf8_unicode_ci

Can you tell me what’s wrong? Code is below :

[php]<?php
mysql_connect(“localhost”,“sweebez_ideagen”,“HIDDEN_PASSWORD”) or die (mysql_error());
mysql_select_db(‘sweebez_ideagen’) or die (mysql_error());

$result = mysql_query(“SELECT N_DESCRIPTION FROM NAICS ORDER BY RAND( ) LIMIT 0 , 500”);

//While there are rows to display
while($row = mysql_fetch_array($result)){

//Display the results from the current row in a list
echo “

  • ”;
    echo $row[field_value];
    $row = mysql_fetch_array($result);
    echo “
  • ”;
    }[/php]

    THANKS ;D !

    Nevermind. Fixed it!

    [php]<?php
    mysql_connect(“localhost”,“sweebez_ideagen”,“PASSSWORD”) or die (mysql_error());
    mysql_select_db(‘sweebez_ideagen’) or die (mysql_error());

    $result = mysql_query(“SELECT N_DESCRIPTION FROM NAICS ORDER BY RAND( ) LIMIT 0 , 500”);

    //While there are rows to display
    while($row = mysql_fetch_array($result)){

    //Display the results from the current row in a list
    echo “

  • ”;
    echo $row[field_value];
    $row = mysql_fetch_array($result);
    echo $row[N_DESCRIPTION];
    echo “
  • ”;
    }
    ?>[/php]

    What was wrong? I think seeing what you changed would help me figure out what i’m doing wrong.

    First, I forgot the “?>”, which was just sloppy.

    Then, notice that i have two echos, “echo $row[field_value];” and “echo $row[N_DESCRIPTION];”.
    Only one of them does anything. “Field value” is meaningless, so I have to actually specify which column I want again, even though it’s just a single column array (I imagine it’s a very useful function if you have multiple columns)

    Sponsor our Newsletter | Privacy Policy | Terms of Service