Jump to content

Multi-Dimensional Array Query


justlukeyou

Recommended Posts

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']); ?>
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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);
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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)
?>
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.