SitePoint Sponsor

User Tag List

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

    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 Code:
    <?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?>
    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
    Location
    Mexico city, Mexico
    Posts
    353
    Mentioned
    1 Post(s)
    Tagged
    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
    Location
    Poole, UK
    Posts
    4,994
    Mentioned
    100 Post(s)
    Tagged
    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


Bookmarks

Posting Permissions

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