justlukeyou Posted March 25, 2013 Share Posted March 25, 2013 Hi, I am trying to complete a multi-dimensional array however when I use the following link: website.php?skill=print-design It echoes the following: skills.php?skill= The plan is to query skill1, skill2 and skill3 by querying skill only. Does anyone have any suggestions on how I can clear it. <?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); ?> <?php echo ($row['skill1']); ?> Quote Link to comment Share on other sites More sharing options...
requinix Posted March 25, 2013 Share Posted March 25, 2013 You can't base64_encode() an array. Given the code you've shown, what are you trying to get out of it? Quote Link to comment Share on other sites More sharing options...
justlukeyou Posted March 25, 2013 Author Share Posted March 25, 2013 Thanks, I have 3 columns skill1, skill2 and skill3. I am trying to running a query such as .php?skill=web-design instead of .php?skill1=web-design which wont allow me to query skill2 and skill3. Quote Link to comment Share on other sites More sharing options...
requinix Posted March 25, 2013 Share Posted March 25, 2013 That's a URL, not a query. What is "?skill=web-design" supposed to do? What does the $skills array have to do with it? Quote Link to comment Share on other sites More sharing options...
Barand Posted March 25, 2013 Share Posted March 25, 2013 Do you mean .php?skill[]=web-design&skill[]=print-design&skill[]=programming Quote Link to comment Share on other sites More sharing options...
justlukeyou Posted March 25, 2013 Author Share Posted March 25, 2013 Hi, I have these links: website.com/query.php?skill=graphic-design and website.com/query.php?skill=web-design But 'Graphic Design' is part of skill1 column and 'Web Design' is part of skill2 column. I am trying to get the link to query multiple columns. Quote Link to comment Share on other sites More sharing options...
Barand Posted March 25, 2013 Share Posted March 25, 2013 So are you saying you have a table with columns called "Skill1", "Skill2" and "Skill3" ? Quote Link to comment Share on other sites More sharing options...
justlukeyou Posted March 25, 2013 Author Share Posted March 25, 2013 Thats right. I am now trying to query them all as 'skill'. Quote Link to comment Share on other sites More sharing options...
Barand Posted March 25, 2013 Share Posted March 25, 2013 Then why don't you normalize them into a separate table with a column called skill. You must have come across the concept after six years on this forum! Quote Link to comment Share on other sites More sharing options...
justlukeyou Posted March 25, 2013 Author Share Posted March 25, 2013 (edited) Hi, Is it possible to do a query against all 3 columns? Normalizing it into another table sounds more complicated if I can just run a query on the existing table. Edited March 25, 2013 by justlukeyou Quote Link to comment Share on other sites More sharing options...
Jessica Posted March 26, 2013 Share Posted March 26, 2013 Just like the dozen other times we've told you, you need to normalize your data. We will not help you do it the wrong way. Stop asking. Quote Link to comment Share on other sites More sharing options...
justlukeyou Posted March 31, 2013 Author Share Posted March 31, 2013 (edited) Hi, When someone submits there 3 skills can I insert them into both skill1, skill2, skill3 and skill? So the 3 skills enter 'skill' and skill1, skill2, skill3. I have also been advised it can be done like this... $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); Edited March 31, 2013 by justlukeyou Quote Link to comment Share on other sites More sharing options...
Jessica Posted March 31, 2013 Share Posted March 31, 2013 Just like the dozen other times we've told you, you need to normalize your data. We will not help you do it the wrong way. Stop asking. Quote Link to comment Share on other sites More sharing options...
justlukeyou Posted April 1, 2013 Author Share Posted April 1, 2013 Hi, So how would I normalise this data? How does this interact with a multidimensional array? Quote Link to comment Share on other sites More sharing options...
jcbones Posted April 1, 2013 Share Posted April 1, 2013 . Quote Link to comment Share on other sites More sharing options...
justlukeyou Posted April 6, 2013 Author Share Posted April 6, 2013 So I need to place all the skills from the 3 columns into one column along with the users id. Perform a query against this single column and perform a join query? I would also have to set up a method to update both the original 3 columns and this single column. If I have 3 columns simultaneously inserted into one column will that work. Is it possible to insert 3 into 1 simultaneously. I am confused why someone else suggested I use multi-dimensional array. That suggests I dont need to set up another table. Quote Link to comment Share on other sites More sharing options...
justlukeyou Posted April 8, 2013 Author Share Posted April 8, 2013 Hi, I got this code to work but there is no data normalisation so should I be using it? <?php //Create a function. The advantage is that it is reusable is reusable //This can be stored in a seperate file if required i.e. functions.php //It can be included in the main file using includes('functions.php); and reused in other pages. if (isset($_GET['skill'])) { //Checks if the url parameter exist $skill = $_GET['skill']; $skills = getSkill($skill); //This passes the url parameter to the function } function getSkill($skill) { $sql = "SELECT * FROM users WHERE skill1 = '$skill' OR skill2 = '$skill' OR skill3 = '$skill'"; //Selects records from the database where skill1 or skill2 or skill3 match the url parameter $result = mysql_query($sql) or die(mysql_error()); while ($row = mysql_fetch_assoc($result)) { $skills[] = $row; //Builds an array of the results } return $skills; //Returns the array } foreach ($skills as $skill) ?> Quote Link to comment Share on other sites More sharing options...
Jessica Posted April 8, 2013 Share Posted April 8, 2013 Yes. After we told you time and time again that you need to do X, ask us if you still need to do X. Go ahead. See what happens. Quote Link to comment Share on other sites More sharing options...
justlukeyou Posted April 8, 2013 Author Share Posted April 8, 2013 (edited) Hi, I asked someone what I should do to solve this BEFORE I came on here and they said to use a multi-dimensional array, that is why I asked on here how to do a multi-dimensional array. Unless Im wrong no one has explained why I should not use a multi-dimensional array and instead use data normalisation. Edited April 8, 2013 by justlukeyou Quote Link to comment Share on other sites More sharing options...
Jessica Posted April 8, 2013 Share Posted April 8, 2013 The two things are not related. You've been given numerous resources on what it means to normalize your table structure. Why would you think we would say now its okay to NOT do it? I checked your history, you were given good info on this topic a year ago. Troll. Quote Link to comment Share on other sites More sharing options...
Solution justlukeyou Posted April 8, 2013 Author Solution Share Posted April 8, 2013 But the code appears to work fine and it was the first recommendation I was given. Seeing as no one can articulate why I shouldn't use this method I shall stick with it. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.