Multi-Dimensional Array, Almost There

Hi,

I have been trying to complete a multidimensional array. It currently dumps the whole array but it wont echo individual rows which are the last 3 lines.

Can anyone please advise how I can echo just single rows instead of the whole array?

<?php
    if(isset($_GET['skill'])) {
        $skills = $_GET['skill'];
        
        $sql = "SELECT * FROM users WHERE skill1 = '$skills'";
        $res = mysql_query($sql) or die(mysql_error());
        //This will return one row, is that what you want?
        //    $row = mysql_fetch_assoc($res); 
        //    $num_rows = mysql_num_rows($res); 
        
        //in your job post it sounds like the query would retutn multiple rows.
        //this will loop the resut of the query.
        while ($row = mysql_fetch_assoc($res)) {
            var_dump($row);
            echo $firstname;
        }
    }

?>



<?php echo (!empty($row['skill1'])) ? $row['skill1'] : ''; ?>
<?php echo $skill1; ?>
<?php echo $skill; ?>

you should not use the $_GET variables directly on your mysql query, it is dangerous, try filtering it before you use it.

Also I don’t see you declared the variable $firstname, is that what you are having problems with?

If the variable $firstname is part of the query results then you should be doing something like $row->firstname if you have an object or $row[‘firstname’] if you have an array.

What do you get when for var_dump($row) ?

On an equally important note, you should be migrating away from the mysql_* extension as it’s deprecated as of the current version of PHP and will very likely be removed from the next version of PHP. You should now be using either the mysqli_* extension or PDO, both of them offer the use of prepared statements.