SitePoint Sponsor

User Tag List

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

    Query Multiple Columns

    Hi,

    I am echoing 3 columns skill1, skill2 and skill3.

    I am trying to echo them into a query skills.php?skill1=(echoskill1 or skill2 or skill3) but I need it to be skills.php?skill=(echoskill1 or skill2 or skill3)

    So instead of this....

    skills.php?skill1=(echoskill1 or skill2 or skill3)
    skills.php?skill2=(echoskill1 or skill2 or skill3)
    skills.php?skill3=(echoskill1 or skill2 or skill3)

    I have this...

    skills.php?skill=(echoskill1 or skill2 or skill3)

  2. #2
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    4,813
    Mentioned
    141 Post(s)
    Tagged
    0 Thread(s)
    send it as an array.
    PHP Code:
    $skills = array('skill1' => 'skill value 1''skill2' => 'skill value 2''skill3' => 'skill value 3');
    echo 
    "skills.php?skill=" base64_encode($skills); 
    Be sure to congratulate xMog on earning April's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  3. #3
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    730
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Many thanks, that looks ideal.

    How do I fit the query code together with this code?

    I have tried this...

    Code:
    		<?php
    if (isset($_GET['skills']))
    $skills = array('skill1' => 'skill value 1', 'skill2' => 'skill value 2', 'skill3' => 'skill value 3');
    echo "skills.php?skill=" . base64_encode($skills);
    $sql = "SELECT * FROM users WHERE skills = '$skill1'";
    $res = mysql_query($sql) or die(mysql_error());
    $row = mysql_fetch_assoc($res); 
    $num_rows = mysql_num_rows($res); 
    ?>
    Code:
    $skills = array('skill1' => 'skill value 1', 'skill2' => 'skill value 2', 'skill3' => 'skill value 3');
    echo "skills.php?skill=" . base64_encode($skills);

  4. #4
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    4,813
    Mentioned
    141 Post(s)
    Tagged
    0 Thread(s)
    I gave you the code to build the link to the page that shows the skills. To read the skills from the link you will need to reverse it.

    PHP Code:
    $skillsEncoded $_GET['skill'];
    $skills base64_decode($skillsEncoded);
    // now you have a multi-dimensional array again stored in $skills 
    Be sure to congratulate xMog on earning April's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  5. #5
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    730
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Thanks,

    When I try to apply it echoes "skills.php?skill=" which is the same as when I remove that peice of code.


    Code:
    		<?php
    if (isset($_GET['skills']))
    $skills = array('skill1' => 'skill value 1', 'skill2' => 'skill value 2', 'skill3' => 'skill value 3');
    echo "skills.php?skill=" . base64_encode($skills);
    $skillsEncoded = $_GET['skill'];
    $skills = base64_decode($skillsEncoded);
    $sql = "SELECT * FROM users WHERE skill1 = '$skills'";
    $res = mysql_query($sql) or die(mysql_error());
    $row = mysql_fetch_assoc($res); 
    $num_rows = mysql_num_rows($res); 
    ?>
    
    <div class="whyevspacerheader">
    Search Event Skills
    </div>
    <?php echo ($row['skill1']); ?>
    
      </div>

  6. #6
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    4,813
    Mentioned
    141 Post(s)
    Tagged
    0 Thread(s)
    My point was, replace your current links:
    skills.php?skill=(echoskill1 or skill2 or skill3)

    So they are generated using
    PHP Code:
    $skills = array('skill1' => 'skill value 1''skill2' => 'skill value 2''skill3' => 'skill value 3');
    echo 
    "skills.php?skill=" base64_encode($skills); 
    Then on skills.php, read the skill variable that is passed using
    PHP Code:
    $skillsEncoded $_GET['skill'];
    $skills base64_decode($skillsEncoded);
    // now you have a multi-dimensional array again stored in $skills 
    Be sure to congratulate xMog on earning April's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes


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
  •