Jump to content

problem with array


Ameslee

Recommended Posts

[code]
<?php
echo "<a href = \"?search=$category[0]\"> Employment </a> <br>
                      <a href = \"?search=$category[1]\"> Government </a> <br>
                      <a href = \"?search=$category[2]\"> Training </a> <br>
                      <a href = \"?search=$category[3]\"> Rehabilitation </a><br>
                      <a href = \"?search=$category[4]\"> Accommodation </a><br>
                      <a href = \"?search=$category[5]\"> Sport and Leisure </a><br>
                      <a href = \"?search=$category[6]\"> Information </a> <br>
                      <a href = \"?search=$category[7]\"> Personal Support </a> <br>
                      <a href = \"?search=$category[8]\">Education </a> <br>
                      <a href = \"?search=$category[9]\"> Transition to Work </a> <br>
                      <a href = \"?search=$category[10]\"> Community Participation </a><br>
                        </p>";
$hostname = localhost;
$username = ;
$password = ;


$conn = mysql_connect($hostname, $username, $password) or die(mysql_error());
$connection = mysql_select_db("greenac_VORNExpo", $conn);


if (in_array($_GET['search'], $category)) {

$sql = mysql_query("SELECT * FROM services WHERE category LIKE '".$search."%';") or die(mysql_error());
while ($row = mysql_fetch_array($sql)){
// display results
echo "<br><a href=\"display_services.php?id=".$row['service2id']."\">" .$row['name']. "<br>";

}

}
?>[/code]

can someone tell me why i am getting the following error and how to fix it, thanks

error:  Warning: in_array() [function.in-array]: Wrong datatype for second argument in /home/greenac/public_html/search.php on line 241

Link to comment
Share on other sites

Where? You didn't do anything with it. If you mean in the links, that doesn't make any sense.
I think you want something like this

[code]$category = array('Employment', 'Government' ); // etc [/code]
then
[code]
foreach($category AS $id=>$cat){
  echo '<a href="?search='.$id.'">'.$cat.'</a> <br>';
}
[/code]
Finally
[code]if ($category[$_GET['search']]){[/code]
Try that.
Link to comment
Share on other sites

you can put what I wrote for you.

Should search be a number or string? If it's the string, IE: Government, change this line also:
$sql = mysql_query("SELECT * FROM services WHERE category LIKE '".$category[$_GET['search']]."%';") or die(mysql_error());
Link to comment
Share on other sites

is this right
[code]
<?php
$category = array('Employment', 'Government', 'Training', 'Rehabilitation', 'Accommodation', 'Sport and Leisure', 'Information', 'Personal Support', 'Education', 'Transition to Work', 'Community Participation');
foreach($category as $cat) {
  echo '<a href="?search='.$id.'">'.$cat.'</a> <br>';
}
$hostname = localhost;
$username = ;
$password = ;


$conn = mysql_connect($hostname, $username, $password) or die(mysql_error());
$connection = mysql_select_db("greenac_VORNExpo", $conn);


if ($category[$_GET['search']]){

$sql = mysql_query("SELECT * FROM services WHERE category LIKE '".$category[$_GET['search']]."%';") or die(mysql_error());
while ($row = mysql_fetch_array($sql)){
// display results
echo "<br><a href=\"display_services.php?id=".$row['service2id']."\">" .$row['name']. "<br>";

}

}
?>[/code]
Link to comment
Share on other sites

hey i had a bit of trouble with that but i fixed it, one problem though, here is the code:
[code]
<?php
$category = array('Employment', 'Government', 'Training', 'Rehabilitation', 'Accommodation', 'Sport and Leisure', 'Information', 'Personal Support', 'Education', 'Transition to Work', 'Community Participation');
foreach($category as $cat) {
  echo '<a href="?search='.$cat.'">'.$cat.'</a> <br>';
}
$hostname = localhost;
$username = ;
$password = ;


$conn = mysql_connect($hostname, $username, $password) or die(mysql_error());
$connection = mysql_select_db("greenac_VORNExpo", $conn);


if (in_array($_GET['search'],$category)) {

$sql = mysql_query("SELECT * FROM services WHERE category LIKE '".$_GET['search']."%';") or die(mysql_error());
while ($row = mysql_fetch_array($sql)){
// display results
echo "<br><a href=\"display_services.php?id=".$row['service2id']."\">" .$row['name']. "<br>";

}

}
?>[/code]

ill try to explain the problem as best as possible.  I click a link, it displays a record.  if i have more than one category in that field, it wont display it, if i click a link that is a second record, it wont display.  so it doesnt look up the second thing in that field
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.