SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru
    Join Date
    Feb 2007
    2 Post(s)
    0 Thread(s)

    Multi-Dimensional Array, Almost There


    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 Code:
    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)) {


    <?php echo (!empty($row['skill1'])) ? $row['skill1'] : ''?>
    echo $skill1?>
    echo $skill?>
    Last edited by SpacePhoenix; Apr 9, 2013 at 11:24. Reason: placed php tags around php code

  2. #2
    SitePoint Addict tlacaelelrl's Avatar
    Join Date
    Apr 2011
    Mexico city, Mexico
    1 Post(s)
    0 Thread(s)
    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) ?
    Do you get bothered because I do the same thing every day?
    Do you question why I do it?
    Then find something that you actually like doing!!!

    Stop thinking on what I do.

  3. #3
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Poole, UK
    103 Post(s)
    0 Thread(s)
    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.
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts